Submission #899600

#TimeUsernameProblemLanguageResultExecution timeMemory
899600pccExperimental Charges (NOI19_charges)C++14
100 / 100
18 ms3420 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define pll pair<ll,ll> #define pii pair<int,int> #define fs first #define sc second #define tlll tuple<ll,ll,ll> const int mxn = 2e5+10; int dsu[mxn],sz[mxn]; int n,q; int root(int k){ return k == dsu[k]?k:dsu[k] = root(dsu[k]); } inline void onion(int a,int b){ a = root(a),b = root(b); if(a == b)return; if(sz[a]<sz[b])swap(a,b); dsu[b] = a; sz[a] += sz[b]; return; } int main(){ ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); cin>>n>>q; for(int i = 1;i<=n*2;i++)dsu[i] = i,sz[i] = 1; while(q--){ char c;int a,b; cin>>c>>a>>b; if(c == 'Q'){ if(root(a) == root(b))cout<<"R\n"; else if(root(a) == root(b+n))cout<<"A\n"; else cout<<"?\n"; } else if(c == 'R'){ onion(a,b); onion(a+n,b+n); } else{ onion(a,b+n); onion(a+n,b); } } return 0; }
#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...