/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Wrong Answer 1ms 532.0 KiB
#2 Wrong Answer 1ms 532.0 KiB

Code

#include <bits/stdc++.h>
using namespace std;
using ll = long long;

const int MAXNODES = 30 * 300001;
int Next[2][MAXNODES];    // child pointers: Next[bit][node]
bool created[MAXNODES];  // whether node exists
int EndCnt[MAXNODES];     // number of values ending at this node
int SubCnt[MAXNODES];     // number of values passing through this node

int sz;
ll answer;
int BITLEN = 30;

void insert(int x) {
    int v = 0;
    for (int b = BITLEN - 1; b >= 0; --b) {
        int c = (x >> b) & 1;
        if (!created[ Next[c][v] ]) {
            Next[c][v] = ++sz;
            created[ sz ] = true;
        }
        v = Next[c][v];
        SubCnt[v]++;
    }
    EndCnt[v]++;
}

void search(int x, int p) {
    int v = 0;
    for (int b = BITLEN - 1; b >= 0; --b) {
        int c = (x >> b) & 1;
        int cc = (p >> b) & 1;
        int want = c ^ 1;
        if (cc == 1) {
            if (!created[Next[want][v]]) return;
            v = Next[want][v];
        } else {
            if (created[Next[want][v]]) answer += SubCnt[Next[want][v]];
            v = Next[want ^ 1][v];
            if (!created[v]) return;
        }
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int T;
    cin >> T;
    while (T--) {
        int N;
        cin >> N;
        vector<int> a(N);
        for (int i = 0; i < N; ++i) cin >> a[i];

        for (int i = 0; i < N; ++i) {
            a[i] ^= (i + 1);
        }

        sz = 0;
        answer = 0;
        for (int i = 0; i <= BITLEN * N; ++i) {
            created[i] = false;
            Next[0][i] = Next[1][i] = 0;
            SubCnt[i] = EndCnt[i] = 0;
        }
        created[0] = true;

        for (int i = N - 1; i >= 0; --i) {
            search(i + 1, a[i]);
            insert(a[i]);
        }

        cout << answer << "\n";
    }
    return 0;
}

Information

Submit By
Type
Submission
Problem
P1198 E. Good Signal Pairs
Language
C++17 (G++ 13.2.0)
Submit At
2025-05-23 09:32:54
Judged At
2025-05-23 09:32:54
Judged By
Score
0
Total Time
1ms
Peak Memory
532.0 KiB