Submission #367647

#TimeUsernameProblemLanguageResultExecution timeMemory
367647ritul_kr_singhExperimental Charges (NOI19_charges)C++17
100 / 100
32 ms4972 KiB
//#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...