Submission #334825

#TimeUsernameProblemLanguageResultExecution timeMemory
334825juggernautBirthday gift (IZhO18_treearray)C++14
56 / 100
153 ms748 KiB
#include<bits/stdc++.h> using namespace std; int n,m,q,a[2005],up[2005][11],tin[2005],tout[2005],timer; vector<int>g[2005]; void dfs(int v,int p){ tin[v]=++timer; up[v][0]=p; for(int i=1;i<11;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=10;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]); while(q--){ int type; scanf("%d",&type); if(type&1){ int pos,val; scanf("%d%d",&pos,&val); a[pos]=val; }else{ int l,r,v,al=-1,ar=-1; scanf("%d%d%d",&l,&r,&v); for(int i=l;i<r;i++){ if(a[i]==v){ al=i; ar=i; break; } if(lca(a[i],a[i+1])==v){ al=i; ar=i+1; break; } } if(a[r]==v){ al=r; ar=r; } printf("%d %d\n",al,ar); } } }

Compilation message (stderr)

treearray.cpp: In function 'int main()':
treearray.cpp:23:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   23 |     scanf("%d%d%d",&n,&m,&q);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~
treearray.cpp:26:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   26 |         scanf("%d%d",&x,&y);
      |         ~~~~~^~~~~~~~~~~~~~
treearray.cpp:31:31: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   31 |     for(int i=1;i<=m;i++)scanf("%d",&a[i]);
      |                          ~~~~~^~~~~~~~~~~~
treearray.cpp:34:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   34 |         scanf("%d",&type);
      |         ~~~~~^~~~~~~~~~~~
treearray.cpp:37:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   37 |             scanf("%d%d",&pos,&val);
      |             ~~~~~^~~~~~~~~~~~~~~~~~
treearray.cpp:41:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   41 |             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...