# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
334835 | 2020-12-10T05:01:41 Z | juggernaut | Birthday gift (IZhO18_treearray) | C++14 | 17 ms | 23916 KB |
#include<bits/stdc++.h> using namespace std; int n,m,q,a[200005],up[200005][18],tin[200005],tout[200005],timer; vector<int>g[200005]; set<int>lc[200005],ar[200005]; set<int>::iterator it; void dfs(int v,int p){ tin[v]=++timer; up[v][0]=p; for(int i=1;i<18;i++)up[v][i]=up[up[v][i-1]][i-1]; for(int to:g[v])if(to!=p)dfs(to,v); tout[v]=++timer; } bool upper(int a,int b){ return tin[a]<=tin[b]&&tout[a]>=tout[b]; } int lca(int a,int b){ if(upper(a,b))return a; if(upper(b,a))return b; for(int i=17;i>=0;i--) if(!upper(up[a][i],b))a=up[a][i]; return up[a][0]; } int main(){ scanf("%d%d%d",&n,&m,&q); for(int i=1;i<n;i++){ int x,y; scanf("%d%d",&x,&y); g[x].push_back(y); g[y].push_back(x); } dfs(1,1); for(int i=1;i<=m;i++){ scanf("%d",&a[i]); ar[a[i]].insert(i); } for(int i=1;i<m;i++) lc[lca(a[i],a[i+1])].insert(i); while(q--){ int type; scanf("%d",&type); if(type&1){ int pos,val; scanf("%d%d",&pos,&val); ar[a[pos]].erase(pos); if(pos>1) lc[lca(a[pos],a[pos-1])].erase(pos-1); if(pos<m) lc[lca(a[pos],a[pos+1])].erase(pos); a[pos]=val; if(pos>1) lc[lca(a[pos],a[pos-1])].insert(pos-1); if(pos<m) lc[lca(a[pos],a[pos+1])].insert(pos); ar[a[pos]].insert(pos); }else{ int l,r,v,al=-1,arr=-1; scanf("%d%d%d",&l,&r,&v); //Case al=arr it=ar[v].lower_bound(l); if(it!=ar[v].end()) if(*it<=r)al=arr=*it; //Case al+1=arr it=lc[v].lower_bound(l); if(it!=lc[v].end()) if(*it<=r)al=*it,arr=al+1; cout<<al<<" "<<arr<<"\n"; } } }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 16 ms | 23788 KB | n=5 |
2 | Correct | 16 ms | 23808 KB | n=100 |
3 | Correct | 17 ms | 23788 KB | n=100 |
4 | Correct | 17 ms | 23788 KB | n=100 |
5 | Correct | 17 ms | 23788 KB | n=100 |
6 | Correct | 17 ms | 23916 KB | n=100 |
7 | Correct | 16 ms | 23788 KB | n=100 |
8 | Correct | 17 ms | 23788 KB | n=100 |
9 | Correct | 16 ms | 23788 KB | n=100 |
10 | Correct | 17 ms | 23788 KB | n=100 |
11 | Correct | 17 ms | 23788 KB | n=100 |
12 | Incorrect | 16 ms | 23788 KB | Wrong output format. |
13 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 16 ms | 23788 KB | n=5 |
2 | Correct | 16 ms | 23808 KB | n=100 |
3 | Correct | 17 ms | 23788 KB | n=100 |
4 | Correct | 17 ms | 23788 KB | n=100 |
5 | Correct | 17 ms | 23788 KB | n=100 |
6 | Correct | 17 ms | 23916 KB | n=100 |
7 | Correct | 16 ms | 23788 KB | n=100 |
8 | Correct | 17 ms | 23788 KB | n=100 |
9 | Correct | 16 ms | 23788 KB | n=100 |
10 | Correct | 17 ms | 23788 KB | n=100 |
11 | Correct | 17 ms | 23788 KB | n=100 |
12 | Incorrect | 16 ms | 23788 KB | Wrong output format. |
13 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 16 ms | 23788 KB | n=5 |
2 | Correct | 16 ms | 23808 KB | n=100 |
3 | Correct | 17 ms | 23788 KB | n=100 |
4 | Correct | 17 ms | 23788 KB | n=100 |
5 | Correct | 17 ms | 23788 KB | n=100 |
6 | Correct | 17 ms | 23916 KB | n=100 |
7 | Correct | 16 ms | 23788 KB | n=100 |
8 | Correct | 17 ms | 23788 KB | n=100 |
9 | Correct | 16 ms | 23788 KB | n=100 |
10 | Correct | 17 ms | 23788 KB | n=100 |
11 | Correct | 17 ms | 23788 KB | n=100 |
12 | Incorrect | 16 ms | 23788 KB | Wrong output format. |
13 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 16 ms | 23788 KB | n=5 |
2 | Correct | 16 ms | 23808 KB | n=100 |
3 | Correct | 17 ms | 23788 KB | n=100 |
4 | Correct | 17 ms | 23788 KB | n=100 |
5 | Correct | 17 ms | 23788 KB | n=100 |
6 | Correct | 17 ms | 23916 KB | n=100 |
7 | Correct | 16 ms | 23788 KB | n=100 |
8 | Correct | 17 ms | 23788 KB | n=100 |
9 | Correct | 16 ms | 23788 KB | n=100 |
10 | Correct | 17 ms | 23788 KB | n=100 |
11 | Correct | 17 ms | 23788 KB | n=100 |
12 | Incorrect | 16 ms | 23788 KB | Wrong output format. |
13 | Halted | 0 ms | 0 KB | - |