Submission #1114253

# Submission time Handle Problem Language Result Execution time Memory
1114253 2024-11-18T12:55:31 Z dead0ne Birthday gift (IZhO18_treearray) C++17
56 / 100
1041 ms 82508 KB
#include <bits/stdc++.h>
#define pb push_back
#define spc << " " <<
#define endl "\n"
#define all(x) x.begin(), x.end()
#define int long long
#define ii pair<int, int>
#define vi vector<int>
#define vii vector<ii>
#define st first
#define nd second
#define mid (l+r)/2
#define inf 1e15
#define MOD 998244353
#define MX 200005
using namespace std;

vi edges[MX];
int par[19][MX], dep[MX];
void dfs(int node, int pare){
    par[0][node]=pare;
    for(auto i:edges[node]){
        if(i!=pare){
            dep[i]=dep[node]+1;
            dfs(i, node);
        }
    }
}
int lca(int v, int u){
    if(dep[u]>dep[v]) swap(v,u);
    for(int i=dep[v]-dep[u]; i>0; i-=i&-i) v=par[__lg(i&-i)][v];
    if(v==u) return v;
    for(int i=18; i>=0; i--){
        if(par[i][v]!=par[i][u]){
            v=par[i][v];
            u=par[i][u];
        }
    }
    return par[0][v];
}


void solve(){
    int n,m,q; cin >> n >> m >> q;
    for(int i=1; i<n; i++){
        int a,b; cin >> a >> b;
        edges[a].pb(b);
        edges[b].pb(a);
    }
    par[0][1]=1;
    dep[1]=0;
    dfs(1, 0);
    for(int i=1; i<=18; i++){
        for(int j=1; j<=n; j++){
            par[i][j] = par[i-1][par[i-1][j]];
        }
    }
    int arr[m+1];
    set<ii> ans[n+1];
    for(int i=1; i<=m; i++){
        cin >> arr[i];
        ans[arr[i]].insert({i,i});
        if(i>1){
            ans[lca(arr[i], arr[i-1])].insert({i-1, i});
        }
    }
    for(int i=1; i<=q; i++){
        int ty; cin >> ty;
        if(ty==1){
            int pos,v; cin >> pos >> v;
            ans[arr[pos]].erase({pos,pos});
            if(pos>1) ans[lca(arr[pos], arr[pos-1])].erase({pos-1,pos});
            if(pos<n) ans[lca(arr[pos], arr[pos+1])].erase({pos,pos+1});
            arr[pos]=v;
            ans[arr[pos]].insert({pos,pos});
            if(pos>1) ans[lca(arr[pos], arr[pos-1])].insert({pos-1,pos});
            if(pos<n) ans[lca(arr[pos], arr[pos+1])].insert({pos,pos+1});
        }
        else{
            int l,r,v; cin >> l >> r >> v;
            auto it=(ans[v].lower_bound({l,l}));
            if(it==ans[v].end() || (*it).nd>r) cout << "-1 -1\n";
            else{
                assert((*it).st>=l && (*it).nd<=r);
                cout << (*it).st spc (*it).nd << endl;
            }
        }
    }
}


signed main(){
    ios_base::sync_with_stdio(false);cin.tie(0);
    #ifdef Local
    freopen("in","r",stdin);
    freopen("out","w",stdout);
    /*#else
    freopen("248.in","r",stdin);
    freopen("248.out","w",stdout);*/
    #endif


    int t=1;
    //cin >> t;
    while(t--) solve();
}
# Verdict Execution time Memory Grader output
1 Correct 4 ms 21840 KB n=5
2 Correct 4 ms 19792 KB n=100
3 Correct 4 ms 19792 KB n=100
4 Correct 4 ms 21840 KB n=100
5 Correct 5 ms 32080 KB n=100
6 Correct 4 ms 19792 KB n=100
7 Correct 4 ms 19792 KB n=100
8 Correct 4 ms 19792 KB n=100
9 Correct 4 ms 19792 KB n=100
10 Correct 4 ms 30032 KB n=100
11 Correct 4 ms 21840 KB n=100
12 Correct 3 ms 13816 KB n=100
13 Correct 4 ms 23888 KB n=100
14 Correct 4 ms 13648 KB n=100
15 Correct 3 ms 11600 KB n=100
16 Correct 4 ms 11600 KB n=100
17 Correct 4 ms 19792 KB n=100
18 Correct 4 ms 19792 KB n=100
19 Correct 3 ms 15868 KB n=100
20 Correct 3 ms 17744 KB n=100
21 Correct 3 ms 15696 KB n=100
22 Correct 3 ms 17744 KB n=100
23 Correct 4 ms 17744 KB n=100
24 Correct 3 ms 13648 KB n=100
25 Correct 3 ms 15696 KB n=100
26 Correct 3 ms 17744 KB n=12
27 Correct 3 ms 17744 KB n=100
# Verdict Execution time Memory Grader output
1 Correct 4 ms 21840 KB n=5
2 Correct 4 ms 19792 KB n=100
3 Correct 4 ms 19792 KB n=100
4 Correct 4 ms 21840 KB n=100
5 Correct 5 ms 32080 KB n=100
6 Correct 4 ms 19792 KB n=100
7 Correct 4 ms 19792 KB n=100
8 Correct 4 ms 19792 KB n=100
9 Correct 4 ms 19792 KB n=100
10 Correct 4 ms 30032 KB n=100
11 Correct 4 ms 21840 KB n=100
12 Correct 3 ms 13816 KB n=100
13 Correct 4 ms 23888 KB n=100
14 Correct 4 ms 13648 KB n=100
15 Correct 3 ms 11600 KB n=100
16 Correct 4 ms 11600 KB n=100
17 Correct 4 ms 19792 KB n=100
18 Correct 4 ms 19792 KB n=100
19 Correct 3 ms 15868 KB n=100
20 Correct 3 ms 17744 KB n=100
21 Correct 3 ms 15696 KB n=100
22 Correct 3 ms 17744 KB n=100
23 Correct 4 ms 17744 KB n=100
24 Correct 3 ms 13648 KB n=100
25 Correct 3 ms 15696 KB n=100
26 Correct 3 ms 17744 KB n=12
27 Correct 3 ms 17744 KB n=100
28 Correct 4 ms 15964 KB n=500
29 Correct 3 ms 18000 KB n=500
30 Correct 4 ms 20048 KB n=500
31 Correct 4 ms 20048 KB n=500
32 Correct 4 ms 15952 KB n=500
33 Correct 4 ms 15952 KB n=500
34 Correct 4 ms 15952 KB n=500
35 Correct 4 ms 22264 KB n=500
36 Correct 4 ms 15952 KB n=500
37 Correct 4 ms 20048 KB n=500
38 Correct 4 ms 15952 KB n=500
39 Correct 4 ms 18176 KB n=500
40 Correct 4 ms 15952 KB n=500
41 Correct 4 ms 11856 KB n=500
42 Correct 4 ms 13916 KB n=500
43 Correct 4 ms 20048 KB n=500
44 Correct 4 ms 11856 KB n=500
45 Correct 3 ms 11856 KB n=500
46 Correct 4 ms 13904 KB n=500
47 Correct 5 ms 18000 KB n=500
48 Correct 4 ms 18000 KB n=500
49 Correct 4 ms 15952 KB n=500
50 Correct 4 ms 15952 KB n=500
51 Correct 5 ms 15952 KB n=500
52 Correct 4 ms 18000 KB n=500
53 Correct 4 ms 18000 KB n=500
54 Correct 4 ms 18000 KB n=500
55 Correct 3 ms 15952 KB n=278
56 Correct 4 ms 18000 KB n=500
57 Correct 4 ms 15952 KB n=500
58 Correct 4 ms 18000 KB n=500
# Verdict Execution time Memory Grader output
1 Correct 4 ms 21840 KB n=5
2 Correct 4 ms 19792 KB n=100
3 Correct 4 ms 19792 KB n=100
4 Correct 4 ms 21840 KB n=100
5 Correct 5 ms 32080 KB n=100
6 Correct 4 ms 19792 KB n=100
7 Correct 4 ms 19792 KB n=100
8 Correct 4 ms 19792 KB n=100
9 Correct 4 ms 19792 KB n=100
10 Correct 4 ms 30032 KB n=100
11 Correct 4 ms 21840 KB n=100
12 Correct 3 ms 13816 KB n=100
13 Correct 4 ms 23888 KB n=100
14 Correct 4 ms 13648 KB n=100
15 Correct 3 ms 11600 KB n=100
16 Correct 4 ms 11600 KB n=100
17 Correct 4 ms 19792 KB n=100
18 Correct 4 ms 19792 KB n=100
19 Correct 3 ms 15868 KB n=100
20 Correct 3 ms 17744 KB n=100
21 Correct 3 ms 15696 KB n=100
22 Correct 3 ms 17744 KB n=100
23 Correct 4 ms 17744 KB n=100
24 Correct 3 ms 13648 KB n=100
25 Correct 3 ms 15696 KB n=100
26 Correct 3 ms 17744 KB n=12
27 Correct 3 ms 17744 KB n=100
28 Correct 4 ms 15964 KB n=500
29 Correct 3 ms 18000 KB n=500
30 Correct 4 ms 20048 KB n=500
31 Correct 4 ms 20048 KB n=500
32 Correct 4 ms 15952 KB n=500
33 Correct 4 ms 15952 KB n=500
34 Correct 4 ms 15952 KB n=500
35 Correct 4 ms 22264 KB n=500
36 Correct 4 ms 15952 KB n=500
37 Correct 4 ms 20048 KB n=500
38 Correct 4 ms 15952 KB n=500
39 Correct 4 ms 18176 KB n=500
40 Correct 4 ms 15952 KB n=500
41 Correct 4 ms 11856 KB n=500
42 Correct 4 ms 13916 KB n=500
43 Correct 4 ms 20048 KB n=500
44 Correct 4 ms 11856 KB n=500
45 Correct 3 ms 11856 KB n=500
46 Correct 4 ms 13904 KB n=500
47 Correct 5 ms 18000 KB n=500
48 Correct 4 ms 18000 KB n=500
49 Correct 4 ms 15952 KB n=500
50 Correct 4 ms 15952 KB n=500
51 Correct 5 ms 15952 KB n=500
52 Correct 4 ms 18000 KB n=500
53 Correct 4 ms 18000 KB n=500
54 Correct 4 ms 18000 KB n=500
55 Correct 3 ms 15952 KB n=278
56 Correct 4 ms 18000 KB n=500
57 Correct 4 ms 15952 KB n=500
58 Correct 4 ms 18000 KB n=500
59 Correct 6 ms 16464 KB n=2000
60 Correct 6 ms 20560 KB n=2000
61 Correct 5 ms 14416 KB n=2000
62 Correct 6 ms 18512 KB n=2000
63 Correct 6 ms 22608 KB n=2000
64 Correct 8 ms 18512 KB n=2000
65 Correct 6 ms 16464 KB n=2000
66 Correct 5 ms 16464 KB n=2000
67 Correct 6 ms 16464 KB n=2000
68 Correct 6 ms 16464 KB n=2000
69 Correct 6 ms 16464 KB n=2000
70 Correct 5 ms 18512 KB n=2000
71 Correct 6 ms 22608 KB n=2000
72 Correct 5 ms 16464 KB n=2000
73 Correct 5 ms 16464 KB n=2000
74 Correct 5 ms 12368 KB n=1844
75 Correct 6 ms 16464 KB n=2000
76 Correct 7 ms 20560 KB n=2000
77 Correct 6 ms 16464 KB n=2000
78 Correct 6 ms 16464 KB n=2000
79 Correct 6 ms 14416 KB n=2000
80 Correct 6 ms 16464 KB n=2000
81 Correct 6 ms 14592 KB n=2000
82 Correct 6 ms 16464 KB n=2000
83 Correct 6 ms 20728 KB n=2000
84 Correct 6 ms 16632 KB n=2000
85 Correct 6 ms 12368 KB n=2000
86 Correct 6 ms 16464 KB n=2000
87 Correct 7 ms 20560 KB n=2000
88 Correct 6 ms 16632 KB n=2000
89 Correct 6 ms 22368 KB n=2000
90 Correct 6 ms 20560 KB n=2000
91 Correct 6 ms 16464 KB n=2000
# Verdict Execution time Memory Grader output
1 Correct 4 ms 21840 KB n=5
2 Correct 4 ms 19792 KB n=100
3 Correct 4 ms 19792 KB n=100
4 Correct 4 ms 21840 KB n=100
5 Correct 5 ms 32080 KB n=100
6 Correct 4 ms 19792 KB n=100
7 Correct 4 ms 19792 KB n=100
8 Correct 4 ms 19792 KB n=100
9 Correct 4 ms 19792 KB n=100
10 Correct 4 ms 30032 KB n=100
11 Correct 4 ms 21840 KB n=100
12 Correct 3 ms 13816 KB n=100
13 Correct 4 ms 23888 KB n=100
14 Correct 4 ms 13648 KB n=100
15 Correct 3 ms 11600 KB n=100
16 Correct 4 ms 11600 KB n=100
17 Correct 4 ms 19792 KB n=100
18 Correct 4 ms 19792 KB n=100
19 Correct 3 ms 15868 KB n=100
20 Correct 3 ms 17744 KB n=100
21 Correct 3 ms 15696 KB n=100
22 Correct 3 ms 17744 KB n=100
23 Correct 4 ms 17744 KB n=100
24 Correct 3 ms 13648 KB n=100
25 Correct 3 ms 15696 KB n=100
26 Correct 3 ms 17744 KB n=12
27 Correct 3 ms 17744 KB n=100
28 Correct 4 ms 15964 KB n=500
29 Correct 3 ms 18000 KB n=500
30 Correct 4 ms 20048 KB n=500
31 Correct 4 ms 20048 KB n=500
32 Correct 4 ms 15952 KB n=500
33 Correct 4 ms 15952 KB n=500
34 Correct 4 ms 15952 KB n=500
35 Correct 4 ms 22264 KB n=500
36 Correct 4 ms 15952 KB n=500
37 Correct 4 ms 20048 KB n=500
38 Correct 4 ms 15952 KB n=500
39 Correct 4 ms 18176 KB n=500
40 Correct 4 ms 15952 KB n=500
41 Correct 4 ms 11856 KB n=500
42 Correct 4 ms 13916 KB n=500
43 Correct 4 ms 20048 KB n=500
44 Correct 4 ms 11856 KB n=500
45 Correct 3 ms 11856 KB n=500
46 Correct 4 ms 13904 KB n=500
47 Correct 5 ms 18000 KB n=500
48 Correct 4 ms 18000 KB n=500
49 Correct 4 ms 15952 KB n=500
50 Correct 4 ms 15952 KB n=500
51 Correct 5 ms 15952 KB n=500
52 Correct 4 ms 18000 KB n=500
53 Correct 4 ms 18000 KB n=500
54 Correct 4 ms 18000 KB n=500
55 Correct 3 ms 15952 KB n=278
56 Correct 4 ms 18000 KB n=500
57 Correct 4 ms 15952 KB n=500
58 Correct 4 ms 18000 KB n=500
59 Correct 6 ms 16464 KB n=2000
60 Correct 6 ms 20560 KB n=2000
61 Correct 5 ms 14416 KB n=2000
62 Correct 6 ms 18512 KB n=2000
63 Correct 6 ms 22608 KB n=2000
64 Correct 8 ms 18512 KB n=2000
65 Correct 6 ms 16464 KB n=2000
66 Correct 5 ms 16464 KB n=2000
67 Correct 6 ms 16464 KB n=2000
68 Correct 6 ms 16464 KB n=2000
69 Correct 6 ms 16464 KB n=2000
70 Correct 5 ms 18512 KB n=2000
71 Correct 6 ms 22608 KB n=2000
72 Correct 5 ms 16464 KB n=2000
73 Correct 5 ms 16464 KB n=2000
74 Correct 5 ms 12368 KB n=1844
75 Correct 6 ms 16464 KB n=2000
76 Correct 7 ms 20560 KB n=2000
77 Correct 6 ms 16464 KB n=2000
78 Correct 6 ms 16464 KB n=2000
79 Correct 6 ms 14416 KB n=2000
80 Correct 6 ms 16464 KB n=2000
81 Correct 6 ms 14592 KB n=2000
82 Correct 6 ms 16464 KB n=2000
83 Correct 6 ms 20728 KB n=2000
84 Correct 6 ms 16632 KB n=2000
85 Correct 6 ms 12368 KB n=2000
86 Correct 6 ms 16464 KB n=2000
87 Correct 7 ms 20560 KB n=2000
88 Correct 6 ms 16632 KB n=2000
89 Correct 6 ms 22368 KB n=2000
90 Correct 6 ms 20560 KB n=2000
91 Correct 6 ms 16464 KB n=2000
92 Correct 707 ms 81604 KB n=200000
93 Correct 865 ms 80396 KB n=200000
94 Correct 779 ms 80160 KB n=200000
95 Correct 727 ms 81976 KB n=200000
96 Correct 724 ms 82024 KB n=200000
97 Correct 884 ms 80456 KB n=200000
98 Correct 682 ms 82104 KB n=200000
99 Correct 883 ms 80968 KB n=200000
100 Correct 769 ms 81324 KB n=200000
101 Correct 800 ms 79688 KB n=200000
102 Correct 364 ms 82508 KB n=200000
103 Correct 365 ms 82324 KB n=200000
104 Correct 342 ms 82432 KB n=200000
105 Correct 325 ms 82248 KB n=200000
106 Correct 371 ms 82056 KB n=200000
107 Correct 371 ms 82124 KB n=200000
108 Correct 832 ms 81072 KB n=200000
109 Correct 845 ms 81224 KB n=200000
110 Correct 889 ms 81224 KB n=200000
111 Correct 752 ms 81896 KB n=200000
112 Correct 787 ms 79944 KB n=200000
113 Correct 918 ms 80476 KB n=200000
114 Correct 695 ms 82104 KB n=200000
115 Correct 1041 ms 80848 KB n=200000
116 Correct 684 ms 81884 KB n=200000
117 Correct 630 ms 79464 KB n=200000
118 Correct 804 ms 80528 KB n=200000
119 Correct 731 ms 81672 KB n=200000
120 Correct 879 ms 79176 KB n=200000
121 Correct 860 ms 79092 KB n=200000
122 Correct 836 ms 79764 KB n=200000
123 Correct 401 ms 81736 KB n=200000
124 Incorrect 124 ms 36564 KB Wrong range.
125 Halted 0 ms 0 KB -