Submission #334834

#TimeUsernameProblemLanguageResultExecution timeMemory
334834juggernautBirthday gift (IZhO18_treearray)C++14
0 / 100
18 ms23916 KiB
#include<bits/stdc++.h> using namespace std; int n,m,q,a[200005],up[200005][18],tin[200005],tout[200005],timer; vector<int>g[200005]; set<int>lc[200005],ar[200005]; set<int>::iterator it; void dfs(int v,int p){ tin[v]=++timer; up[v][0]=p; for(int i=1;i<18;i++)up[v][i]=up[up[v][i-1]][i-1]; for(int to:g[v])if(to!=p)dfs(to,v); tout[v]=++timer; } bool upper(int a,int b){ return tin[a]<=tin[b]&&tout[a]>=tout[b]; } int lca(int a,int b){ if(upper(a,b))return a; if(upper(b,a))return b; for(int i=17;i>=0;i--) if(!upper(up[a][i],b))a=up[a][i]; return up[a][0]; } int main(){ scanf("%d%d%d",&n,&m,&q); for(int i=1;i<n;i++){ int x,y; scanf("%d%d",&x,&y); g[x].push_back(y); g[y].push_back(x); } dfs(1,1); for(int i=1;i<=m;i++){ scanf("%d",&a[i]); ar[a[i]].insert(i); } for(int i=1;i<m;i++) lc[lca(a[i],a[i+1])].insert(i); while(q--){ int type; scanf("%d",&type); if(type&1){ int pos,val; scanf("%d%d",&pos,&val); ar[a[pos]].erase(pos); if(pos>1) lc[lca(a[pos],a[pos-1])].erase(pos-1); if(pos<m) lc[lca(a[pos],a[pos+1])].erase(pos); a[pos]=val; if(pos>1) lc[lca(a[pos],a[pos-1])].insert(pos-1); if(pos<m) lc[lca(a[pos],a[pos+1])].insert(pos); ar[a[pos]].insert(pos); }else{ int l,r,v,al=-1,arr=-1; scanf("%d%d%d",&l,&r,&v); //Case al=arr it=ar[v].lower_bound(l); if(it!=ar[v].end()) if(*it<=r&&*it>=l)al=arr=*it; //Case al+1=arr it=lc[v].lower_bound(l); if(it!=lc[v].end()) if(*it<=r&&*it>=l)al=*it,arr=al+1; printf("%d %d\n",al,arr); } } }

Compilation message (stderr)

treearray.cpp: In function 'int main()':
treearray.cpp:25:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   25 |     scanf("%d%d%d",&n,&m,&q);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~
treearray.cpp:28:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   28 |         scanf("%d%d",&x,&y);
      |         ~~~~~^~~~~~~~~~~~~~
treearray.cpp:34:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   34 |         scanf("%d",&a[i]);
      |         ~~~~~^~~~~~~~~~~~
treearray.cpp:41:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   41 |         scanf("%d",&type);
      |         ~~~~~^~~~~~~~~~~~
treearray.cpp:44:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   44 |             scanf("%d%d",&pos,&val);
      |             ~~~~~^~~~~~~~~~~~~~~~~~
treearray.cpp:58:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   58 |             scanf("%d%d%d",&l,&r,&v);
      |             ~~~~~^~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...