# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
89629 | 2018-12-17T16:51:40 Z | Vardanyan | Birthday gift (IZhO18_treearray) | C++14 | 32 ms | 30412 KB |
#include <bits/stdc++.h> using namespace std; const int N = 2*1000*100+5; int a[N]; vector<int> g[N]; int colour[N]; int par[N]; int dp[N][20]; int depth[N]; void kaxel(int v,int dep = 0,int p = -1){ par[v] = p; dp[v][0] = p; depth[v] = dep; for(int i = 0;i<g[v].size();i++){ int to = g[v][i]; if(to == p) continue; kaxel(to,dep+1,v); } } int lca(int a,int b){ if(depth[a]<depth[b]) swap(a,b); if(a == b) return a; int dif = depth[a]-depth[b]; for(int i = 19;i>=0;i--){ if((dif>>i)&1) a = dp[a][i]; } // cout<<a<<" "<<b<<endl; if(a == b) return a; for(int i = 19;i>=0;i--){ if(dp[a][i] == -1 || dp[b][i] == -1) continue; if(dp[a][i] == dp[b][i]) continue; a = dp[a][i]; b = dp[b][i]; } if(a == b) return a; a = dp[a][0]; return a; } multiset<int> ANS[N]; int main(){ int n,m,q; scanf("%d%d%d",&n,&m,&q); for(int i = 1;i<=n-1;i++){ int x,y; scanf("%d%d",&x,&y); g[x].push_back(y); g[y].push_back(x); } memset(dp,-1,sizeof dp); kaxel(1); for(int j = 1;j<=19;j++){ for(int i = 1;i<=n;i++){ if(dp[i][j-1] == -1) dp[i][j] = -1; else dp[i][j] = dp[dp[i][j-1]][j-1]; } } /*int x,y; while(cin>>x>>y){ cout<<lca(x,y)<<endl; }*/ /*for(int i = 1;i<=n;i++){ for(int j = 0;j<=4;j++){ cout<<dp[i][j]<<" "; } cout<<endl; }*/ for(int i = 1;i<=m;i++) scanf("%d",&a[i]); for(int i = 1;i<=m;i++){ ANS[a[i]].insert(i); if(i == m) continue; ANS[lca(a[i],a[i+1])].insert(i); } while(q--){ int tp; scanf("%d",&tp); if(tp == 1){ int pos,val; scanf("%d%d",&pos,&val); int now = a[pos]; ANS[a[pos]].erase(ANS[a[pos]].find(pos)); if(pos>1){ ANS[lca(a[pos],a[pos-1])].erase(ANS[lca(a[pos],a[pos-1])].find(pos-1)); } if(pos<m){ ANS[lca(a[pos],a[pos+1])].erase(ANS[lca(a[pos],a[pos+1])].find(pos)); } a[pos] = val; ANS[val].insert(pos); if(pos-1>0) ANS[lca(a[pos],a[pos-1])].insert(pos-1); if(pos+1<=m) ANS[lca(a[pos],a[pos+1])].insert(pos); } else{ int l,r,v; scanf("%d%d%d",&l,&r,&v); multiset<int>::iterator it = ANS[v].lower_bound(l); if(it == ANS[v].end()){ printf("-1 -1\n"); continue; } int pos = *it; if(pos>r){ printf("-1 -1\n"); continue; } if(a[pos] == v){ printf("%d %d\n",pos,pos); continue; } printf("%d %d\n",pos,pos+1); } } return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 26 ms | 30072 KB | n=5 |
2 | Correct | 27 ms | 30072 KB | n=100 |
3 | Correct | 29 ms | 30344 KB | n=100 |
4 | Correct | 30 ms | 30344 KB | n=100 |
5 | Correct | 28 ms | 30344 KB | n=100 |
6 | Correct | 27 ms | 30412 KB | n=100 |
7 | Correct | 32 ms | 30412 KB | n=100 |
8 | Correct | 28 ms | 30412 KB | n=100 |
9 | Correct | 26 ms | 30412 KB | n=100 |
10 | Correct | 30 ms | 30412 KB | n=100 |
11 | Correct | 30 ms | 30412 KB | n=100 |
12 | Incorrect | 31 ms | 30412 KB | Wrong output format. |
13 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 26 ms | 30072 KB | n=5 |
2 | Correct | 27 ms | 30072 KB | n=100 |
3 | Correct | 29 ms | 30344 KB | n=100 |
4 | Correct | 30 ms | 30344 KB | n=100 |
5 | Correct | 28 ms | 30344 KB | n=100 |
6 | Correct | 27 ms | 30412 KB | n=100 |
7 | Correct | 32 ms | 30412 KB | n=100 |
8 | Correct | 28 ms | 30412 KB | n=100 |
9 | Correct | 26 ms | 30412 KB | n=100 |
10 | Correct | 30 ms | 30412 KB | n=100 |
11 | Correct | 30 ms | 30412 KB | n=100 |
12 | Incorrect | 31 ms | 30412 KB | Wrong output format. |
13 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 26 ms | 30072 KB | n=5 |
2 | Correct | 27 ms | 30072 KB | n=100 |
3 | Correct | 29 ms | 30344 KB | n=100 |
4 | Correct | 30 ms | 30344 KB | n=100 |
5 | Correct | 28 ms | 30344 KB | n=100 |
6 | Correct | 27 ms | 30412 KB | n=100 |
7 | Correct | 32 ms | 30412 KB | n=100 |
8 | Correct | 28 ms | 30412 KB | n=100 |
9 | Correct | 26 ms | 30412 KB | n=100 |
10 | Correct | 30 ms | 30412 KB | n=100 |
11 | Correct | 30 ms | 30412 KB | n=100 |
12 | Incorrect | 31 ms | 30412 KB | Wrong output format. |
13 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 26 ms | 30072 KB | n=5 |
2 | Correct | 27 ms | 30072 KB | n=100 |
3 | Correct | 29 ms | 30344 KB | n=100 |
4 | Correct | 30 ms | 30344 KB | n=100 |
5 | Correct | 28 ms | 30344 KB | n=100 |
6 | Correct | 27 ms | 30412 KB | n=100 |
7 | Correct | 32 ms | 30412 KB | n=100 |
8 | Correct | 28 ms | 30412 KB | n=100 |
9 | Correct | 26 ms | 30412 KB | n=100 |
10 | Correct | 30 ms | 30412 KB | n=100 |
11 | Correct | 30 ms | 30412 KB | n=100 |
12 | Incorrect | 31 ms | 30412 KB | Wrong output format. |
13 | Halted | 0 ms | 0 KB | - |