# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
41553 | 2018-02-18T21:04:15 Z | Pajaraja | Birthday gift (IZhO18_treearray) | C++14 | 25 ms | 24284 KB |
#include <bits/stdc++.h> #define MAXN 200007 #define MAXL 22 using namespace std; vector<int> g[MAXN]; multiset<int> k[MAXN],km[MAXN]; multiset<int>::iterator it; int p[MAXL][MAXN],a[MAXN],b[MAXN],in[MAXN],out[MAXN],n,cnt; void dfs(int s,int f) { p[0][s]=f; in[s]=cnt++; for(int i=0;i<g[s].size();i++) if(g[s][i]!=f) dfs(g[s][i],s); out[s]=cnt++; } bool insub(int x,int y) {return ((in[x]<=in[y])&&(out[x]>=out[y]));} void lcainit() { dfs(1,0); in[0]=-1; out[0]=2*MAXN; for(int i=1;i<MAXL;i++) for(int j=0;j<n;j++) p[i][j]=p[i-1][p[i-1][j]]; } int lca(int x,int y) { if(insub(x,y)) return x; if(insub(y,x)) return y; for(int i=MAXL-1;i>=0;i--) if(!insub(p[i][x],y)) x=p[i][x]; return p[0][x]; } int main() { int m,q; scanf("%d%d%d",&n,&m,&q); for(int i=0;i<n-1;i++) { int t1,t2; scanf("%d%d",&t1,&t2); g[t1].push_back(t2); g[t2].push_back(t1); } lcainit(); for(int i=1;i<=m;i++) scanf("%d",&a[i]); for(int i=1;i<m;i++) b[i]=lca(a[i],a[i+1]); for(int i=1;i<=m;i++) k[a[i]].insert(i); for(int i=1;i<m;i++) km[b[i]].insert(i); while(q--) { int t; scanf("%d",&t); if(t==1) { int t1,t2; scanf("%d%d",&t1,&t2); if(t1>1) { int u=lca(t2,a[t1-1]); km[b[t1-1]].erase(t1-1); km[u].insert(t1-1); b[t1-1]=u; } if(t1<m) { int u=lca(t2,a[t1+1]); km[b[t1]].erase(t1); km[u].insert(t1); b[t1]=u; } k[a[t1]].erase(t1); a[t1]=t2; k[a[t1]].insert(t1); } else { int l,r,u; scanf("%d%d%d",&l,&r,&u); it=k[u].lower_bound(l); if(it!=k[u].end() && *it<=r) {printf("%d %d\n",*it,*it); continue;} it=km[u].lower_bound(l); if(it!=km[u].end() && *it<r) {printf("%d %d\n",*it,*it+1); continue;} printf("-1 -1\n"); } } }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 25 ms | 23928 KB | n=5 |
2 | Correct | 21 ms | 23928 KB | n=100 |
3 | Correct | 21 ms | 24068 KB | n=100 |
4 | Correct | 21 ms | 24140 KB | n=100 |
5 | Correct | 21 ms | 24212 KB | n=100 |
6 | Correct | 20 ms | 24212 KB | n=100 |
7 | Correct | 20 ms | 24212 KB | n=100 |
8 | Correct | 22 ms | 24212 KB | n=100 |
9 | Correct | 20 ms | 24212 KB | n=100 |
10 | Correct | 20 ms | 24212 KB | n=100 |
11 | Correct | 19 ms | 24212 KB | n=100 |
12 | Correct | 19 ms | 24212 KB | n=100 |
13 | Correct | 22 ms | 24212 KB | n=100 |
14 | Correct | 22 ms | 24284 KB | n=100 |
15 | Correct | 22 ms | 24284 KB | n=100 |
16 | Correct | 20 ms | 24284 KB | n=100 |
17 | Correct | 20 ms | 24284 KB | n=100 |
18 | Correct | 21 ms | 24284 KB | n=100 |
19 | Correct | 20 ms | 24284 KB | n=100 |
20 | Incorrect | 21 ms | 24284 KB | Jury has the answer but participant has not |
21 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 25 ms | 23928 KB | n=5 |
2 | Correct | 21 ms | 23928 KB | n=100 |
3 | Correct | 21 ms | 24068 KB | n=100 |
4 | Correct | 21 ms | 24140 KB | n=100 |
5 | Correct | 21 ms | 24212 KB | n=100 |
6 | Correct | 20 ms | 24212 KB | n=100 |
7 | Correct | 20 ms | 24212 KB | n=100 |
8 | Correct | 22 ms | 24212 KB | n=100 |
9 | Correct | 20 ms | 24212 KB | n=100 |
10 | Correct | 20 ms | 24212 KB | n=100 |
11 | Correct | 19 ms | 24212 KB | n=100 |
12 | Correct | 19 ms | 24212 KB | n=100 |
13 | Correct | 22 ms | 24212 KB | n=100 |
14 | Correct | 22 ms | 24284 KB | n=100 |
15 | Correct | 22 ms | 24284 KB | n=100 |
16 | Correct | 20 ms | 24284 KB | n=100 |
17 | Correct | 20 ms | 24284 KB | n=100 |
18 | Correct | 21 ms | 24284 KB | n=100 |
19 | Correct | 20 ms | 24284 KB | n=100 |
20 | Incorrect | 21 ms | 24284 KB | Jury has the answer but participant has not |
21 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 25 ms | 23928 KB | n=5 |
2 | Correct | 21 ms | 23928 KB | n=100 |
3 | Correct | 21 ms | 24068 KB | n=100 |
4 | Correct | 21 ms | 24140 KB | n=100 |
5 | Correct | 21 ms | 24212 KB | n=100 |
6 | Correct | 20 ms | 24212 KB | n=100 |
7 | Correct | 20 ms | 24212 KB | n=100 |
8 | Correct | 22 ms | 24212 KB | n=100 |
9 | Correct | 20 ms | 24212 KB | n=100 |
10 | Correct | 20 ms | 24212 KB | n=100 |
11 | Correct | 19 ms | 24212 KB | n=100 |
12 | Correct | 19 ms | 24212 KB | n=100 |
13 | Correct | 22 ms | 24212 KB | n=100 |
14 | Correct | 22 ms | 24284 KB | n=100 |
15 | Correct | 22 ms | 24284 KB | n=100 |
16 | Correct | 20 ms | 24284 KB | n=100 |
17 | Correct | 20 ms | 24284 KB | n=100 |
18 | Correct | 21 ms | 24284 KB | n=100 |
19 | Correct | 20 ms | 24284 KB | n=100 |
20 | Incorrect | 21 ms | 24284 KB | Jury has the answer but participant has not |
21 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 25 ms | 23928 KB | n=5 |
2 | Correct | 21 ms | 23928 KB | n=100 |
3 | Correct | 21 ms | 24068 KB | n=100 |
4 | Correct | 21 ms | 24140 KB | n=100 |
5 | Correct | 21 ms | 24212 KB | n=100 |
6 | Correct | 20 ms | 24212 KB | n=100 |
7 | Correct | 20 ms | 24212 KB | n=100 |
8 | Correct | 22 ms | 24212 KB | n=100 |
9 | Correct | 20 ms | 24212 KB | n=100 |
10 | Correct | 20 ms | 24212 KB | n=100 |
11 | Correct | 19 ms | 24212 KB | n=100 |
12 | Correct | 19 ms | 24212 KB | n=100 |
13 | Correct | 22 ms | 24212 KB | n=100 |
14 | Correct | 22 ms | 24284 KB | n=100 |
15 | Correct | 22 ms | 24284 KB | n=100 |
16 | Correct | 20 ms | 24284 KB | n=100 |
17 | Correct | 20 ms | 24284 KB | n=100 |
18 | Correct | 21 ms | 24284 KB | n=100 |
19 | Correct | 20 ms | 24284 KB | n=100 |
20 | Incorrect | 21 ms | 24284 KB | Jury has the answer but participant has not |
21 | Halted | 0 ms | 0 KB | - |