跳到正文

剪贴板

剪贴板 2mrrz1th

原文
剪贴板信息

剪贴板信息

收录
更新
C++
#include <bits/stdc++.h>
#define PII pair<int, int>
using namespace std;
const int N = 2.5e5 + 3;
const int Q = 1e5 + 3;

inline int read() {
    char ch = getchar(); int x = 0;
    while (!isdigit(ch)) {ch = getchar();}
    while (isdigit(ch)) {x = x * 10 + ch - 48; ch = getchar();}
    return x;
}

int ID, n, T, a[N];

namespace subtask1 {
    bool check() {return ID == 1;}

    void solve() {
        int opt, l, r;
        while (T--) {
            opt = read();
            if (opt == 1) {
                l = read(); r = read();
                for (int i = r; i > l; --i) a[i] ^= a[i - 1];
            }else {
                l = read();
                printf("%d\n", a[l]);
            }
        }
        for (int i = 1; i <= n; ++i) printf("%d\n", a[i]);
    }
}

namespace subtask2 {
    bool check() {return ID == 2 || ID == 3;}
    bitset<N> now, tmp;

    void solve() {
        if (ID == 2) now[1] = 1;
        else for (int i = 1; i <= n; ++i) now[i] = a[i];
        int opt, l, r;
        while (T--) {
            opt = read();
            if (opt == 1) {
                l = read(); r = read(); tmp.set();
                tmp >>= l;
                tmp <<= (N - r + l);
                tmp >>= (N - r);
                tmp &= now;
                tmp <<= 1;
                now ^= tmp;
            }else {
                l = read();
                if (ID == 2) {
                    if (now[l] == 1) printf("%d\n", a[1]);
                    else printf("%d\n", 0);
                }
                else printf("%d\n", (int)now[l]);
            }
        }
        if (ID == 2) for (int i = 1; i <= n; ++i) printf("%d\n", now[i] ? a[1] : 0);
        else for (int i = 1; i <= n; ++i) printf("%d\n", (int)now[i]);
    }
}

namespace subtask3 {
    const int P = 8;
    const int B = (1 << P) + 3;
    const int M = (1 << P);

    bool check() {return 4 <= ID && ID <= 6;}

    int sum[N][B], dn[B], up[B], pre[N];

    void solve() {
        for (int i = 1; i < M; ++i) {
            dn[i] = (i & -i);
            if (i == dn[i]) up[i] = i;
            else up[i] = up[i ^ dn[i]];
        }
        for (int i = 1; i <= n; ++i) pre[i] = pre[i - 1] ^ a[i];
        for (int i = 1; i <= n; ++i) {
            sum[i][0] = pre[i];
            for (int j = 1; j < M; ++j) {
                if (j == dn[j]) {
                    if (i < j) sum[i][j] = pre[i];
                    else {
                        sum[i][j] = pre[i] ^ pre[i - j];
                        if (i > (j << 1)) sum[i][j] ^= sum[i - (j << 1)][j];
                    }
                }else {
                    int k = (j ^ up[j]);
                    sum[i][j] = sum[i][k];
                    if (i > up[j]) sum[i][j] ^= sum[i - up[j]][k];
                    if (i > (up[j] << 1)) sum[i][j] ^= sum[i - (up[j] << 1)][j];
                }
            }
        }
        int opt, l, r, o = 0;
        for (int qwq = 1; qwq <= T; ++qwq) {
            opt = read();
            if (opt == 1) l = read(), r = read(), o++;
            else {
                l = read();
                if (o == 0) printf("%d\n", a[l]);
                else {
                    int x = (o >> P) << P;
                    int y = (o & (M - 1)); y = M - 1 - y;
                    int ans = 0, z = l;
                    while (z > 0) {
                        int id = (((l - z) >> P) << P);
                        if ((id & x) != id) z -= M;
                        else {
                            ans ^= sum[z][y];
                            if (z > M) ans ^= sum[z - M][y];
                            z -= M;
                        }
                    }
                    printf("%d\n", ans);
                }
            }
        }
        for (int i = 1; i <= n; ++i) {
            int l = i;
            if (o == 0) printf("%d\n", a[o]);
            else {
                int x = (o >> P) << P;
                int y = (o & (M - 1)); y = M - 1 - y;
                int ans = 0, z = l;
                while (z > 0) {
                    int id = (((l - z) >> P) << P);
                    if ((id & x) != id) z -= M;
                    else {
                        ans ^= sum[z][y];
                        if (z > M) ans ^= sum[z - M][y];
                        z -= M;
                    }
                }
                printf("%d\n", ans);
            }
        }
    }
}

namespace subtask4 {
    const int M = 300;
    const int P = 8;
    const int B = (1 << P);
    const int O = 1000;

    int sum[O][M], val[O][M], num, L[O], R[O], pos[N], tmp[M];
    vector<int> vec[O];

    void init(int id) {
        if (id == num) return;
        for (int i = 0; i < B; ++i) val[id][i] = a[R[id] - i];
        for (int j = 1; j < B; j <<= 1)
            for (int i = 0; i < B; i += (j << 1))
                for (int k = 0; k < j; ++k)
                    val[id][i + j + k] ^= val[id][i + k];
    }

    void push_down(int id) {
        int m = vec[id].size();
        for (int i = 0; i < P; ++i)
            if ((m >> i) & 1) for (int j = B - 1; j >= (1 << i); --j)
                a[L[id] + j] ^= a[L[id] + j - (1 << i)];
        for (int i = 0; i < B; ++i) tmp[i] = 0;
        for (int i = 0; i < vec[id].size(); ++i) tmp[(m - i - 1) & (B - 1)] ^= vec[id][i];
        for (int j = 1; j < B; j <<= 1)
            for (int i = 0; i < B; i += (j << 1))
                for (int k = 0; k < j; ++k)
                    tmp[i + k] ^= tmp[i + j + k];
        for (int i = 0; i < B && L[id] + i <= R[id]; ++i) a[L[id] + i] ^= tmp[i];
        vec[id].clear();
        for (int i = 0; i < B && L[id] + i <= R[id]; ++i) sum[id][i] = 0;
    }

    void update(int l, int r) {
        if (pos[l] == pos[r]) {
            push_down(pos[l]);
            for (int i = r; i > l; --i) a[i] ^= a[i - 1];
            init(pos[l]);
        }else if (pos[l] + 1 == pos[r]) {
            push_down(pos[l]); push_down(pos[r]);
            for (int i = r; i > l; --i) a[i] ^= a[i - 1];
            init(pos[l]); init(pos[r]);
        }else {
            push_down(pos[l]); push_down(pos[r]);
            int now = a[R[pos[l]]], nxt;
            for (int i = pos[l] + 1; i < pos[r]; ++i) {
                nxt = val[i][vec[i].size() & (B - 1)] ^ sum[i][vec[i].size() & (B - 1)];
                sum[i][vec[i].size() & (B - 1)] ^= now;
                vec[i].push_back(now);
                now = nxt;
            }
            for (int i = r; i > L[pos[r]]; --i) a[i] ^= a[i - 1];
            a[L[pos[r]]] ^= now;
            for (int i = R[pos[l]]; i > l; --i) a[i] ^= a[i - 1];
            init(pos[l]); init(pos[r]);
        }
    }

    void solve() {
        for (int i = 1; i <= n; i += B)
            L[++num] = i, R[num] = min(i + B - 1, n);
        for (int i = 1; i <= num; ++i)
            for (int j = L[i]; j <= R[i]; ++j) pos[j] = i;
        for (int i = 1; i < num; ++i) init(i);
        int opt, l, r;
        while (T--) {
            opt = read();
            if (opt == 1) {
                l = read(); r = read();
                update(l, r);
            }else {
                l = read();
                push_down(pos[l]); init(pos[l]);
                printf("%d\n", a[l]);
            }
        }
        for (int i = 1; i <= num; ++i) push_down(i);
        for (int i = 1; i <= n; ++i) printf("%d\n", a[i]);
    }
}

int main() {
    freopen("in.in", "r", stdin);
    freopen("mine.out", "w", stdout);
    ID = read(); n = read(); T = read();
    for (int i = 1; i <= n; ++i) a[i] = read();
    if (subtask1 :: check()) subtask1 :: solve();
    else if (subtask2 :: check()) subtask2 :: solve();
    else if (subtask3 :: check()) subtask3 :: solve();
    else subtask4 :: solve();
    return 0;
}