답안 #1057976

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1057976 2024-08-14T07:48:19 Z 정민찬(#11077) Telephone Plans (CCO24_day2problem3) C++17
11 / 25
4000 ms 47416 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++) {
        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;
            for (ll i=q; i>=q-t; i--)
                ans += add[i];
            cout << ans << '\n';
            prv = ans;
        }
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 28764 KB Output is correct
2 Correct 4 ms 28764 KB Output is correct
3 Correct 4 ms 28764 KB Output is correct
4 Correct 3 ms 28764 KB Output is correct
5 Correct 4 ms 28976 KB Output is correct
6 Correct 4 ms 28764 KB Output is correct
7 Correct 3 ms 28764 KB Output is correct
8 Correct 4 ms 28764 KB Output is correct
9 Correct 5 ms 28764 KB Output is correct
10 Correct 4 ms 28760 KB Output is correct
11 Correct 4 ms 28972 KB Output is correct
12 Correct 4 ms 28764 KB Output is correct
13 Correct 5 ms 28760 KB Output is correct
14 Correct 4 ms 28764 KB Output is correct
15 Correct 4 ms 28764 KB Output is correct
16 Correct 5 ms 28764 KB Output is correct
17 Correct 4 ms 28892 KB Output is correct
18 Correct 4 ms 28764 KB Output is correct
19 Correct 4 ms 28764 KB Output is correct
20 Correct 4 ms 28764 KB Output is correct
21 Correct 4 ms 28980 KB Output is correct
22 Correct 4 ms 28764 KB Output is correct
23 Correct 5 ms 28980 KB Output is correct
24 Correct 5 ms 29128 KB Output is correct
25 Correct 4 ms 28764 KB Output is correct
26 Correct 4 ms 28860 KB Output is correct
27 Correct 5 ms 28976 KB Output is correct
28 Correct 4 ms 28760 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 28764 KB Output is correct
2 Correct 4 ms 28764 KB Output is correct
3 Correct 5 ms 28760 KB Output is correct
4 Correct 5 ms 28760 KB Output is correct
5 Correct 5 ms 28764 KB Output is correct
6 Correct 4 ms 28760 KB Output is correct
7 Correct 5 ms 28760 KB Output is correct
8 Correct 4 ms 28764 KB Output is correct
9 Correct 4 ms 28876 KB Output is correct
10 Correct 4 ms 28764 KB Output is correct
11 Correct 5 ms 28760 KB Output is correct
12 Correct 4 ms 28764 KB Output is correct
13 Correct 4 ms 28764 KB Output is correct
14 Correct 5 ms 28760 KB Output is correct
15 Correct 5 ms 28764 KB Output is correct
16 Correct 4 ms 28764 KB Output is correct
17 Correct 4 ms 28780 KB Output is correct
18 Correct 3 ms 28972 KB Output is correct
19 Correct 5 ms 28764 KB Output is correct
20 Correct 4 ms 28764 KB Output is correct
21 Correct 4 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 4 ms 28880 KB Output is correct
25 Correct 5 ms 28972 KB Output is correct
26 Correct 4 ms 28764 KB Output is correct
27 Correct 4 ms 28764 KB Output is correct
28 Correct 4 ms 28820 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 28764 KB Output is correct
2 Correct 4 ms 28764 KB Output is correct
3 Correct 4 ms 28764 KB Output is correct
4 Correct 3 ms 28764 KB Output is correct
5 Correct 4 ms 28976 KB Output is correct
6 Correct 4 ms 28764 KB Output is correct
7 Correct 3 ms 28764 KB Output is correct
8 Correct 4 ms 28764 KB Output is correct
9 Correct 5 ms 28764 KB Output is correct
10 Correct 4 ms 28760 KB Output is correct
11 Correct 4 ms 28972 KB Output is correct
12 Correct 4 ms 28764 KB Output is correct
13 Correct 5 ms 28760 KB Output is correct
14 Correct 4 ms 28764 KB Output is correct
15 Correct 4 ms 28764 KB Output is correct
16 Correct 5 ms 28764 KB Output is correct
17 Correct 4 ms 28892 KB Output is correct
18 Correct 4 ms 28764 KB Output is correct
19 Correct 4 ms 28764 KB Output is correct
20 Correct 4 ms 28764 KB Output is correct
21 Correct 4 ms 28980 KB Output is correct
22 Correct 4 ms 28764 KB Output is correct
23 Correct 5 ms 28980 KB Output is correct
24 Correct 5 ms 29128 KB Output is correct
25 Correct 4 ms 28764 KB Output is correct
26 Correct 4 ms 28860 KB Output is correct
27 Correct 5 ms 28976 KB Output is correct
28 Correct 4 ms 28760 KB Output is correct
29 Correct 31 ms 29292 KB Output is correct
30 Correct 33 ms 29276 KB Output is correct
31 Correct 6 ms 29196 KB Output is correct
32 Correct 20 ms 29016 KB Output is correct
33 Correct 11 ms 29020 KB Output is correct
34 Correct 6 ms 29016 KB Output is correct
35 Correct 18 ms 29020 KB Output is correct
36 Correct 7 ms 29400 KB Output is correct
37 Correct 7 ms 28992 KB Output is correct
38 Correct 21 ms 29020 KB Output is correct
39 Correct 24 ms 29220 KB Output is correct
40 Correct 19 ms 29020 KB Output is correct
41 Correct 28 ms 29240 KB Output is correct
42 Correct 7 ms 29016 KB Output is correct
43 Correct 8 ms 29020 KB Output is correct
44 Correct 29 ms 29248 KB Output is correct
45 Correct 7 ms 29020 KB Output is correct
46 Correct 30 ms 29236 KB Output is correct
47 Correct 9 ms 29016 KB Output is correct
48 Correct 6 ms 29196 KB Output is correct
49 Correct 8 ms 29016 KB Output is correct
50 Correct 12 ms 29020 KB Output is correct
51 Correct 7 ms 29016 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 28764 KB Output is correct
2 Correct 4 ms 28764 KB Output is correct
3 Correct 5 ms 28760 KB Output is correct
4 Correct 5 ms 28760 KB Output is correct
5 Correct 5 ms 28764 KB Output is correct
6 Correct 4 ms 28760 KB Output is correct
7 Correct 5 ms 28760 KB Output is correct
8 Correct 4 ms 28764 KB Output is correct
9 Correct 4 ms 28876 KB Output is correct
10 Correct 4 ms 28764 KB Output is correct
11 Correct 5 ms 28760 KB Output is correct
12 Correct 4 ms 28764 KB Output is correct
13 Correct 4 ms 28764 KB Output is correct
14 Correct 5 ms 28760 KB Output is correct
15 Correct 5 ms 28764 KB Output is correct
16 Correct 4 ms 28764 KB Output is correct
17 Correct 4 ms 28780 KB Output is correct
18 Correct 3 ms 28972 KB Output is correct
19 Correct 5 ms 28764 KB Output is correct
20 Correct 4 ms 28764 KB Output is correct
21 Correct 4 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 4 ms 28880 KB Output is correct
25 Correct 5 ms 28972 KB Output is correct
26 Correct 4 ms 28764 KB Output is correct
27 Correct 4 ms 28764 KB Output is correct
28 Correct 4 ms 28820 KB Output is correct
29 Correct 29 ms 29300 KB Output is correct
30 Correct 31 ms 29272 KB Output is correct
31 Correct 7 ms 29016 KB Output is correct
32 Correct 19 ms 29276 KB Output is correct
33 Correct 6 ms 29276 KB Output is correct
34 Correct 7 ms 29016 KB Output is correct
35 Correct 22 ms 29284 KB Output is correct
36 Correct 7 ms 29276 KB Output is correct
37 Correct 7 ms 29020 KB Output is correct
38 Correct 25 ms 29276 KB Output is correct
39 Correct 25 ms 29276 KB Output is correct
40 Correct 20 ms 29020 KB Output is correct
41 Correct 18 ms 29284 KB Output is correct
42 Correct 6 ms 29272 KB Output is correct
43 Correct 8 ms 29020 KB Output is correct
44 Correct 30 ms 29328 KB Output is correct
45 Correct 6 ms 29272 KB Output is correct
46 Correct 31 ms 29256 KB Output is correct
47 Correct 7 ms 29276 KB Output is correct
48 Correct 6 ms 29020 KB Output is correct
49 Correct 7 ms 29276 KB Output is correct
50 Correct 7 ms 29020 KB Output is correct
51 Correct 7 ms 29016 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 28764 KB Output is correct
2 Correct 4 ms 28764 KB Output is correct
3 Correct 4 ms 28764 KB Output is correct
4 Correct 3 ms 28764 KB Output is correct
5 Correct 4 ms 28976 KB Output is correct
6 Correct 4 ms 28764 KB Output is correct
7 Correct 3 ms 28764 KB Output is correct
8 Correct 4 ms 28764 KB Output is correct
9 Correct 5 ms 28764 KB Output is correct
10 Correct 4 ms 28760 KB Output is correct
11 Correct 4 ms 28972 KB Output is correct
12 Correct 4 ms 28764 KB Output is correct
13 Correct 5 ms 28760 KB Output is correct
14 Correct 4 ms 28764 KB Output is correct
15 Correct 4 ms 28764 KB Output is correct
16 Correct 5 ms 28764 KB Output is correct
17 Correct 4 ms 28892 KB Output is correct
18 Correct 4 ms 28764 KB Output is correct
19 Correct 4 ms 28764 KB Output is correct
20 Correct 4 ms 28764 KB Output is correct
21 Correct 4 ms 28980 KB Output is correct
22 Correct 4 ms 28764 KB Output is correct
23 Correct 5 ms 28980 KB Output is correct
24 Correct 5 ms 29128 KB Output is correct
25 Correct 4 ms 28764 KB Output is correct
26 Correct 4 ms 28860 KB Output is correct
27 Correct 5 ms 28976 KB Output is correct
28 Correct 4 ms 28760 KB Output is correct
29 Correct 31 ms 29292 KB Output is correct
30 Correct 33 ms 29276 KB Output is correct
31 Correct 6 ms 29196 KB Output is correct
32 Correct 20 ms 29016 KB Output is correct
33 Correct 11 ms 29020 KB Output is correct
34 Correct 6 ms 29016 KB Output is correct
35 Correct 18 ms 29020 KB Output is correct
36 Correct 7 ms 29400 KB Output is correct
37 Correct 7 ms 28992 KB Output is correct
38 Correct 21 ms 29020 KB Output is correct
39 Correct 24 ms 29220 KB Output is correct
40 Correct 19 ms 29020 KB Output is correct
41 Correct 28 ms 29240 KB Output is correct
42 Correct 7 ms 29016 KB Output is correct
43 Correct 8 ms 29020 KB Output is correct
44 Correct 29 ms 29248 KB Output is correct
45 Correct 7 ms 29020 KB Output is correct
46 Correct 30 ms 29236 KB Output is correct
47 Correct 9 ms 29016 KB Output is correct
48 Correct 6 ms 29196 KB Output is correct
49 Correct 8 ms 29016 KB Output is correct
50 Correct 12 ms 29020 KB Output is correct
51 Correct 7 ms 29016 KB Output is correct
52 Execution timed out 4078 ms 46244 KB Time limit exceeded
53 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 28764 KB Output is correct
2 Correct 4 ms 28764 KB Output is correct
3 Correct 5 ms 28760 KB Output is correct
4 Correct 5 ms 28760 KB Output is correct
5 Correct 5 ms 28764 KB Output is correct
6 Correct 4 ms 28760 KB Output is correct
7 Correct 5 ms 28760 KB Output is correct
8 Correct 4 ms 28764 KB Output is correct
9 Correct 4 ms 28876 KB Output is correct
10 Correct 4 ms 28764 KB Output is correct
11 Correct 5 ms 28760 KB Output is correct
12 Correct 4 ms 28764 KB Output is correct
13 Correct 4 ms 28764 KB Output is correct
14 Correct 5 ms 28760 KB Output is correct
15 Correct 5 ms 28764 KB Output is correct
16 Correct 4 ms 28764 KB Output is correct
17 Correct 4 ms 28780 KB Output is correct
18 Correct 3 ms 28972 KB Output is correct
19 Correct 5 ms 28764 KB Output is correct
20 Correct 4 ms 28764 KB Output is correct
21 Correct 4 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 4 ms 28880 KB Output is correct
25 Correct 5 ms 28972 KB Output is correct
26 Correct 4 ms 28764 KB Output is correct
27 Correct 4 ms 28764 KB Output is correct
28 Correct 4 ms 28820 KB Output is correct
29 Correct 29 ms 29300 KB Output is correct
30 Correct 31 ms 29272 KB Output is correct
31 Correct 7 ms 29016 KB Output is correct
32 Correct 19 ms 29276 KB Output is correct
33 Correct 6 ms 29276 KB Output is correct
34 Correct 7 ms 29016 KB Output is correct
35 Correct 22 ms 29284 KB Output is correct
36 Correct 7 ms 29276 KB Output is correct
37 Correct 7 ms 29020 KB Output is correct
38 Correct 25 ms 29276 KB Output is correct
39 Correct 25 ms 29276 KB Output is correct
40 Correct 20 ms 29020 KB Output is correct
41 Correct 18 ms 29284 KB Output is correct
42 Correct 6 ms 29272 KB Output is correct
43 Correct 8 ms 29020 KB Output is correct
44 Correct 30 ms 29328 KB Output is correct
45 Correct 6 ms 29272 KB Output is correct
46 Correct 31 ms 29256 KB Output is correct
47 Correct 7 ms 29276 KB Output is correct
48 Correct 6 ms 29020 KB Output is correct
49 Correct 7 ms 29276 KB Output is correct
50 Correct 7 ms 29020 KB Output is correct
51 Correct 7 ms 29016 KB Output is correct
52 Execution timed out 4086 ms 47416 KB Time limit exceeded
53 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 28764 KB Output is correct
2 Correct 4 ms 28764 KB Output is correct
3 Correct 5 ms 28760 KB Output is correct
4 Correct 5 ms 28760 KB Output is correct
5 Correct 5 ms 28764 KB Output is correct
6 Correct 4 ms 28760 KB Output is correct
7 Correct 5 ms 28760 KB Output is correct
8 Correct 4 ms 28764 KB Output is correct
9 Correct 4 ms 28876 KB Output is correct
10 Correct 4 ms 28764 KB Output is correct
11 Correct 5 ms 28760 KB Output is correct
12 Correct 4 ms 28764 KB Output is correct
13 Correct 4 ms 28764 KB Output is correct
14 Correct 5 ms 28760 KB Output is correct
15 Correct 5 ms 28764 KB Output is correct
16 Correct 4 ms 28764 KB Output is correct
17 Correct 4 ms 28780 KB Output is correct
18 Correct 3 ms 28972 KB Output is correct
19 Correct 5 ms 28764 KB Output is correct
20 Correct 4 ms 28764 KB Output is correct
21 Correct 4 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 4 ms 28880 KB Output is correct
25 Correct 5 ms 28972 KB Output is correct
26 Correct 4 ms 28764 KB Output is correct
27 Correct 4 ms 28764 KB Output is correct
28 Correct 4 ms 28820 KB Output is correct
29 Correct 29 ms 29300 KB Output is correct
30 Correct 31 ms 29272 KB Output is correct
31 Correct 7 ms 29016 KB Output is correct
32 Correct 19 ms 29276 KB Output is correct
33 Correct 6 ms 29276 KB Output is correct
34 Correct 7 ms 29016 KB Output is correct
35 Correct 22 ms 29284 KB Output is correct
36 Correct 7 ms 29276 KB Output is correct
37 Correct 7 ms 29020 KB Output is correct
38 Correct 25 ms 29276 KB Output is correct
39 Correct 25 ms 29276 KB Output is correct
40 Correct 20 ms 29020 KB Output is correct
41 Correct 18 ms 29284 KB Output is correct
42 Correct 6 ms 29272 KB Output is correct
43 Correct 8 ms 29020 KB Output is correct
44 Correct 30 ms 29328 KB Output is correct
45 Correct 6 ms 29272 KB Output is correct
46 Correct 31 ms 29256 KB Output is correct
47 Correct 7 ms 29276 KB Output is correct
48 Correct 6 ms 29020 KB Output is correct
49 Correct 7 ms 29276 KB Output is correct
50 Correct 7 ms 29020 KB Output is correct
51 Correct 7 ms 29016 KB Output is correct
52 Execution timed out 4086 ms 47416 KB Time limit exceeded
53 Halted 0 ms 0 KB -