QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#876300#8613. Cardinalitysuperguymj#RE 0ms3584kbC++201.4kb2025-01-30 19:48:192025-01-30 19:48:20

Judging History

This is the latest submission verdict.

  • [2025-01-30 19:48:20]
  • Judged
  • Verdict: RE
  • Time: 0ms
  • Memory: 3584kb
  • [2025-01-30 19:48:19]
  • Submitted

answer

#include <bits/stdc++.h>
using namespace std;
mt19937 rd(233);
using bs = bitset<12500>;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n, q;
    cin >> n >> q;
    vector<int> vis(n + q + 1);
    vector<bs> vec(q * 2 / 3);
    vector<array<int, 2>> fr(n + q + 1);
    vector<int> saveid(n + q + 1, -1);
    int idc = 0, vistag = 0;
    auto search = [&](auto &&self, int x, bs &bs) -> void {
        if (x <= n) {
            bs[(x - 1) >> 2] = 1;
        } else if (vis[x] < vistag) {
            vis[x] = vistag;
            if (saveid[x] == -1) {
                self(self, fr[x][0], bs);
                self(self, fr[x][1], bs);
            } else {
                bs |= vec[saveid[x]];
            }
        }
    };
    for (int i = 1; i <= q; i++) {
        cin >> fr[n + i][0] >> fr[n + i][1];
        bs now;
        ++vistag;
        for (int j = 0; j < 2; j++) {
            int x = fr[n + i][j];
            if (!vis[x] && idc < (int)vec.size() && rd() % 99999 < 66666) {
                saveid[x] = idc++;
                ++vistag;
                search(search, x, vec[saveid[x]]);
                now |= vec[saveid[x]];
            } else {
                search(search, x, now);
            }
        }
        cout << now.count() * 2 << '\n';
        if (i % 50 == 0 || i == n) {
            cout.flush();
        }
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3584kb

input:

4 5
1 2
2 3
5 6
6 7
4 7

output:

2
2
2
2
2

result:

ok 

Test #2:

score: -100
Runtime Error

input:

10 100
9 2
9 10
5 1
6 6
13 14
3 4
3 8
8 4
16 5
14 2
8 13
14 9
6 17
15 11
24 7
24 20
1 26
14 27
6 18
14 14
15 11
14 25
8 11
7 30
3 11
12 3
6 19
29 36
30 9
38 6
2 28
12 40
33 25
20 42
17 30
23 1
34 41
41 36
7 18
39 45
32 4
30 21
46 26
12 39
42 42
46 48
31 54
16 37
42 4
27 34

output:

4
2
4
2
2
2
4
4
2
4
2
4
2
0
2
0
2
2
2
2
0
2
2
2
2
4
2
2
2
2
4
2
0
0
0
2
4
4
2
0
2
0
2
2
0
2
0
2
2
0

result: