Submission #41687

#TimeUsernameProblemLanguageResultExecution timeMemory
41687IvanCBirthday gift (IZhO18_treearray)C++14
56 / 100
4096 ms34972 KiB
#include <bits/stdc++.h> using namespace std; typedef pair<int,int> ii; const int MAXN = 2*1e5 + 10; vector<int> grafo[MAXN]; int ini[MAXN],dfsNum,treearray[MAXN],n,m,q; ii vetorzao[2*MAXN],seg[8*MAXN]; void dfs(int v,int p,int depth){ ini[v] = ++dfsNum; vetorzao[dfsNum] = ii(depth,v); for(int u : grafo[v]){ if(u == p) continue; dfs(u,v,depth+1); vetorzao[++dfsNum] = ii(depth,v); } } void build(int pos,int left,int right){ if(left == right){ seg[pos] = vetorzao[left]; return; } int mid = (left+right)/2; build(2*pos,left,mid); build(2*pos+1,mid+1,right); seg[pos] = min(seg[2*pos],seg[2*pos+1]); } ii query(int pos,int left,int right,int i,int j){ if(left >= i && right <= j) return seg[pos]; int mid = (left+right)/2; if(j <= mid) return query(2*pos,left,mid,i,j); else if(i >= mid + 1) return query(2*pos+1,mid+1,right,i,j); else return min(query(2*pos,left,mid,i,j),query(2*pos+1,mid+1,right,i,j)); } ii func(int l,int r){ if(l > r) swap(l,r); return query(1,1,dfsNum,l,r); } int main(){ scanf("%d %d %d",&n,&m,&q); for(int i = 1;i<n;i++){ int u,v; scanf("%d %d",&u,&v); grafo[u].push_back(v); grafo[v].push_back(u); } dfs(1,-1,0); build(1,1,dfsNum); for(int i = 1;i<=m;i++){ scanf("%d",&treearray[i]); treearray[i] = ini[treearray[i]]; } for(int pergunta = 1;pergunta<=q;pergunta++){ int operacao; scanf("%d",&operacao); if(operacao == 1){ int idx,v; scanf("%d %d",&idx,&v); treearray[idx] = ini[v]; } else{ int l,r,v,flag = 0; scanf("%d %d %d",&l,&r,&v); for(int i = l;i<=r && !flag;i++){ if(treearray[i] == ini[v]){ printf("%d %d\n",i,i); flag = 1; } else if(i + 1 <= r && func(treearray[i],treearray[i+1]).second == v ){ printf("%d %d\n",i,i+1); flag = 1; } } if(!flag) printf("-1 -1\n"); } } return 0; }

Compilation message (stderr)

treearray.cpp: In function 'int main()':
treearray.cpp:39:28: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d %d",&n,&m,&q);
                            ^
treearray.cpp:42:23: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d",&u,&v);
                       ^
treearray.cpp:49:28: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d",&treearray[i]);
                            ^
treearray.cpp:54:24: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d",&operacao);
                        ^
treearray.cpp:57:26: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    scanf("%d %d",&idx,&v);
                          ^
treearray.cpp:62:30: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    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...