只过hack求调
查看原帖
只过hack求调
840620
jinyeranxi楼主2024/3/2 14:16

只过hack求调

#include<bits/stdc++.h>

#define ll long long
#define lc p<<1
#define rc p<<1|1
using namespace std;
constexpr int N = 100010;

struct node {
    int num;
    int l, r, lazy;

    void update(int val) {
        lazy = val;
        num = 1 << val;
    }
} tr[N << 2];

void push_up(int p) {
    tr[p].num = (tr[lc].num | tr[rc].num);
}

void push_down(int p) {
    int x = tr[p].lazy;
    if (x) {
        tr[p].lazy = 0;
        tr[lc].update(x);
        tr[rc].update(x);
    }
}

void build(int p, int l, int r) {
    tr[p].l = l, tr[p].r = r;
    tr[p].lazy = 0;
    tr[p].num = 2;
    if (l == r)return;
    int mid = l + r >> 1;
    build(lc, l, mid), build(rc, mid + 1, r);
}

void update(int p, int l, int r, int x) {
    if (tr[p].l >= l && tr[p].r <= r) {
        tr[p].update(x);
        return;
    }
    int mid = tr[p].l + tr[p].r >> 1;
    if (mid >= l)update(lc, l, r, x);
    if (r > mid)update(rc, l, r, x);
    push_up(p);
}

int query(int p, int l, int r) {
    if (tr[p].l >= l && tr[p].r <= r)
        return tr[p].num;
    int mid = tr[p].l + tr[p].r >> 1;
    push_down(p);
    int ans = 0;
    if (mid >= l)ans |= query(lc, l, r);
    if (mid < r)ans |= query(rc, l, r);
    push_up(p);
    return ans;
}

int calc(int x) {
    int ans = 0;
    while (x) {
        x -= x & -x;
        ans++;
    }
    return ans;
}

int main() {
    int l, t, T;
    cin >> l >> t >> T;
    build(1, 1, l);
    int a, b, c;
    char opt;
    while (T--) {
        cin >> opt;
        if (opt == 'C') {
            cin >> a >> b >> c;
            if (a > b)swap(a, b);
            update(1, a, b, c);
        } else {
            cin >> a >> b;
            if (a > b)swap(a, b);
            cout << calc(query(1, a, b)) << '\n';
        }
    }
}
2024/3/2 14:16
加载中...