Submission #978900

# Submission time Handle Problem Language Result Execution time Memory
978900 2024-05-10T01:12:11 Z irmuun Birthday gift (IZhO18_treearray) C++17
100 / 100
994 ms 106040 KB
#include<bits/stdc++.h>

using namespace std;

#define ll long long
#define pb push_back
#define ff first
#define ss second
#define all(s) s.begin(),s.end()
#define rall(s) s.rbegin(),s.rend()

const int N=2e5+5;

int n,m,q,a[N],par[N][20],dep[N];
vector<int>adj[N];
void dfs(int x,int p){
    par[x][0]=p;
    for(int y:adj[x]){
        if(y!=p){
            dep[y]=dep[x]+1;
            dfs(y,x);
        }
    }
}
int up(int x,int d){
    for(int i=19;i>=0;i--){
        if(d&(1<<i)){
            x=par[x][i];
        }
    }
    return x;
}
int lca(int x,int y){
    if(dep[x]<dep[y]) swap(x,y);
    x=up(x,dep[x]-dep[y]);
    for(int i=19;i>=0;i--){
        if(par[x][i]!=par[y][i]){
            x=par[x][i];
            y=par[y][i];
        }
    }
    if(x!=y) x=par[x][0];
    return x;
}

int main(){
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    cin>>n>>m>>q;
    for(int i=1;i<n;i++){
        int u,v;
        cin>>u>>v;
        adj[u].pb(v);
        adj[v].pb(u);
    }
    set<int>s[N],d[N];// one/two
    for(int i=1;i<=m;i++){
        cin>>a[i];
        s[a[i]].insert(i);
    }
    dep[1]=0;
    dfs(1,1);
    for(int j=1;j<20;j++){
        for(int i=1;i<=n;i++){
            par[i][j]=par[par[i][j-1]][j-1];
        }
    }
    for(int i=1;i<m;i++){
        d[lca(a[i],a[i+1])].insert(i);
    }
    for(int i=1;i<=n;i++){
        s[i].insert(m+1);
        d[i].insert(m+1);
    }
    while(q--){
        int t;
        cin>>t;
        if(t==1){
            int pos,v;
            cin>>pos>>v;
            s[a[pos]].erase(pos);
            s[v].insert(pos);
            if(pos>1){
                d[lca(a[pos-1],a[pos])].erase(pos-1);
                d[lca(a[pos-1],v)].insert(pos-1);
            }
            if(pos<m){
                d[lca(a[pos],a[pos+1])].erase(pos);
                d[lca(v,a[pos+1])].insert(pos);
            }
            a[pos]=v;
        }
        else{
            int l,r,u;
            cin>>l>>r>>u;
            int x=*s[u].lower_bound(l);
            if(x<=r){
                cout<<x<<' '<<x<<"\n";
                continue;
            }
            x=*d[u].lower_bound(l);
            if(x<=r-1){
                cout<<x<<' '<<x+1<<"\n";
                continue;
            }
            cout<<"-1 -1\n";
        }
    }
}
# Verdict Execution time Memory Grader output
1 Correct 13 ms 25436 KB n=5
2 Correct 13 ms 25436 KB n=100
3 Correct 13 ms 25432 KB n=100
4 Correct 14 ms 25436 KB n=100
5 Correct 14 ms 25436 KB n=100
6 Correct 13 ms 25380 KB n=100
7 Correct 13 ms 25436 KB n=100
8 Correct 13 ms 25436 KB n=100
9 Correct 13 ms 25436 KB n=100
10 Correct 15 ms 25432 KB n=100
11 Correct 13 ms 25436 KB n=100
12 Correct 14 ms 25436 KB n=100
13 Correct 14 ms 25556 KB n=100
14 Correct 13 ms 25436 KB n=100
15 Correct 13 ms 25432 KB n=100
16 Correct 13 ms 25436 KB n=100
17 Correct 14 ms 25380 KB n=100
18 Correct 13 ms 25432 KB n=100
19 Correct 14 ms 25432 KB n=100
20 Correct 13 ms 25436 KB n=100
21 Correct 13 ms 25436 KB n=100
22 Correct 14 ms 25432 KB n=100
23 Correct 13 ms 25436 KB n=100
24 Correct 13 ms 25436 KB n=100
25 Correct 13 ms 25436 KB n=100
26 Correct 14 ms 25436 KB n=12
27 Correct 14 ms 25568 KB n=100
# Verdict Execution time Memory Grader output
1 Correct 13 ms 25436 KB n=5
2 Correct 13 ms 25436 KB n=100
3 Correct 13 ms 25432 KB n=100
4 Correct 14 ms 25436 KB n=100
5 Correct 14 ms 25436 KB n=100
6 Correct 13 ms 25380 KB n=100
7 Correct 13 ms 25436 KB n=100
8 Correct 13 ms 25436 KB n=100
9 Correct 13 ms 25436 KB n=100
10 Correct 15 ms 25432 KB n=100
11 Correct 13 ms 25436 KB n=100
12 Correct 14 ms 25436 KB n=100
13 Correct 14 ms 25556 KB n=100
14 Correct 13 ms 25436 KB n=100
15 Correct 13 ms 25432 KB n=100
16 Correct 13 ms 25436 KB n=100
17 Correct 14 ms 25380 KB n=100
18 Correct 13 ms 25432 KB n=100
19 Correct 14 ms 25432 KB n=100
20 Correct 13 ms 25436 KB n=100
21 Correct 13 ms 25436 KB n=100
22 Correct 14 ms 25432 KB n=100
23 Correct 13 ms 25436 KB n=100
24 Correct 13 ms 25436 KB n=100
25 Correct 13 ms 25436 KB n=100
26 Correct 14 ms 25436 KB n=12
27 Correct 14 ms 25568 KB n=100
28 Correct 13 ms 25688 KB n=500
29 Correct 13 ms 25692 KB n=500
30 Correct 14 ms 25692 KB n=500
31 Correct 14 ms 25692 KB n=500
32 Correct 14 ms 25692 KB n=500
33 Correct 13 ms 25692 KB n=500
34 Correct 15 ms 25692 KB n=500
35 Correct 14 ms 25688 KB n=500
36 Correct 18 ms 25524 KB n=500
37 Correct 15 ms 25688 KB n=500
38 Correct 13 ms 25692 KB n=500
39 Correct 13 ms 25692 KB n=500
40 Correct 13 ms 25692 KB n=500
41 Correct 13 ms 25692 KB n=500
42 Correct 13 ms 25692 KB n=500
43 Correct 14 ms 25688 KB n=500
44 Correct 13 ms 25692 KB n=500
45 Correct 16 ms 25692 KB n=500
46 Correct 14 ms 25692 KB n=500
47 Correct 13 ms 25688 KB n=500
48 Correct 13 ms 25688 KB n=500
49 Correct 14 ms 25944 KB n=500
50 Correct 17 ms 25692 KB n=500
51 Correct 15 ms 25588 KB n=500
52 Correct 14 ms 25688 KB n=500
53 Correct 14 ms 25688 KB n=500
54 Correct 14 ms 25692 KB n=500
55 Correct 13 ms 25584 KB n=278
56 Correct 13 ms 25688 KB n=500
57 Correct 14 ms 25944 KB n=500
58 Correct 15 ms 25464 KB n=500
# Verdict Execution time Memory Grader output
1 Correct 13 ms 25436 KB n=5
2 Correct 13 ms 25436 KB n=100
3 Correct 13 ms 25432 KB n=100
4 Correct 14 ms 25436 KB n=100
5 Correct 14 ms 25436 KB n=100
6 Correct 13 ms 25380 KB n=100
7 Correct 13 ms 25436 KB n=100
8 Correct 13 ms 25436 KB n=100
9 Correct 13 ms 25436 KB n=100
10 Correct 15 ms 25432 KB n=100
11 Correct 13 ms 25436 KB n=100
12 Correct 14 ms 25436 KB n=100
13 Correct 14 ms 25556 KB n=100
14 Correct 13 ms 25436 KB n=100
15 Correct 13 ms 25432 KB n=100
16 Correct 13 ms 25436 KB n=100
17 Correct 14 ms 25380 KB n=100
18 Correct 13 ms 25432 KB n=100
19 Correct 14 ms 25432 KB n=100
20 Correct 13 ms 25436 KB n=100
21 Correct 13 ms 25436 KB n=100
22 Correct 14 ms 25432 KB n=100
23 Correct 13 ms 25436 KB n=100
24 Correct 13 ms 25436 KB n=100
25 Correct 13 ms 25436 KB n=100
26 Correct 14 ms 25436 KB n=12
27 Correct 14 ms 25568 KB n=100
28 Correct 13 ms 25688 KB n=500
29 Correct 13 ms 25692 KB n=500
30 Correct 14 ms 25692 KB n=500
31 Correct 14 ms 25692 KB n=500
32 Correct 14 ms 25692 KB n=500
33 Correct 13 ms 25692 KB n=500
34 Correct 15 ms 25692 KB n=500
35 Correct 14 ms 25688 KB n=500
36 Correct 18 ms 25524 KB n=500
37 Correct 15 ms 25688 KB n=500
38 Correct 13 ms 25692 KB n=500
39 Correct 13 ms 25692 KB n=500
40 Correct 13 ms 25692 KB n=500
41 Correct 13 ms 25692 KB n=500
42 Correct 13 ms 25692 KB n=500
43 Correct 14 ms 25688 KB n=500
44 Correct 13 ms 25692 KB n=500
45 Correct 16 ms 25692 KB n=500
46 Correct 14 ms 25692 KB n=500
47 Correct 13 ms 25688 KB n=500
48 Correct 13 ms 25688 KB n=500
49 Correct 14 ms 25944 KB n=500
50 Correct 17 ms 25692 KB n=500
51 Correct 15 ms 25588 KB n=500
52 Correct 14 ms 25688 KB n=500
53 Correct 14 ms 25688 KB n=500
54 Correct 14 ms 25692 KB n=500
55 Correct 13 ms 25584 KB n=278
56 Correct 13 ms 25688 KB n=500
57 Correct 14 ms 25944 KB n=500
58 Correct 15 ms 25464 KB n=500
59 Correct 17 ms 26032 KB n=2000
60 Correct 17 ms 25944 KB n=2000
61 Correct 18 ms 26200 KB n=2000
62 Correct 16 ms 25948 KB n=2000
63 Correct 16 ms 25948 KB n=2000
64 Correct 19 ms 25948 KB n=2000
65 Correct 17 ms 25948 KB n=2000
66 Correct 16 ms 25948 KB n=2000
67 Correct 16 ms 25948 KB n=2000
68 Correct 16 ms 25884 KB n=2000
69 Correct 16 ms 25948 KB n=2000
70 Correct 15 ms 25948 KB n=2000
71 Correct 17 ms 25944 KB n=2000
72 Correct 15 ms 25948 KB n=2000
73 Correct 15 ms 25948 KB n=2000
74 Correct 16 ms 25948 KB n=1844
75 Correct 15 ms 25948 KB n=2000
76 Correct 16 ms 25948 KB n=2000
77 Correct 16 ms 25948 KB n=2000
78 Correct 15 ms 25948 KB n=2000
79 Correct 17 ms 25948 KB n=2000
80 Correct 19 ms 25948 KB n=2000
81 Correct 16 ms 25944 KB n=2000
82 Correct 16 ms 25944 KB n=2000
83 Correct 16 ms 25944 KB n=2000
84 Correct 16 ms 26036 KB n=2000
85 Correct 16 ms 25944 KB n=2000
86 Correct 18 ms 26068 KB n=2000
87 Correct 16 ms 25844 KB n=2000
88 Correct 16 ms 25944 KB n=2000
89 Correct 16 ms 26200 KB n=2000
90 Correct 16 ms 25948 KB n=2000
91 Correct 16 ms 25948 KB n=2000
# Verdict Execution time Memory Grader output
1 Correct 13 ms 25436 KB n=5
2 Correct 13 ms 25436 KB n=100
3 Correct 13 ms 25432 KB n=100
4 Correct 14 ms 25436 KB n=100
5 Correct 14 ms 25436 KB n=100
6 Correct 13 ms 25380 KB n=100
7 Correct 13 ms 25436 KB n=100
8 Correct 13 ms 25436 KB n=100
9 Correct 13 ms 25436 KB n=100
10 Correct 15 ms 25432 KB n=100
11 Correct 13 ms 25436 KB n=100
12 Correct 14 ms 25436 KB n=100
13 Correct 14 ms 25556 KB n=100
14 Correct 13 ms 25436 KB n=100
15 Correct 13 ms 25432 KB n=100
16 Correct 13 ms 25436 KB n=100
17 Correct 14 ms 25380 KB n=100
18 Correct 13 ms 25432 KB n=100
19 Correct 14 ms 25432 KB n=100
20 Correct 13 ms 25436 KB n=100
21 Correct 13 ms 25436 KB n=100
22 Correct 14 ms 25432 KB n=100
23 Correct 13 ms 25436 KB n=100
24 Correct 13 ms 25436 KB n=100
25 Correct 13 ms 25436 KB n=100
26 Correct 14 ms 25436 KB n=12
27 Correct 14 ms 25568 KB n=100
28 Correct 13 ms 25688 KB n=500
29 Correct 13 ms 25692 KB n=500
30 Correct 14 ms 25692 KB n=500
31 Correct 14 ms 25692 KB n=500
32 Correct 14 ms 25692 KB n=500
33 Correct 13 ms 25692 KB n=500
34 Correct 15 ms 25692 KB n=500
35 Correct 14 ms 25688 KB n=500
36 Correct 18 ms 25524 KB n=500
37 Correct 15 ms 25688 KB n=500
38 Correct 13 ms 25692 KB n=500
39 Correct 13 ms 25692 KB n=500
40 Correct 13 ms 25692 KB n=500
41 Correct 13 ms 25692 KB n=500
42 Correct 13 ms 25692 KB n=500
43 Correct 14 ms 25688 KB n=500
44 Correct 13 ms 25692 KB n=500
45 Correct 16 ms 25692 KB n=500
46 Correct 14 ms 25692 KB n=500
47 Correct 13 ms 25688 KB n=500
48 Correct 13 ms 25688 KB n=500
49 Correct 14 ms 25944 KB n=500
50 Correct 17 ms 25692 KB n=500
51 Correct 15 ms 25588 KB n=500
52 Correct 14 ms 25688 KB n=500
53 Correct 14 ms 25688 KB n=500
54 Correct 14 ms 25692 KB n=500
55 Correct 13 ms 25584 KB n=278
56 Correct 13 ms 25688 KB n=500
57 Correct 14 ms 25944 KB n=500
58 Correct 15 ms 25464 KB n=500
59 Correct 17 ms 26032 KB n=2000
60 Correct 17 ms 25944 KB n=2000
61 Correct 18 ms 26200 KB n=2000
62 Correct 16 ms 25948 KB n=2000
63 Correct 16 ms 25948 KB n=2000
64 Correct 19 ms 25948 KB n=2000
65 Correct 17 ms 25948 KB n=2000
66 Correct 16 ms 25948 KB n=2000
67 Correct 16 ms 25948 KB n=2000
68 Correct 16 ms 25884 KB n=2000
69 Correct 16 ms 25948 KB n=2000
70 Correct 15 ms 25948 KB n=2000
71 Correct 17 ms 25944 KB n=2000
72 Correct 15 ms 25948 KB n=2000
73 Correct 15 ms 25948 KB n=2000
74 Correct 16 ms 25948 KB n=1844
75 Correct 15 ms 25948 KB n=2000
76 Correct 16 ms 25948 KB n=2000
77 Correct 16 ms 25948 KB n=2000
78 Correct 15 ms 25948 KB n=2000
79 Correct 17 ms 25948 KB n=2000
80 Correct 19 ms 25948 KB n=2000
81 Correct 16 ms 25944 KB n=2000
82 Correct 16 ms 25944 KB n=2000
83 Correct 16 ms 25944 KB n=2000
84 Correct 16 ms 26036 KB n=2000
85 Correct 16 ms 25944 KB n=2000
86 Correct 18 ms 26068 KB n=2000
87 Correct 16 ms 25844 KB n=2000
88 Correct 16 ms 25944 KB n=2000
89 Correct 16 ms 26200 KB n=2000
90 Correct 16 ms 25948 KB n=2000
91 Correct 16 ms 25948 KB n=2000
92 Correct 571 ms 86904 KB n=200000
93 Correct 977 ms 95496 KB n=200000
94 Correct 886 ms 104160 KB n=200000
95 Correct 584 ms 93172 KB n=200000
96 Correct 535 ms 93088 KB n=200000
97 Correct 888 ms 98840 KB n=200000
98 Correct 602 ms 93124 KB n=200000
99 Correct 727 ms 93388 KB n=200000
100 Correct 595 ms 93128 KB n=200000
101 Correct 994 ms 106040 KB n=200000
102 Correct 349 ms 94364 KB n=200000
103 Correct 343 ms 94384 KB n=200000
104 Correct 334 ms 94544 KB n=200000
105 Correct 333 ms 94788 KB n=200000
106 Correct 325 ms 94804 KB n=200000
107 Correct 338 ms 94900 KB n=200000
108 Correct 681 ms 93448 KB n=200000
109 Correct 682 ms 93388 KB n=200000
110 Correct 698 ms 93388 KB n=200000
111 Correct 641 ms 92664 KB n=200000
112 Correct 968 ms 104688 KB n=200000
113 Correct 958 ms 98740 KB n=200000
114 Correct 606 ms 92612 KB n=200000
115 Correct 919 ms 96132 KB n=200000
116 Correct 639 ms 93356 KB n=200000
117 Correct 921 ms 105156 KB n=200000
118 Correct 941 ms 97208 KB n=200000
119 Correct 658 ms 93624 KB n=200000
120 Correct 852 ms 104844 KB n=200000
121 Correct 918 ms 105320 KB n=200000
122 Correct 914 ms 105188 KB n=200000
123 Correct 349 ms 94880 KB n=200000
124 Correct 182 ms 43128 KB n=25264