# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
140741 | 2019-08-04T22:56:52 Z | rzbt | Birthday gift (IZhO18_treearray) | C++14 | 22 ms | 23928 KB |
#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{ 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)!=sp[x].end())t2=*(s[x].lower_bound(l)); 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"); } } return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 22 ms | 23928 KB | n=5 |
2 | Incorrect | 22 ms | 23804 KB | Wrong output format. |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 22 ms | 23928 KB | n=5 |
2 | Incorrect | 22 ms | 23804 KB | Wrong output format. |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 22 ms | 23928 KB | n=5 |
2 | Incorrect | 22 ms | 23804 KB | Wrong output format. |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 22 ms | 23928 KB | n=5 |
2 | Incorrect | 22 ms | 23804 KB | Wrong output format. |
3 | Halted | 0 ms | 0 KB | - |