QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#425112#5022. 【模板】线段树APJifengcCompile Error//C++142.3kb2024-05-29 22:19:182024-05-29 22:19:19

Judging History

你现在查看的是最新测评结果

  • [2024-05-29 22:19:19]
  • 评测
  • [2024-05-29 22:19:18]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
const int MAXN = 250005;
const int B = 500;
int B;
int id;
int n, q, a[MAXN], b[MAXN], c[MAXN];
int qc, qt[MAXN], ql[MAXN], qr[MAXN], qx[MAXN], qid[MAXN];
int qq;
int bl[MAXN], L[MAXN], R[MAXN];
inline void update(int i, int cc) {
    for (int j = 1; j <= cc; j <<= 1) if (cc & j) {
        for (int k = R[i]; k - j >= max(1, L[i - 1]); k--) b[k] ^= b[k - j];
    }
}
int ans[MAXN];
inline void rebuild() {
    for (int i = (bl[n] == 1 ? 1 : 2); i <= bl[n]; i++) {
        int ll = (i == 2 ? 1 : L[i]), rr = R[i];
        for (int j = L[i - 1]; j <= R[i]; j++) b[j] = a[j];
        int cc = 0;
        for (int j = 1; j <= qc; j++) {
            if (qt[j] == 1) {
                if (qr[j] < L[i - 1] || ql[j] > R[i]) continue;
                if (ql[j] <= L[i - 1] && R[i] <= qr[j]) {
                    cc++;
                    continue;
                }
                update(i, cc), cc = 0;
                for (int k = min(R[i], qr[j]); k > max(L[i - 1], ql[j]); k--) b[k] ^= b[k - 1];
            } else {
                if (qx[j] < ll || qx[j] > rr) continue;
                update(i, cc), cc = 0;
                ans[qid[j]] = b[qx[j]];
            }
        }
        update(i, cc);
        for (int j = ll; j <= rr; j++) c[j] = b[j];
    }
    for (int i = 1; i <= n; i++) a[i] = c[i];
    qc = 0;
}
int main() {
    freopen("xor.in", "r", stdin);
    freopen("xor.out", "w", stdout);
    ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
    cin >> id >> n >> q;
    for (int i = 1; i <= n; i++) cin >> a[i];
    for (int l = 1, r, i = 1; l <= n; l = r + 1, i++) {
        r = min(n, l + B - 1);
        L[i] = l, R[i] = r;
        for (int j = l; j <= r; j++) bl[j] = i;
    }
    int tt = 0;
    for (int i = 1; i <= q; i++) {
        int op; cin >> op;
        ++qc;
        if (op == 1) {
            int l, r; cin >> l >> r;
            qt[qc] = 1, ql[qc] = l, qr[qc] = r;
            tt++;
        } else {
            int x; cin >> x;
            qt[qc] = 2, qx[qc] = x, qid[qc] = ++qq;
        }
        if (tt == B) rebuild(), tt = 0;
    }
    rebuild();
    for (int i = 1; i <= qq; i++) cout << ans[i] << '\n';
    for (int i = 1; i <= n; i++) cout << ans[i] << '\n';
    return 0;
}

Details

answer.code:5:5: error: conflicting declaration ‘int B’
    5 | int B;
      |     ^
answer.code:4:11: note: previous declaration as ‘const int B’
    4 | const int B = 500;
      |           ^
answer.code: In function ‘int main()’:
answer.code:44:12: warning: ignoring return value of ‘FILE* freopen(const char*, const char*, FILE*)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   44 |     freopen("xor.in", "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
answer.code:45:12: warning: ignoring return value of ‘FILE* freopen(const char*, const char*, FILE*)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   45 |     freopen("xor.out", "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~