Submission #888099

#TimeUsernameProblemLanguageResultExecution timeMemory
888099Ahmed_SolymanKlasika (COCI20_klasika)C++14
33 / 110
1384 ms524288 KiB
/* In the name of Allah made by: Ahmed_Solyman */ #include <bits/stdc++.h> #include <ext/rope> using namespace std; using namespace __gnu_cxx; #pragma GCC optimize("-Ofast") #pragma GCC optimize("-O1") //-------------------------------------------------------------// typedef long long ll; typedef unsigned long long ull; #define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); #define PI acos(-1) #define lb lower_bound #define ub upper_bound #define endl '\n' #define all(v) v.begin(),v.end() #define allr(v) v.rbegin(),v.rend() #define sum_to(n) (n*(n+1))/2 #define pb push_back #define pf push_front #define fil(arr,x) memset(arr,x,sizeof(arr)) const ll mod=1e9+7; int dx[8]={0,1,0,-1,1,1,-1,-1}; int dy[8]={1,0,-1,0,1,-1,-1,1}; //-------------------------------------------------------------// ll lcm(ll a,ll b) { return (max(a,b)/__gcd(a,b))*min(a,b); } void person_bool(bool x) { cout<<(x?"YES":"NO")<<endl; } const int N=2e5+5; set<int>s[30*N]; int id=1,mark=1,l[2*N],r[2*N],trie[30*N][2]; vector<int>adj[2*N]; void insert(int x,int ind){ int p=0; for(int i=29;i>=0;i--){ bool g=x & (1<<i); if(~trie[p][g])p=trie[p][g]; else p=trie[p][g]=id++; s[p].insert(ind); } } int solve(int a,int b){ int p=0,ret=0; for(int i=29;i>=0;i--){ bool g=a & (1<<i);g^=1; if(~trie[p][g] && s[trie[p][g]].lower_bound(l[b])!=s[trie[p][g]].end() && *s[trie[p][g]].lower_bound(l[b])<=r[b])p=trie[p][g],ret|=(1<<i); else p=trie[p][g^1]; } return ret; } void dfs(int node,int p){ l[node]=mark++; for(auto i:adj[node]) if(i!=p) dfs(i,node); r[node]=mark-1; } int main() { //freopen("input.txt","r",stdin); //freopen("output.txt","w",stdout); #ifndef ONLINE_JUDGE // freopen("input.in", "r", stdin); // freopen("output.out", "w", stdout); #endif fast fil(trie,-1); int q;cin>>q; vector<int>d(q+1); int v=2; vector<array<int,3>>e; while(q--){ string s;cin>>s; if(s=="Add"){ int u,w;cin>>u>>w; d[v]=d[u]^w; e.push_back({0,u,v}); adj[u].push_back(v++); } else{ int a,b;cin>>a>>b; e.push_back({1,a,b}); } } dfs(1,1); insert(0,l[1]); for(auto i:e){ int t=i[0],u=i[1],v=i[2]; if(t==0){ insert(d[v],l[v]); } else{ cout<<solve(d[u],v)<<endl; } } 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...