编号 题目 状态 分数 总时间 内存 代码 / 答案文件 提交者 提交时间
#45437 #1001. A. 神秘谜题 Accepted 100 1122 ms 100520 K C++ 17 / 1.8 K 自动化82-郭筠陶 2020-07-31 10:34:11
显示原始代码
#include "bits/stdc++.h"

using namespace std;

const int trieDepth = 32;
const int maxn = 2e5 + 7;

struct TrieNode {
    int cnt[2]{};
    int next[2]{};

    TrieNode() { cnt[0] = cnt[1] = next[0] = next[1] = 0; }
};

TrieNode trieTree[maxn * trieDepth];

int bitsCnt[trieDepth];
int trieNodeCnt = 1;

void insert(int num);
void insert(int num) {
    int curTrieIndex = 0;
    for (uint depth = 0; depth < trieDepth; ++depth) {
        int curBit = (num >> depth) & 1;
        trieTree[curTrieIndex].cnt[curBit]++;
        bitsCnt[depth] += curBit;

        if (trieTree[curTrieIndex].next[curBit] == 0) {
            trieTree[curTrieIndex].next[curBit] = trieNodeCnt;
            trieNodeCnt++;
        }
        curTrieIndex = trieTree[curTrieIndex].next[curBit];
    }
}

void update(int trieIndex, int depth);
void update(int trieIndex, int depth) {
    TrieNode curTrieNode = trieTree[trieIndex];
    if (curTrieNode.next[1] != 0) {
        update(curTrieNode.next[1], depth + 1);
    }

    bitsCnt[depth] += (curTrieNode.cnt[0] - curTrieNode.cnt[1]);
    swap(trieTree[trieIndex].next[0], trieTree[trieIndex].next[1]);
    swap(trieTree[trieIndex].cnt[0], trieTree[trieIndex].cnt[1]);
}

int query();
int query() {
    int ans = 0;
    for (int depth = 0; depth < trieDepth; ++depth) {
        ans |= (bitsCnt[depth] & 1) << depth;
    }
    return ans;
}

int main() {
    // freopen("input","r",stdin);
    // freopen("output","w",stdout);
    int n;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        int opt;
        cin >> opt;
        if (opt == 1) {
            update(0, 0);
        } else {
            int newNum;
            cin >> newNum;
            insert(newNum);
        }
        cout << query() << endl;
    }
}
子任务 #1
Accepted
得分:100
测试点 #1
Accepted
得分:100
用时:568 ms
内存:100444 KiB

输入文件(1.in

200000
2 526767110
2 724642759
2 567837900
2 104106873
2 357915481
2 33997211
2 444788944
2 
<1586974 bytes omitted>

答案文件(1.ans

526767110
877985729
361528077
330887284
116239149
82537142
510237286
843295274
453728745
55
<2188330 bytes omitted>

用户输出

526767110
877985729
361528077
330887284
116239149
82537142
510237286
843295274
453728745
559263713
323554710
713540578
520942594
<1988302 bytes omitted>

系统信息

Exited with return code 0
测试点 #2
Accepted
得分:100
用时:554 ms
内存:100520 KiB

输入文件(2.in

200000
2 515979308
2 512702340
2 684230440
2 488136957
2 598252313
2 283603971
2 349877373
2
<1586842 bytes omitted>

答案文件(2.ans

515979308
5115816
679905408
899606653
372667236
114362215
302756634
473674072
520218589
525
<2192841 bytes omitted>

用户输出

515979308
5115816
679905408
899606653
372667236
114362215
302756634
473674072
520218589
525056845
703148326
764590712
207056035

<1992813 bytes omitted>

系统信息

Exited with return code 0