Submission #1092286

# Submission time Handle Problem Language Result Execution time Memory
1092286 2024-09-23T17:09:17 Z svm Experimental Charges (NOI19_charges) C++14
100 / 100
26 ms 2708 KB
#include <bits/stdc++.h>

#define TASK "charges"

using namespace std;

#define fst first
#define snd second

typedef long long int64;
typedef pair<int, int> pii;

const int MAXN = 1e5 + 55;

pii par[MAXN];

pii find_set(int u) {
    if (par[u].fst == u) return pii(u, 0);
    pii pu = find_set(par[u].fst);
    return par[u] = pii(pu.fst, pu.snd ^ par[u].snd);
}

void join(int u, int v, bool diff) {
    pii pu = find_set(u);
    pii pv = find_set(v);
    if (pu.fst == pv.fst) return;
    par[pv.fst] = pii(pu.fst, pu.snd ^ pv.snd ^ diff);
}

int main() {
    cin.tie(0)->sync_with_stdio(false);
    int n, q; cin >> n >> q;
    for (int u = 1; u <= n; u++)
        par[u] = pii(u, 0);
    while (q--) {
        string t; int u, v;
        cin >> t >> u >> v;
        if (t == "Q") {
            pii pu = find_set(u), pv = find_set(v);
            if (pu.fst != pv.fst) {
                puts("?");
                continue;
            }
            puts(pu.snd == pv.snd ? "R" : "A");
            continue;
        }
        join(u, v, (t == "A"));
    }
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 2140 KB Output is correct
2 Correct 15 ms 1964 KB Output is correct
3 Correct 18 ms 2136 KB Output is correct
4 Correct 16 ms 2140 KB Output is correct
5 Correct 16 ms 2140 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 23 ms 2648 KB Output is correct
2 Correct 19 ms 2392 KB Output is correct
3 Correct 18 ms 2612 KB Output is correct
4 Correct 21 ms 2396 KB Output is correct
5 Correct 20 ms 2652 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 18 ms 2396 KB Output is correct
2 Correct 18 ms 2708 KB Output is correct
3 Correct 20 ms 2392 KB Output is correct
4 Correct 22 ms 2384 KB Output is correct
5 Correct 20 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 15 ms 2140 KB Output is correct
7 Correct 15 ms 1964 KB Output is correct
8 Correct 18 ms 2136 KB Output is correct
9 Correct 16 ms 2140 KB Output is correct
10 Correct 16 ms 2140 KB Output is correct
11 Correct 23 ms 2648 KB Output is correct
12 Correct 19 ms 2392 KB Output is correct
13 Correct 18 ms 2612 KB Output is correct
14 Correct 21 ms 2396 KB Output is correct
15 Correct 20 ms 2652 KB Output is correct
16 Correct 18 ms 2396 KB Output is correct
17 Correct 18 ms 2708 KB Output is correct
18 Correct 20 ms 2392 KB Output is correct
19 Correct 22 ms 2384 KB Output is correct
20 Correct 20 ms 2396 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 1 ms 344 KB Output is correct
26 Correct 18 ms 2396 KB Output is correct
27 Correct 21 ms 2396 KB Output is correct
28 Correct 26 ms 2356 KB Output is correct
29 Correct 20 ms 2384 KB Output is correct
30 Correct 20 ms 2396 KB Output is correct