QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#448605#8809. Telephone Plansarbuzick0 0ms3624kbC++204.6kb2024-06-19 20:04:582024-06-19 20:04:59

Judging History

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

  • [2024-06-19 20:04:59]
  • 评测
  • 测评结果:0
  • 用时:0ms
  • 内存:3624kb
  • [2024-06-19 20:04:58]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

mt19937 rnd(57);

struct Node {
    int u, v;
    int y;
    Node *l, *r, *pr;
    int sz, sz_ans;

    Node(int _u, int _v) {
        u = _u, v = _v;
        y = rnd();
        l = r = pr = nullptr;
        sz = 1;
        if (u == v) {
            sz_ans = 1;
        } else {
            sz_ans = 0;
        }
    }
};

int sz(Node *root) {
    if (root == nullptr) {
        return 0;
    }
    return root->sz;
}

int sz_ans(Node *root) {
    if (root == nullptr) {
        return 0;
    }
    return root->sz_ans;
}

void relax(Node *root) {
    root->sz = sz(root->l) + sz(root->r) + 1;
    root->sz_ans = sz_ans(root->l) + sz_ans(root->r);
    if (root->u == root->v) {
        root->sz_ans++;
    }
    if (root->l) {
        root->l->pr = root;
    }
    if (root->r) {
        root->r->pr = root;
    }
}

pair<Node *, int> get_root(Node *nw) {
    int ans = sz(nw->l);
    Node *prv = nw;
    nw = nw->pr;
    while (nw != nullptr) {
        if (prv == nw->r) {
            ans += sz(nw->l) + 1;
        }
        prv = nw;
        nw = nw->pr;
    }
    return make_pair(prv, ans);
}

Node *merge(Node *root1, Node *root2) {
    if (root1 == nullptr) {
        return root2;
    }
    if (root2 == nullptr) {
        return root1;
    }
    if (root1->y > root2->y) {
        root1->r = merge(root1->r, root2);
        relax(root1);
        return root1;
    } else {
        root2->l = merge(root1, root2->l);
        relax(root2);
        return root2;
    }
}

pair<Node *, Node *> split_sz(Node *root, int sz_l) {
    if (root == nullptr) {
        return make_pair(nullptr, nullptr);
    }
    if (sz(root->l) >= sz_l) {
        auto [res1, res2] = split_sz(root->l, sz_l);
        root->l = res2;
        relax(root);
        root->pr = nullptr;
        return make_pair(res1, root);
    } else {
        auto [res1, res2] = split_sz(root->r, sz_l - sz(root->l) - 1);
        root->r = res1;
        relax(root);
        root->pr = nullptr;
        return make_pair(root, res2);
    }
}

struct ETT {
    map<pair<int, int>, Node *> edges;

    ETT(int n) {
        for (int i = 0; i < n; ++i) {
            edges[make_pair(i, i)] = new Node(i, i);
        }
    }

    void add_edge(int u, int v) {
        auto [root_u, pos_u] = get_root(edges[make_pair(u, u)]);
        auto [res1_u, res2_u] = split_sz(root_u, pos_u);
        root_u = merge(res2_u, res1_u);
        auto [root_v, pos_v] = get_root(edges[make_pair(v, v)]);
        auto [res1_v, res2_v] = split_sz(root_v, pos_v);
        root_v = merge(res2_v, res1_v);
        edges[make_pair(u, v)] = new Node(u, v);
        edges[make_pair(v, u)] = new Node(v, u);
        merge(merge(root_u, edges[make_pair(u, v)]), merge(root_v, edges[make_pair(v, u)]));
    }

    void del_edge(int u, int v) {
        auto [root, pos_uv] = get_root(edges[make_pair(u, v)]);
        auto [res1, res2] = split_sz(root, pos_uv);
        root = merge(res2, res1);
        split_sz(root, 1);
        auto [_, pos_vu] = get_root(edges[make_pair(v, u)]);
        auto [res3, res4] = split_sz(root, pos_vu);
        split_sz(res4, 1);
    }

    int get_sz(int v) {
        return sz_ans(get_root(edges[make_pair(v, v)]).first);
    }
};

void solve() {
    int e;
    cin >> e;
    int n, q;
    cin >> n >> q;
    vector<int> ans(q + 1);
    ETT forest(n);
    long long prv = 0;
    for (int t = 0; t < q; ++t) {
        int tp;
        cin >> tp;
        if (tp == 1) {
            long long x, y;
            cin >> x >> y;
            x ^= prv, y ^= prv;
            x--, y--;
            ans[t + 1] = ans[t];
            long long add = forest.get_sz(x) * 1LL * forest.get_sz(y);
            for (int i = 0; i <= t + 1; ++i) {
                ans[i] += add;
            }
            forest.add_edge(x, y);
        } else if (tp == 2) {
            int x, y;
            cin >> x >> y;
            x ^= prv, y ^= prv;
            x--, y--;
            forest.del_edge(x, y);
            ans[t + 1] = ans[t] - forest.get_sz(x) * 1LL * forest.get_sz(y);
        } else if (tp == 3) {
            ans[t + 1] = ans[t];
            long long tm;
            cin >> tm;
            tm ^= prv;
            long long ans_nw = ans[max(0LL, t - tm) + 1];
            cout << ans_nw << '\n';
            prv = ans_nw * e;
        }
    }
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int t = 1;
    // cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}

详细

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 3
Accepted
time: 0ms
memory: 3560kb

input:

0
1 147
3 0
3 0
3 1
3 1
3 0
3 5
3 5
3 1
3 1
3 4
3 8
3 2
3 10
3 13
3 10
3 8
3 8
3 0
3 16
3 3
3 1
3 20
3 2
3 10
3 16
3 13
3 17
3 12
3 22
3 7
3 8
3 2
3 12
3 32
3 12
3 31
3 2
3 0
3 21
3 24
3 28
3 32
3 9
3 18
3 26
3 11
3 45
3 35
3 14
3 34
3 49
3 31
3 43
3 11
3 21
3 50
3 4
3 11
3 31
3 51
3 28
3 26
3 18
3 ...

output:

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0

result:

ok 147 lines

Test #2:

score: 0
Accepted
time: 0ms
memory: 3620kb

input:

0
2 10
1 1 2
3 1
3 1
3 2
3 3
3 3
3 3
2 1 2
3 2
3 3

output:

1
1
1
1
1
1
1
1

result:

ok 8 lines

Test #3:

score: 0
Accepted
time: 0ms
memory: 3500kb

input:

0
30 150
1 14 10
3 1
1 14 6
1 3 6
3 4
3 4
1 2 3
3 0
3 5
1 2 9
1 11 9
3 8
1 19 11
3 6
1 8 19
3 14
3 10
1 27 8
3 15
1 27 28
1 28 20
3 0
3 3
1 20 7
1 7 23
3 13
3 5
1 24 23
3 0
3 28
1 24 13
3 5
3 32
3 1
3 13
1 30 13
3 25
1 30 16
1 15 16
3 22
1 29 15
3 13
1 29 25
1 25 1
1 1 18
3 17
3 8
3 10
1 26 18
3 46
...

output:

1
6
6
10
10
21
28
36
36
45
66
66
91
91
105
105
120
120
120
120
136
171
190
253
253
253
276
276
300
300
300
325
351
351
351
351
406
406
435
435
435
435
435
406
435
435
435
300
435
435
406
435
435
136
435
190
435
435
435
136
406
105
120
136
120
435
435
253
435
66
435
435
435
91
435
435
28
435
55
55
43...

result:

ok 92 lines

Test #4:

score: 0
Accepted
time: 0ms
memory: 3556kb

input:

0
30 150
1 18 9
1 18 28
3 0
3 2
1 28 6
3 4
3 3
3 3
1 26 6
1 5 26
1 5 24
1 17 24
3 9
1 17 3
3 12
3 8
3 10
3 7
1 3 13
3 18
1 13 29
3 8
1 29 14
3 11
3 19
1 7 14
3 17
3 27
1 7 23
3 23
3 15
1 8 23
3 17
3 24
1 8 21
3 7
1 30 21
3 4
3 0
3 32
1 15 30
3 5
3 37
1 15 22
1 11 22
3 3
3 36
1 27 11
3 29
3 11
1 27 1...

output:

3
3
6
6
6
28
36
36
36
36
45
55
66
66
78
78
91
91
105
105
120
136
136
136
153
153
190
190
210
210
253
253
276
276
300
435
435
435
435
435
435
435
435
435
435
435
435
435
435
435
435
435
435
378
435
435
435
435
435
435
435
435
435
378
435
435
435
435
435
435
190
435
435
435
66
190
55
435
325
190
91
66...

result:

ok 92 lines

Test #5:

score: -3
Wrong Answer
time: 0ms
memory: 3572kb

input:

0
30 150
1 1 16
3 1
3 0
3 2
3 1
1 26 1
3 4
1 10 21
1 29 8
1 11 17
3 8
3 8
3 3
3 3
3 6
1 2 9
2 29 8
3 11
3 4
3 16
3 8
1 28 4
3 11
3 18
3 11
3 21
1 20 9
1 6 15
1 4 3
3 5
1 12 5
1 22 25
3 20
3 26
1 7 13
1 16 6
3 34
3 21
3 27
2 1 16
3 34
3 39
3 38
3 3
1 24 5
2 16 6
3 36
3 23
1 27 8
3 15
1 10 17
3 29
3 4...

output:

1
1
1
1
3
6
6
6
6
6
7
7
7
7
8
8
8
8
12
15
15
22
21
22
22
22
22
15
24
23
24
28
29
28
32
32
31
23
31
38
47
48
40
50
60
62
65
56
64
64
39
70
70
70
70
62
71
57
71
71
71
62
79
80
68
82
46
81
68
71
43
32
82
75
68
50
32
46
28
64
68
7
82
68
82
28
75
30
75
81
73
12

result:

wrong answer 82nd lines differ - expected: '13', found: '7'

Subtask #2:

score: 0
Runtime Error

Test #29:

score: 2
Accepted
time: 0ms
memory: 3624kb

input:

1
1 147
3 0
3 0
3 1
3 1
3 3
3 0
3 6
3 6
3 0
3 2
3 0
3 5
3 12
3 1
3 2
3 10
3 13
3 15
3 3
3 12
3 20
3 18
3 10
3 12
3 2
3 12
3 14
3 26
3 12
3 24
3 7
3 7
3 6
3 29
3 32
3 16
3 23
3 14
3 25
3 13
3 13
3 31
3 20
3 26
3 0
3 40
3 23
3 28
3 35
3 1
3 31
3 2
3 34
3 37
3 3
3 39
3 17
3 4
3 41
3 11
3 16
3 48
3 10
3...

output:

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0

result:

ok 147 lines

Test #30:

score: 0
Accepted
time: 0ms
memory: 3524kb

input:

1
2 10
1 1 2
3 1
3 1
3 1
3 1
3 1
3 2
3 6
2 0 3
3 2

output:

1
1
1
1
1
1
1
1

result:

ok 8 lines

Test #31:

score: 0
Accepted
time: 0ms
memory: 3572kb

input:

1
30 150
1 21 13
3 1
1 9 20
3 2
3 2
1 18 11
1 18 0
3 6
3 9
3 8
1 12 9
3 8
3 7
1 10 9
3 5
3 24
3 26
3 28
1 6 16
3 6
3 14
1 15 23
3 21
3 48
1 60 47
3 53
3 37
1 35 53
3 56
1 57 59
1 59 37
3 63
3 95
3 94
1 92 79
3 65
1 90 81
1 95 81
3 75
3 111
3 118
3 100
1 124 98
1 101 98
3 121
3 132
3 137
3 153
1 141 ...

output:

1
3
3
10
10
10
15
15
21
21
21
21
28
28
36
36
45
45
55
78
78
78
91
120
120
120
120
153
153
153
153
171
171
190
190
210
231
231
253
253
253
276
300
300
325
325
351
351
406
406
406
435
435
435
435
435
435
435
435
435
435
435
435
435
435
435
435
435
435
435
435
435
276
435
435
435
435
435
136
435
435
10...

result:

ok 92 lines

Test #32:

score: 0
Accepted
time: 0ms
memory: 3556kb

input:

1
30 150
1 4 26
3 0
1 26 5
3 1
1 24 19
1 19 15
3 1
3 14
1 6 28
1 28 4
3 3
3 28
3 28
1 24 27
3 25
3 27
1 4 17
1 11 4
3 22
1 47 58
3 43
1 60 53
3 57
1 73 83
3 70
1 95 82
3 91
3 92
3 73
3 88
1 71 92
3 78
1 110 102
1 102 106
1 106 111
3 123
3 144
3 136
1 159 147
1 145 147
3 191
1 182 172
3 178
3 205
3 2...

output:

1
3
10
10
21
21
21
28
28
45
55
66
78
91
91
91
91
105
153
153
153
190
210
210
210
210
253
253
253
276
325
325
378
378
378
378
435
435
435
435
435
435
435
378
435
435
378
435
435
435
435
435
435
435
435
253
435
435
276
435
435
231
435
435
435
435
435
435
136
300
276
435
435
300
435
190
435
435
36
435
...

result:

ok 92 lines

Test #33:

score: -2
Runtime Error

input:

1
30 150
1 19 12
3 1
1 22 9
3 0
3 6
1 1 20
3 6
3 5
3 1
3 1
3 5
3 10
3 5
3 4
3 2
1 10 8
3 12
3 20
1 11 17
3 14
3 12
1 31 18
3 12
3 9
3 1
3 17
1 19 10
3 11
3 9
1 10 16
3 13
3 5
3 31
1 7 15
3 13
3 26
1 22 27
3 19
1 15 14
3 17
1 21 23
1 26 28
1 3 24
1 0 11
3 0
3 63
1 19 11
3 29
3 63
1 28 25
3 58
3 63
3 ...

output:


result:


Subtask #3:

score: 0
Skipped

Dependency #1:

0%

Subtask #4:

score: 0
Skipped

Dependency #2:

0%

Subtask #5:

score: 0
Skipped

Dependency #3:

0%

Subtask #6:

score: 0
Skipped

Dependency #4:

0%

Subtask #7:

score: 0
Skipped

Dependency #6:

0%