Submission #1057990

# Submission time Handle Problem Language Result Execution time Memory
1057990 2024-08-14T07:51:54 Z 정민찬(#11077) Telephone Plans (CCO24_day2problem3) C++17
11 / 25
4000 ms 46624 KB
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;

set<ll> adj[500010];
ll sz[500010];
ll id[500010];

void dfs(ll x, ll p, ll nw) {
    id[x] = nw;
    for (auto &y : adj[x]) {
        if (y == p) continue;
        dfs(y, x, nw);
    }
}

ll getSize(ll x, ll p) {
    ll ret = 1;
    for (auto &y : adj[x]) {
        if (y == p) continue;
        ret += getSize(y, x);
    }
    return ret;
}

ll add[1500010];

int main() {
    ios_base :: sync_with_stdio(false); cin.tie(NULL);
    ll E;
    cin >> E;
    ll N, Q;
    cin >> N >> Q;
    for (ll i=1; i<=N; i++) {
        id[i] = i;
        sz[i] = 1;
    }
    ll pv = N;
    ll prv = 0;
    ll cur = 0;
    for (ll q=1; q<=Q; q++) {
        if (q != 1) add[q-1] = add[q-2];
        ll cmd;
        cin >> cmd;
        if (cmd == 1) {
            ll x, y;
            cin >> x >> y;
            if (E) {
                x ^= prv;
                y ^= prv;
            }
            if (sz[id[x]] < sz[id[y]]) swap(x, y);
            cur -= sz[id[x]] * (sz[id[x]]-1) / 2;
            cur -= sz[id[y]] * (sz[id[y]]-1) / 2;
            sz[id[x]] += sz[id[y]];
            cur += sz[id[x]] * (sz[id[x]]-1) / 2;
            dfs(y, -1, id[x]);
            adj[x].insert(y);
            adj[y].insert(x);
        }
        else if (cmd == 2) {
            ll x, y;
            cin >> x >> y;
            if (E) {
                x ^= prv;
                y ^= prv;
            }
            adj[x].erase(y);
            adj[y].erase(x);
            ll szx = getSize(x, -1);
            ll szy = getSize(y, -1);
            if (szx < szy) {
                swap(x, y);
                swap(szx, szy);
            }
            dfs(y, -1, ++pv);
            sz[id[x]] = szx;
            sz[id[y]] = szy;
            add[q-1] += szx * szy;
            cur -= szx * szy;
        }
        else {
            ll t;
            cin >> t;
            if (E) {
                t ^= prv;
            }
            ll ans = cur;
            if (q-t == 0) ans += add[q-1];
            else ans += add[q-1] - add[q-t-1];
            cout << ans << '\n';
            prv = ans;
        }
    }
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 28764 KB Output is correct
2 Correct 3 ms 28764 KB Output is correct
3 Correct 4 ms 28764 KB Output is correct
4 Correct 5 ms 28764 KB Output is correct
5 Correct 4 ms 28760 KB Output is correct
6 Correct 4 ms 28764 KB Output is correct
7 Correct 3 ms 28764 KB Output is correct
8 Correct 3 ms 28764 KB Output is correct
9 Correct 3 ms 28892 KB Output is correct
10 Correct 3 ms 28760 KB Output is correct
11 Correct 3 ms 28764 KB Output is correct
12 Correct 4 ms 28764 KB Output is correct
13 Correct 3 ms 28888 KB Output is correct
14 Correct 3 ms 28764 KB Output is correct
15 Correct 4 ms 28764 KB Output is correct
16 Correct 4 ms 28764 KB Output is correct
17 Correct 3 ms 28764 KB Output is correct
18 Correct 3 ms 28764 KB Output is correct
19 Correct 4 ms 28760 KB Output is correct
20 Correct 4 ms 28760 KB Output is correct
21 Correct 3 ms 28764 KB Output is correct
22 Correct 3 ms 28764 KB Output is correct
23 Correct 3 ms 28764 KB Output is correct
24 Correct 4 ms 28764 KB Output is correct
25 Correct 4 ms 28764 KB Output is correct
26 Correct 3 ms 28764 KB Output is correct
27 Correct 3 ms 28764 KB Output is correct
28 Correct 4 ms 28764 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 28968 KB Output is correct
2 Correct 4 ms 28764 KB Output is correct
3 Correct 4 ms 28976 KB Output is correct
4 Correct 4 ms 28764 KB Output is correct
5 Correct 3 ms 28764 KB Output is correct
6 Correct 4 ms 28764 KB Output is correct
7 Correct 3 ms 28764 KB Output is correct
8 Correct 3 ms 28764 KB Output is correct
9 Correct 3 ms 28764 KB Output is correct
10 Correct 3 ms 28764 KB Output is correct
11 Correct 4 ms 28764 KB Output is correct
12 Correct 4 ms 28764 KB Output is correct
13 Correct 3 ms 28764 KB Output is correct
14 Correct 3 ms 28764 KB Output is correct
15 Correct 4 ms 28764 KB Output is correct
16 Correct 3 ms 28764 KB Output is correct
17 Correct 3 ms 28764 KB Output is correct
18 Correct 3 ms 28764 KB Output is correct
19 Correct 3 ms 28764 KB Output is correct
20 Correct 4 ms 28760 KB Output is correct
21 Correct 3 ms 28764 KB Output is correct
22 Correct 3 ms 28764 KB Output is correct
23 Correct 4 ms 28764 KB Output is correct
24 Correct 3 ms 28764 KB Output is correct
25 Correct 4 ms 28764 KB Output is correct
26 Correct 3 ms 28764 KB Output is correct
27 Correct 3 ms 28764 KB Output is correct
28 Correct 3 ms 28764 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 28764 KB Output is correct
2 Correct 3 ms 28764 KB Output is correct
3 Correct 4 ms 28764 KB Output is correct
4 Correct 5 ms 28764 KB Output is correct
5 Correct 4 ms 28760 KB Output is correct
6 Correct 4 ms 28764 KB Output is correct
7 Correct 3 ms 28764 KB Output is correct
8 Correct 3 ms 28764 KB Output is correct
9 Correct 3 ms 28892 KB Output is correct
10 Correct 3 ms 28760 KB Output is correct
11 Correct 3 ms 28764 KB Output is correct
12 Correct 4 ms 28764 KB Output is correct
13 Correct 3 ms 28888 KB Output is correct
14 Correct 3 ms 28764 KB Output is correct
15 Correct 4 ms 28764 KB Output is correct
16 Correct 4 ms 28764 KB Output is correct
17 Correct 3 ms 28764 KB Output is correct
18 Correct 3 ms 28764 KB Output is correct
19 Correct 4 ms 28760 KB Output is correct
20 Correct 4 ms 28760 KB Output is correct
21 Correct 3 ms 28764 KB Output is correct
22 Correct 3 ms 28764 KB Output is correct
23 Correct 3 ms 28764 KB Output is correct
24 Correct 4 ms 28764 KB Output is correct
25 Correct 4 ms 28764 KB Output is correct
26 Correct 3 ms 28764 KB Output is correct
27 Correct 3 ms 28764 KB Output is correct
28 Correct 4 ms 28764 KB Output is correct
29 Correct 30 ms 29276 KB Output is correct
30 Correct 29 ms 29276 KB Output is correct
31 Correct 4 ms 29020 KB Output is correct
32 Correct 18 ms 29020 KB Output is correct
33 Correct 5 ms 29020 KB Output is correct
34 Correct 4 ms 29020 KB Output is correct
35 Correct 16 ms 29208 KB Output is correct
36 Correct 6 ms 29224 KB Output is correct
37 Correct 6 ms 29020 KB Output is correct
38 Correct 20 ms 29020 KB Output is correct
39 Correct 23 ms 29020 KB Output is correct
40 Correct 20 ms 29020 KB Output is correct
41 Correct 17 ms 29016 KB Output is correct
42 Correct 5 ms 29020 KB Output is correct
43 Correct 6 ms 29108 KB Output is correct
44 Correct 28 ms 29276 KB Output is correct
45 Correct 5 ms 29020 KB Output is correct
46 Correct 29 ms 29208 KB Output is correct
47 Correct 5 ms 29020 KB Output is correct
48 Correct 5 ms 29020 KB Output is correct
49 Correct 5 ms 29152 KB Output is correct
50 Correct 4 ms 29016 KB Output is correct
51 Correct 4 ms 29016 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 28968 KB Output is correct
2 Correct 4 ms 28764 KB Output is correct
3 Correct 4 ms 28976 KB Output is correct
4 Correct 4 ms 28764 KB Output is correct
5 Correct 3 ms 28764 KB Output is correct
6 Correct 4 ms 28764 KB Output is correct
7 Correct 3 ms 28764 KB Output is correct
8 Correct 3 ms 28764 KB Output is correct
9 Correct 3 ms 28764 KB Output is correct
10 Correct 3 ms 28764 KB Output is correct
11 Correct 4 ms 28764 KB Output is correct
12 Correct 4 ms 28764 KB Output is correct
13 Correct 3 ms 28764 KB Output is correct
14 Correct 3 ms 28764 KB Output is correct
15 Correct 4 ms 28764 KB Output is correct
16 Correct 3 ms 28764 KB Output is correct
17 Correct 3 ms 28764 KB Output is correct
18 Correct 3 ms 28764 KB Output is correct
19 Correct 3 ms 28764 KB Output is correct
20 Correct 4 ms 28760 KB Output is correct
21 Correct 3 ms 28764 KB Output is correct
22 Correct 3 ms 28764 KB Output is correct
23 Correct 4 ms 28764 KB Output is correct
24 Correct 3 ms 28764 KB Output is correct
25 Correct 4 ms 28764 KB Output is correct
26 Correct 3 ms 28764 KB Output is correct
27 Correct 3 ms 28764 KB Output is correct
28 Correct 3 ms 28764 KB Output is correct
29 Correct 29 ms 29276 KB Output is correct
30 Correct 29 ms 29272 KB Output is correct
31 Correct 4 ms 29020 KB Output is correct
32 Correct 18 ms 29016 KB Output is correct
33 Correct 5 ms 29020 KB Output is correct
34 Correct 5 ms 29020 KB Output is correct
35 Correct 17 ms 29232 KB Output is correct
36 Correct 5 ms 29016 KB Output is correct
37 Correct 5 ms 29020 KB Output is correct
38 Correct 20 ms 29212 KB Output is correct
39 Correct 19 ms 29016 KB Output is correct
40 Correct 19 ms 29020 KB Output is correct
41 Correct 16 ms 29192 KB Output is correct
42 Correct 5 ms 29016 KB Output is correct
43 Correct 7 ms 29020 KB Output is correct
44 Correct 28 ms 29272 KB Output is correct
45 Correct 5 ms 29020 KB Output is correct
46 Correct 28 ms 29196 KB Output is correct
47 Correct 5 ms 28976 KB Output is correct
48 Correct 5 ms 29132 KB Output is correct
49 Correct 5 ms 29020 KB Output is correct
50 Correct 4 ms 29020 KB Output is correct
51 Correct 4 ms 29020 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 28764 KB Output is correct
2 Correct 3 ms 28764 KB Output is correct
3 Correct 4 ms 28764 KB Output is correct
4 Correct 5 ms 28764 KB Output is correct
5 Correct 4 ms 28760 KB Output is correct
6 Correct 4 ms 28764 KB Output is correct
7 Correct 3 ms 28764 KB Output is correct
8 Correct 3 ms 28764 KB Output is correct
9 Correct 3 ms 28892 KB Output is correct
10 Correct 3 ms 28760 KB Output is correct
11 Correct 3 ms 28764 KB Output is correct
12 Correct 4 ms 28764 KB Output is correct
13 Correct 3 ms 28888 KB Output is correct
14 Correct 3 ms 28764 KB Output is correct
15 Correct 4 ms 28764 KB Output is correct
16 Correct 4 ms 28764 KB Output is correct
17 Correct 3 ms 28764 KB Output is correct
18 Correct 3 ms 28764 KB Output is correct
19 Correct 4 ms 28760 KB Output is correct
20 Correct 4 ms 28760 KB Output is correct
21 Correct 3 ms 28764 KB Output is correct
22 Correct 3 ms 28764 KB Output is correct
23 Correct 3 ms 28764 KB Output is correct
24 Correct 4 ms 28764 KB Output is correct
25 Correct 4 ms 28764 KB Output is correct
26 Correct 3 ms 28764 KB Output is correct
27 Correct 3 ms 28764 KB Output is correct
28 Correct 4 ms 28764 KB Output is correct
29 Correct 30 ms 29276 KB Output is correct
30 Correct 29 ms 29276 KB Output is correct
31 Correct 4 ms 29020 KB Output is correct
32 Correct 18 ms 29020 KB Output is correct
33 Correct 5 ms 29020 KB Output is correct
34 Correct 4 ms 29020 KB Output is correct
35 Correct 16 ms 29208 KB Output is correct
36 Correct 6 ms 29224 KB Output is correct
37 Correct 6 ms 29020 KB Output is correct
38 Correct 20 ms 29020 KB Output is correct
39 Correct 23 ms 29020 KB Output is correct
40 Correct 20 ms 29020 KB Output is correct
41 Correct 17 ms 29016 KB Output is correct
42 Correct 5 ms 29020 KB Output is correct
43 Correct 6 ms 29108 KB Output is correct
44 Correct 28 ms 29276 KB Output is correct
45 Correct 5 ms 29020 KB Output is correct
46 Correct 29 ms 29208 KB Output is correct
47 Correct 5 ms 29020 KB Output is correct
48 Correct 5 ms 29020 KB Output is correct
49 Correct 5 ms 29152 KB Output is correct
50 Correct 4 ms 29016 KB Output is correct
51 Correct 4 ms 29016 KB Output is correct
52 Execution timed out 4046 ms 46428 KB Time limit exceeded
53 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 28968 KB Output is correct
2 Correct 4 ms 28764 KB Output is correct
3 Correct 4 ms 28976 KB Output is correct
4 Correct 4 ms 28764 KB Output is correct
5 Correct 3 ms 28764 KB Output is correct
6 Correct 4 ms 28764 KB Output is correct
7 Correct 3 ms 28764 KB Output is correct
8 Correct 3 ms 28764 KB Output is correct
9 Correct 3 ms 28764 KB Output is correct
10 Correct 3 ms 28764 KB Output is correct
11 Correct 4 ms 28764 KB Output is correct
12 Correct 4 ms 28764 KB Output is correct
13 Correct 3 ms 28764 KB Output is correct
14 Correct 3 ms 28764 KB Output is correct
15 Correct 4 ms 28764 KB Output is correct
16 Correct 3 ms 28764 KB Output is correct
17 Correct 3 ms 28764 KB Output is correct
18 Correct 3 ms 28764 KB Output is correct
19 Correct 3 ms 28764 KB Output is correct
20 Correct 4 ms 28760 KB Output is correct
21 Correct 3 ms 28764 KB Output is correct
22 Correct 3 ms 28764 KB Output is correct
23 Correct 4 ms 28764 KB Output is correct
24 Correct 3 ms 28764 KB Output is correct
25 Correct 4 ms 28764 KB Output is correct
26 Correct 3 ms 28764 KB Output is correct
27 Correct 3 ms 28764 KB Output is correct
28 Correct 3 ms 28764 KB Output is correct
29 Correct 29 ms 29276 KB Output is correct
30 Correct 29 ms 29272 KB Output is correct
31 Correct 4 ms 29020 KB Output is correct
32 Correct 18 ms 29016 KB Output is correct
33 Correct 5 ms 29020 KB Output is correct
34 Correct 5 ms 29020 KB Output is correct
35 Correct 17 ms 29232 KB Output is correct
36 Correct 5 ms 29016 KB Output is correct
37 Correct 5 ms 29020 KB Output is correct
38 Correct 20 ms 29212 KB Output is correct
39 Correct 19 ms 29016 KB Output is correct
40 Correct 19 ms 29020 KB Output is correct
41 Correct 16 ms 29192 KB Output is correct
42 Correct 5 ms 29016 KB Output is correct
43 Correct 7 ms 29020 KB Output is correct
44 Correct 28 ms 29272 KB Output is correct
45 Correct 5 ms 29020 KB Output is correct
46 Correct 28 ms 29196 KB Output is correct
47 Correct 5 ms 28976 KB Output is correct
48 Correct 5 ms 29132 KB Output is correct
49 Correct 5 ms 29020 KB Output is correct
50 Correct 4 ms 29020 KB Output is correct
51 Correct 4 ms 29020 KB Output is correct
52 Execution timed out 4005 ms 46624 KB Time limit exceeded
53 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 28968 KB Output is correct
2 Correct 4 ms 28764 KB Output is correct
3 Correct 4 ms 28976 KB Output is correct
4 Correct 4 ms 28764 KB Output is correct
5 Correct 3 ms 28764 KB Output is correct
6 Correct 4 ms 28764 KB Output is correct
7 Correct 3 ms 28764 KB Output is correct
8 Correct 3 ms 28764 KB Output is correct
9 Correct 3 ms 28764 KB Output is correct
10 Correct 3 ms 28764 KB Output is correct
11 Correct 4 ms 28764 KB Output is correct
12 Correct 4 ms 28764 KB Output is correct
13 Correct 3 ms 28764 KB Output is correct
14 Correct 3 ms 28764 KB Output is correct
15 Correct 4 ms 28764 KB Output is correct
16 Correct 3 ms 28764 KB Output is correct
17 Correct 3 ms 28764 KB Output is correct
18 Correct 3 ms 28764 KB Output is correct
19 Correct 3 ms 28764 KB Output is correct
20 Correct 4 ms 28760 KB Output is correct
21 Correct 3 ms 28764 KB Output is correct
22 Correct 3 ms 28764 KB Output is correct
23 Correct 4 ms 28764 KB Output is correct
24 Correct 3 ms 28764 KB Output is correct
25 Correct 4 ms 28764 KB Output is correct
26 Correct 3 ms 28764 KB Output is correct
27 Correct 3 ms 28764 KB Output is correct
28 Correct 3 ms 28764 KB Output is correct
29 Correct 29 ms 29276 KB Output is correct
30 Correct 29 ms 29272 KB Output is correct
31 Correct 4 ms 29020 KB Output is correct
32 Correct 18 ms 29016 KB Output is correct
33 Correct 5 ms 29020 KB Output is correct
34 Correct 5 ms 29020 KB Output is correct
35 Correct 17 ms 29232 KB Output is correct
36 Correct 5 ms 29016 KB Output is correct
37 Correct 5 ms 29020 KB Output is correct
38 Correct 20 ms 29212 KB Output is correct
39 Correct 19 ms 29016 KB Output is correct
40 Correct 19 ms 29020 KB Output is correct
41 Correct 16 ms 29192 KB Output is correct
42 Correct 5 ms 29016 KB Output is correct
43 Correct 7 ms 29020 KB Output is correct
44 Correct 28 ms 29272 KB Output is correct
45 Correct 5 ms 29020 KB Output is correct
46 Correct 28 ms 29196 KB Output is correct
47 Correct 5 ms 28976 KB Output is correct
48 Correct 5 ms 29132 KB Output is correct
49 Correct 5 ms 29020 KB Output is correct
50 Correct 4 ms 29020 KB Output is correct
51 Correct 4 ms 29020 KB Output is correct
52 Execution timed out 4005 ms 46624 KB Time limit exceeded
53 Halted 0 ms 0 KB -