全wa,求调
查看原帖
全wa,求调
796389
xiansen楼主2024/7/24 10:52
#include <bits/stdc++.h>
using ll = long long;
// #define int ll
#define lc u << 1
#define rc u << 1 | 1
#define endl '\n'
using namespace std;
typedef pair<int, int> PII;
const int N = 1e5 + 5, mod = 1e9 + 7;
constexpr ll inf = 1E18;
template <class Info, class Tag>
struct LazySegmentTree
{
    const int n;
    vector<Info> info;
    vector<Tag> tag;
    LazySegmentTree(int n) : n(n), info((4 << __lg(n) + 1) + 5), tag((4 << __lg(n) + 1) + 5) {}
    LazySegmentTree(vector<Info> init) : LazySegmentTree(init.size() - 1)
    {
        function<void(int, int, int)> build = [&](int u, int l, int r)
        {
            if (r - l == 0)
            {
                info[u] = init[l];
                return;
            }
            int m = (l + r) / 2;
            build(lc, l, m);
            build(rc, m + 1, r);
            pull(u);
        };
        build(1, 1, n);
    }
    void pull(int u)
    {
        info[u] = info[lc] + info[rc];
    }
    void apply(int u, const Tag &v)
    {
        info[u].apply(v);
        tag[u].apply(v);
    }
    void push(int u)
    {
        apply(lc, tag[u]);
        apply(rc, tag[u]);
        tag[u] = Tag();
    }
    void modify(int u, int l, int r, int x, const Info &v)
    {
        if (r - l == 0)
        {
            info[u] = v;
            return;
        }
        int m = (l + r) / 2;
        push(u);
        if (x <= m)
        {
            modify(lc, l, m, x, v);
        }
        else
        {
            modify(rc, m + 1, r, x, v);
        }
        pull(u);
    }
    void modify(int u, const Info &v)
    {
        modify(1, 1, n, u, v);
    }
    Info rangeQuery(int l, int r)
    {
        return rangeQuery(1, 1, n, l, r);
    }
    Info rangeQuery(int u, int l, int r, int x, int y)
    {
        if (l > y || r < x)
        {
            return Info();
        }
        if (l >= x && r <= y)
        {
            return info[u];
        }
        int m = (l + r) / 2;
        push(u);
        if (x <= m && y > m)
            return rangeQuery(lc, l, m, x, y) + rangeQuery(rc, m + 1, r, x, y);
        else if (x <= m)
            return rangeQuery(lc, l, m, x, y);
        else
            return rangeQuery(rc, m + 1, r, x, y);
    }
    void rangeApply(int l, int r, const Tag &v)
    {
        return rangeApply(1, 1, n, l, r, v);
    }
    void rangeApply(int u, int l, int r, int x, int y, const Tag &v)
    {
        if (l > y || r < x)
        {
            return;
        }
        if (l >= x && r <= y)
        {
            apply(u, v);
            return;
        }
        int m = (l + r) / 2;
        push(u);
        rangeApply(lc, l, m, x, y, v);
        rangeApply(rc, m + 1, r, x, y, v);
        pull(u);
    }
    void half()
    {
        half(1, 1, n);
    }
    void half(int u, int l, int r)
    {
        if (info[u].act == 0)
        {
            return;
        }
        if ((info[u].min + 1) / 2 == (info[u].max + 1) / 2)
        {
            apply(u, {-(info[u].min + 1) / 2});
            return;
        }
        int m = (l + r) / 2;
        push(u);
        half(lc, l, m);
        half(rc, m + 1, r);
        pull(u);
    }
};
struct Tag
{
    ll add = 0;
    void apply(Tag t)
    {
        if (t.add)
            add = t.add;
    }
};
struct Info
{
    ll sum = 1;
    void apply(Tag t)
    {
        if (t.add)
            sum = t.add;
    }
};
Info operator+(Info a, Info b)
{
    Info c;
    c.sum = a.sum | b.sum;
    return c;
}
void solve()
{
    int n, t, q;
    cin >> n >> t >> q;
    vector<Info> a(n + 1, {1});
    LazySegmentTree<Info, Tag> tr(a);
    for (int i = 1; i <= q; i++)
    {
        char op;
        cin >> op;
        if (op == 'C')
        {
            int l, r, x;
            cin >> l >> r >> x;
            if (l > r)
                swap(l, r);
            tr.rangeApply(l, r, {1ll << x});
        }
        else
        {
            int l, r;
            cin >> l >> r;
            if (l > r)
                swap(l, r);
            int tem = tr.rangeQuery(l, r).sum;
            // cout << tem << endl;
            int ans = 0;
            for (int i = 0; i <= t; i++)
            {
                if (1 << i & tem)
                    ans++;
            }
            cout << ans << endl;
        }
    }
}
signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    // int ttt;
    // cin >> ttt;
    // while (ttt--)
    solve();
    return 0;
}
2024/7/24 10:52
加载中...