제출 #140742

#제출 시각아이디문제언어결과실행 시간메모리
140742rzbtEvacuation plan (IZhO18_plan)C++14
0 / 100
588 ms524292 KiB
#include <bits/stdc++.h> #define mp make_pair #define pb push_back #define F first #define S second #define all(x) x.begin(),x.end() #define MAXN 200005 using namespace std; int n,m,q; vector<int> niz[MAXN]; int predak[MAXN][21]; int dubina[MAXN]; int a[MAXN]; set<int> s[MAXN],sp[MAXN]; void dfs(int t,int o,int h){ predak[t][0]=o; dubina[t]=h; for(auto x:niz[t]) if(x!=o) dfs(x,t,h+1); } int lca(int a, int b){ if(dubina[b]>dubina[a])swap(a,b); for(int j=20;j>=0;j--){ if(dubina[predak[a][j]]>=dubina[b])a=predak[a][j]; } if(a==b)return a; for(int j=20;j>=0;j--){ if(predak[a][j]!=predak[b][j]){ a=predak[a][j]; b=predak[b][j]; } } return predak[a][0]; } int main() { scanf("%d %d %d", &n, &m, &q); for(int i=1;i<n;i++){ int t1,t2; scanf("%d %d", &t1, &t2); niz[t1].pb(t2); niz[t2].pb(t1); } dfs(1,0,1); for(int j=1;j<21;j++) for(int i=1;i<=n;i++) predak[i][j]=predak[i][predak[i][j-1]]; for(int i=1;i<=m;i++) scanf("%d",a+i); for(int i=1;i<m;i++) s[lca(a[i],a[i+1])].insert(i); for(int i=1;i<=m;i++) sp[a[i]].insert(i); while(q--){ int qt; //FITTER HAPPIER MORE PRODUCTIVE scanf("%d", &qt); if(qt==1){ int pos,x; scanf("%d %d", &pos,&x); if(pos!=1)s[lca(a[pos],a[pos-1])].erase(pos-1); if(pos!=m)s[lca(a[pos],a[pos+1])].erase(pos); sp[a[pos]].erase(pos); a[pos]=x; if(pos!=1)s[lca(a[pos],a[pos-1])].insert(pos-1); if(pos!=m)s[lca(a[pos],a[pos+1])].insert(pos); sp[a[pos]].insert(pos); }else if(qt==2){ int l,r,x; scanf("%d %d %d", &l, &r, &x); //printf(" %d %d\n",sp[x].size(),s[x].size()); int t1=0,t2=0; if(!sp[x].empty() && sp[x].lower_bound(l)!=sp[x].end())t1=*(sp[x].lower_bound(l)); if(!s[x].empty() && s[x].lower_bound(l)!=s[x].end())t2=*(s[x].lower_bound(l)); //printf(" %d %d %d %d\n",sp[x].size(),s[x].size(),t1,t2); if(t1<=r && t1)printf("%d %d\n",t1,t1); else if(t2<r && t2)printf("%d %d\n",t2,t2+1); else printf("-1 -1\n"); } else{ int x,y; scanf("%d %d", &x, &y); printf(" %d\n",lca(a[x],a[y])); } } return 0; }

컴파일 시 표준 에러 (stderr) 메시지

plan.cpp: In function 'int main()':
plan.cpp:46:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d %d", &n, &m, &q);
     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
plan.cpp:49:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d %d", &t1, &t2);
         ~~~~~^~~~~~~~~~~~~~~~~~~
plan.cpp:58:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d",a+i);
         ~~~~~^~~~~~~~~~
plan.cpp:65:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", &qt);
         ~~~~~^~~~~~~~~~~
plan.cpp:68:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf("%d %d", &pos,&x);
             ~~~~~^~~~~~~~~~~~~~~~~~
plan.cpp:81:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf("%d %d %d", &l, &r, &x);
             ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
plan.cpp:93:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf("%d %d", &x, &y);
             ~~~~~^~~~~~~~~~~~~~~~~
#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...