This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
//#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 |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |