# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
41552 | 2018-02-18T20:57:46 Z | Pajaraja | Birthday gift (IZhO18_treearray) | C++14 | 22 ms | 24344 KB |
#include <bits/stdc++.h> #define MAXN 200007 #define MAXL 22 using namespace std; vector<int> g[MAXN]; set<int> k[MAXN],km[MAXN]; set<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
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 19 ms | 23928 KB | n=5 |
2 | Correct | 20 ms | 23928 KB | n=100 |
3 | Correct | 20 ms | 24072 KB | n=100 |
4 | Correct | 20 ms | 24072 KB | n=100 |
5 | Correct | 20 ms | 24072 KB | n=100 |
6 | Correct | 19 ms | 24140 KB | n=100 |
7 | Correct | 20 ms | 24248 KB | n=100 |
8 | Correct | 19 ms | 24248 KB | n=100 |
9 | Correct | 21 ms | 24248 KB | n=100 |
10 | Correct | 19 ms | 24296 KB | n=100 |
11 | Correct | 19 ms | 24296 KB | n=100 |
12 | Correct | 19 ms | 24296 KB | n=100 |
13 | Correct | 22 ms | 24296 KB | n=100 |
14 | Correct | 21 ms | 24296 KB | n=100 |
15 | Correct | 19 ms | 24300 KB | n=100 |
16 | Correct | 21 ms | 24344 KB | n=100 |
17 | Correct | 22 ms | 24344 KB | n=100 |
18 | Correct | 20 ms | 24344 KB | n=100 |
19 | Correct | 20 ms | 24344 KB | n=100 |
20 | Incorrect | 19 ms | 24344 KB | Jury has the answer but participant has not |
21 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 19 ms | 23928 KB | n=5 |
2 | Correct | 20 ms | 23928 KB | n=100 |
3 | Correct | 20 ms | 24072 KB | n=100 |
4 | Correct | 20 ms | 24072 KB | n=100 |
5 | Correct | 20 ms | 24072 KB | n=100 |
6 | Correct | 19 ms | 24140 KB | n=100 |
7 | Correct | 20 ms | 24248 KB | n=100 |
8 | Correct | 19 ms | 24248 KB | n=100 |
9 | Correct | 21 ms | 24248 KB | n=100 |
10 | Correct | 19 ms | 24296 KB | n=100 |
11 | Correct | 19 ms | 24296 KB | n=100 |
12 | Correct | 19 ms | 24296 KB | n=100 |
13 | Correct | 22 ms | 24296 KB | n=100 |
14 | Correct | 21 ms | 24296 KB | n=100 |
15 | Correct | 19 ms | 24300 KB | n=100 |
16 | Correct | 21 ms | 24344 KB | n=100 |
17 | Correct | 22 ms | 24344 KB | n=100 |
18 | Correct | 20 ms | 24344 KB | n=100 |
19 | Correct | 20 ms | 24344 KB | n=100 |
20 | Incorrect | 19 ms | 24344 KB | Jury has the answer but participant has not |
21 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 19 ms | 23928 KB | n=5 |
2 | Correct | 20 ms | 23928 KB | n=100 |
3 | Correct | 20 ms | 24072 KB | n=100 |
4 | Correct | 20 ms | 24072 KB | n=100 |
5 | Correct | 20 ms | 24072 KB | n=100 |
6 | Correct | 19 ms | 24140 KB | n=100 |
7 | Correct | 20 ms | 24248 KB | n=100 |
8 | Correct | 19 ms | 24248 KB | n=100 |
9 | Correct | 21 ms | 24248 KB | n=100 |
10 | Correct | 19 ms | 24296 KB | n=100 |
11 | Correct | 19 ms | 24296 KB | n=100 |
12 | Correct | 19 ms | 24296 KB | n=100 |
13 | Correct | 22 ms | 24296 KB | n=100 |
14 | Correct | 21 ms | 24296 KB | n=100 |
15 | Correct | 19 ms | 24300 KB | n=100 |
16 | Correct | 21 ms | 24344 KB | n=100 |
17 | Correct | 22 ms | 24344 KB | n=100 |
18 | Correct | 20 ms | 24344 KB | n=100 |
19 | Correct | 20 ms | 24344 KB | n=100 |
20 | Incorrect | 19 ms | 24344 KB | Jury has the answer but participant has not |
21 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 19 ms | 23928 KB | n=5 |
2 | Correct | 20 ms | 23928 KB | n=100 |
3 | Correct | 20 ms | 24072 KB | n=100 |
4 | Correct | 20 ms | 24072 KB | n=100 |
5 | Correct | 20 ms | 24072 KB | n=100 |
6 | Correct | 19 ms | 24140 KB | n=100 |
7 | Correct | 20 ms | 24248 KB | n=100 |
8 | Correct | 19 ms | 24248 KB | n=100 |
9 | Correct | 21 ms | 24248 KB | n=100 |
10 | Correct | 19 ms | 24296 KB | n=100 |
11 | Correct | 19 ms | 24296 KB | n=100 |
12 | Correct | 19 ms | 24296 KB | n=100 |
13 | Correct | 22 ms | 24296 KB | n=100 |
14 | Correct | 21 ms | 24296 KB | n=100 |
15 | Correct | 19 ms | 24300 KB | n=100 |
16 | Correct | 21 ms | 24344 KB | n=100 |
17 | Correct | 22 ms | 24344 KB | n=100 |
18 | Correct | 20 ms | 24344 KB | n=100 |
19 | Correct | 20 ms | 24344 KB | n=100 |
20 | Incorrect | 19 ms | 24344 KB | Jury has the answer but participant has not |
21 | Halted | 0 ms | 0 KB | - |