Submission #367647

# Submission time Handle Problem Language Result Execution time Memory
367647 2021-02-17T20:25:48 Z ritul_kr_singh Experimental Charges (NOI19_charges) C++17
100 / 100
32 ms 4972 KB
//#pragma GCC optimize("Ofast,unroll-loops")
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define sp << " " <<
#define nl << "\n"

int p[200000], sz[200000];

int parent(int u){
    return p[u] == u ? u : p[u] = parent(p[u]);
}

void merge(int a, int b){
    a = parent(a), b = parent(b);
    if(a==b) return;
    if(sz[a] < sz[b]) swap(a, b);
    sz[a] += sz[b];
    p[b] = a;
}

signed main(){
    ios_base::sync_with_stdio(false); cin.tie(nullptr);
    int n, q; cin >> n >> q;
    for(int i=0; i<2*n; ++i){
        sz[i] = 1;
        p[i] = i;
    }
    while(q--){
        char t; cin >> t;
        int x, y; cin >> x >> y;
        --x, --y;
        if(t=='Q'){
            bool rep = parent(2*x) == parent(2*y), att = parent(2*x) == parent(2*y + 1);
            if(rep) cout << "R\n";
            else if(att) cout << "A\n";
            else cout << "?\n";
        }else{
            merge(2*x, 2*y + (t=='A'));
            merge(2*y + (t=='R'), 2*x + (t=='A') + (t=='R'));
        }
//        for(int i=0; i<2*n; ++i) cout << i sp parent(i) nl;
    }
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 27 ms 4332 KB Output is correct
2 Correct 23 ms 4460 KB Output is correct
3 Correct 29 ms 4332 KB Output is correct
4 Correct 32 ms 4332 KB Output is correct
5 Correct 28 ms 4332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 27 ms 4844 KB Output is correct
2 Correct 30 ms 4844 KB Output is correct
3 Correct 29 ms 4844 KB Output is correct
4 Correct 30 ms 4716 KB Output is correct
5 Correct 31 ms 4972 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 29 ms 4716 KB Output is correct
2 Correct 30 ms 4620 KB Output is correct
3 Correct 28 ms 4588 KB Output is correct
4 Correct 29 ms 4844 KB Output is correct
5 Correct 31 ms 4716 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 512 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 2 ms 408 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 27 ms 4332 KB Output is correct
7 Correct 23 ms 4460 KB Output is correct
8 Correct 29 ms 4332 KB Output is correct
9 Correct 32 ms 4332 KB Output is correct
10 Correct 28 ms 4332 KB Output is correct
11 Correct 27 ms 4844 KB Output is correct
12 Correct 30 ms 4844 KB Output is correct
13 Correct 29 ms 4844 KB Output is correct
14 Correct 30 ms 4716 KB Output is correct
15 Correct 31 ms 4972 KB Output is correct
16 Correct 29 ms 4716 KB Output is correct
17 Correct 30 ms 4620 KB Output is correct
18 Correct 28 ms 4588 KB Output is correct
19 Correct 29 ms 4844 KB Output is correct
20 Correct 31 ms 4716 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 1 ms 512 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 2 ms 408 KB Output is correct
26 Correct 26 ms 4748 KB Output is correct
27 Correct 30 ms 4716 KB Output is correct
28 Correct 30 ms 4588 KB Output is correct
29 Correct 30 ms 4736 KB Output is correct
30 Correct 29 ms 4588 KB Output is correct