# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
542381 | 2022-03-26T10:15:18 Z | krit3379 | Birthday gift (IZhO18_treearray) | C++17 | 16 ms | 23932 KB |
#include<bits/stdc++.h> using namespace std; #define N 200005 int dep[N],bp[20][N],val[N]; vector<int> g[N]; set<int> s[N],ss[N]; void dfs(int s,int f){ dep[s]=dep[f]+1; bp[0][s]=f; for(auto x:g[s])if(x!=f)dfs(x,s); } int lca(int a,int b){ if(dep[a]>dep[b])swap(a,b); int i,dif=dep[b]-dep[a]; for(i=0;i<20;i++)if(dif&(1<<i))b=bp[i][b]; if(a==b)return a; for(i=19;i>=0;i--)if(bp[i][a]!=bp[i][b]){ a=bp[i][a]; b=bp[i][b]; } return bp[0][a]; } int main(){ int n,m,q,i,j,a,b,op,pos,v,l,r; scanf("%d %d %d",&n,&m,&q); for(i=1;i<n;i++){ scanf("%d %d",&a,&b); g[a].push_back(b); g[b].push_back(a); } for(i=1;i<=m;i++)scanf("%d",&val[i]),s[val[i]].insert(i); dfs(1,0); for(i=1;i<20;i++)for(j=1;j<=n;j++)bp[i][j]=bp[i-1][bp[i-1][j]]; for(i=1;i<n;i++)ss[lca(val[i],val[i+1])].insert(i); while(q--){ scanf("%d",&op); if(op==1){ scanf("%d %d",&pos,&v); s[val[pos]].erase(pos); s[v].insert(pos); if(pos>1){ ss[lca(val[pos],val[pos-1])].erase(pos-1); ss[lca(v,val[pos-1])].insert(pos-1); } if(pos<m){ ss[lca(val[pos],val[pos+1])].erase(pos); ss[lca(v,val[pos+1])].insert(pos); } val[pos]=v; } else{ scanf("%d %d %d",&l,&r,&v); auto it1=s[v].lower_bound(l),it2=ss[v].lower_bound(l); if(it1!=s[v].end()&&*it1<=r)printf("%d %d\n",*it1,*it1); else if(it2!=ss[v].end()&&*it2<r)printf("%d %d\n",*it2,*it2+1); else printf("-1 -1\n"); } } return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 13 ms | 23892 KB | n=5 |
2 | Correct | 13 ms | 23920 KB | n=100 |
3 | Correct | 13 ms | 23884 KB | n=100 |
4 | Correct | 12 ms | 23892 KB | n=100 |
5 | Correct | 12 ms | 23892 KB | n=100 |
6 | Correct | 12 ms | 23820 KB | n=100 |
7 | Correct | 13 ms | 23932 KB | n=100 |
8 | Correct | 14 ms | 23892 KB | n=100 |
9 | Correct | 16 ms | 23900 KB | n=100 |
10 | Correct | 15 ms | 23912 KB | n=100 |
11 | Correct | 13 ms | 23836 KB | n=100 |
12 | Correct | 11 ms | 23888 KB | n=100 |
13 | Correct | 14 ms | 23928 KB | n=100 |
14 | Correct | 13 ms | 23836 KB | n=100 |
15 | Correct | 13 ms | 23888 KB | n=100 |
16 | Correct | 13 ms | 23892 KB | n=100 |
17 | Correct | 13 ms | 23892 KB | n=100 |
18 | Correct | 16 ms | 23884 KB | n=100 |
19 | Correct | 15 ms | 23892 KB | n=100 |
20 | Correct | 13 ms | 23888 KB | n=100 |
21 | Correct | 13 ms | 23892 KB | n=100 |
22 | Correct | 13 ms | 23932 KB | n=100 |
23 | Correct | 12 ms | 23892 KB | n=100 |
24 | Correct | 12 ms | 23892 KB | n=100 |
25 | Correct | 12 ms | 23876 KB | n=100 |
26 | Incorrect | 15 ms | 23860 KB | Jury has the answer but participant has not |
27 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 13 ms | 23892 KB | n=5 |
2 | Correct | 13 ms | 23920 KB | n=100 |
3 | Correct | 13 ms | 23884 KB | n=100 |
4 | Correct | 12 ms | 23892 KB | n=100 |
5 | Correct | 12 ms | 23892 KB | n=100 |
6 | Correct | 12 ms | 23820 KB | n=100 |
7 | Correct | 13 ms | 23932 KB | n=100 |
8 | Correct | 14 ms | 23892 KB | n=100 |
9 | Correct | 16 ms | 23900 KB | n=100 |
10 | Correct | 15 ms | 23912 KB | n=100 |
11 | Correct | 13 ms | 23836 KB | n=100 |
12 | Correct | 11 ms | 23888 KB | n=100 |
13 | Correct | 14 ms | 23928 KB | n=100 |
14 | Correct | 13 ms | 23836 KB | n=100 |
15 | Correct | 13 ms | 23888 KB | n=100 |
16 | Correct | 13 ms | 23892 KB | n=100 |
17 | Correct | 13 ms | 23892 KB | n=100 |
18 | Correct | 16 ms | 23884 KB | n=100 |
19 | Correct | 15 ms | 23892 KB | n=100 |
20 | Correct | 13 ms | 23888 KB | n=100 |
21 | Correct | 13 ms | 23892 KB | n=100 |
22 | Correct | 13 ms | 23932 KB | n=100 |
23 | Correct | 12 ms | 23892 KB | n=100 |
24 | Correct | 12 ms | 23892 KB | n=100 |
25 | Correct | 12 ms | 23876 KB | n=100 |
26 | Incorrect | 15 ms | 23860 KB | Jury has the answer but participant has not |
27 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 13 ms | 23892 KB | n=5 |
2 | Correct | 13 ms | 23920 KB | n=100 |
3 | Correct | 13 ms | 23884 KB | n=100 |
4 | Correct | 12 ms | 23892 KB | n=100 |
5 | Correct | 12 ms | 23892 KB | n=100 |
6 | Correct | 12 ms | 23820 KB | n=100 |
7 | Correct | 13 ms | 23932 KB | n=100 |
8 | Correct | 14 ms | 23892 KB | n=100 |
9 | Correct | 16 ms | 23900 KB | n=100 |
10 | Correct | 15 ms | 23912 KB | n=100 |
11 | Correct | 13 ms | 23836 KB | n=100 |
12 | Correct | 11 ms | 23888 KB | n=100 |
13 | Correct | 14 ms | 23928 KB | n=100 |
14 | Correct | 13 ms | 23836 KB | n=100 |
15 | Correct | 13 ms | 23888 KB | n=100 |
16 | Correct | 13 ms | 23892 KB | n=100 |
17 | Correct | 13 ms | 23892 KB | n=100 |
18 | Correct | 16 ms | 23884 KB | n=100 |
19 | Correct | 15 ms | 23892 KB | n=100 |
20 | Correct | 13 ms | 23888 KB | n=100 |
21 | Correct | 13 ms | 23892 KB | n=100 |
22 | Correct | 13 ms | 23932 KB | n=100 |
23 | Correct | 12 ms | 23892 KB | n=100 |
24 | Correct | 12 ms | 23892 KB | n=100 |
25 | Correct | 12 ms | 23876 KB | n=100 |
26 | Incorrect | 15 ms | 23860 KB | Jury has the answer but participant has not |
27 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 13 ms | 23892 KB | n=5 |
2 | Correct | 13 ms | 23920 KB | n=100 |
3 | Correct | 13 ms | 23884 KB | n=100 |
4 | Correct | 12 ms | 23892 KB | n=100 |
5 | Correct | 12 ms | 23892 KB | n=100 |
6 | Correct | 12 ms | 23820 KB | n=100 |
7 | Correct | 13 ms | 23932 KB | n=100 |
8 | Correct | 14 ms | 23892 KB | n=100 |
9 | Correct | 16 ms | 23900 KB | n=100 |
10 | Correct | 15 ms | 23912 KB | n=100 |
11 | Correct | 13 ms | 23836 KB | n=100 |
12 | Correct | 11 ms | 23888 KB | n=100 |
13 | Correct | 14 ms | 23928 KB | n=100 |
14 | Correct | 13 ms | 23836 KB | n=100 |
15 | Correct | 13 ms | 23888 KB | n=100 |
16 | Correct | 13 ms | 23892 KB | n=100 |
17 | Correct | 13 ms | 23892 KB | n=100 |
18 | Correct | 16 ms | 23884 KB | n=100 |
19 | Correct | 15 ms | 23892 KB | n=100 |
20 | Correct | 13 ms | 23888 KB | n=100 |
21 | Correct | 13 ms | 23892 KB | n=100 |
22 | Correct | 13 ms | 23932 KB | n=100 |
23 | Correct | 12 ms | 23892 KB | n=100 |
24 | Correct | 12 ms | 23892 KB | n=100 |
25 | Correct | 12 ms | 23876 KB | n=100 |
26 | Incorrect | 15 ms | 23860 KB | Jury has the answer but participant has not |
27 | Halted | 0 ms | 0 KB | - |