Submission #894449

# Submission time Handle Problem Language Result Execution time Memory
894449 2023-12-28T09:39:39 Z 12345678 Birthday gift (IZhO18_treearray) C++17
100 / 100
991 ms 91916 KB
#include <bits/stdc++.h>

using namespace std;

const int nx=2e5+5, kx=18;
int n, m, q, u, v, lvl[nx], pa[nx][kx], t, l, r, vl, x, a[nx];
vector<int> d[nx];
set<int> s[nx], o[nx];

void dfs(int u, int p)
{
    lvl[u]=lvl[p]+1;
    pa[u][0]=p;
    for (int i=1; i<kx; i++) pa[u][i]=pa[pa[u][i-1]][i-1];
    for (auto v:d[u]) if (v!=p) dfs(v, u);
}

int lca(int u, int v)
{
    if (lvl[u]>lvl[v]) swap(u, v);
    for (int i=kx-1; i>=0; i--) if (lvl[pa[v][i]]>=lvl[u]) v=pa[v][i];
    if (u==v) return u;
    for (int i=kx-1; i>=0; i--) if (pa[u][i]!=pa[v][i]) u=pa[u][i], v=pa[v][i];
    return pa[u][0];
}

void update(int idx)
{
    if (idx>1) s[lca(a[idx], a[idx-1])].insert(idx-1);
    if (idx<m) s[lca(a[idx], a[idx+1])].insert(idx);
    o[a[idx]].insert(idx);
}

void remove(int idx)
{
    if (idx>1) s[lca(a[idx], a[idx-1])].erase(idx-1);
    if (idx<m) s[lca(a[idx], a[idx+1])].erase(idx);
    o[a[idx]].erase(idx);
}

int main()
{
    cin.tie(NULL)->sync_with_stdio(false);
    cin>>n>>m>>q;
    for (int i=0; i<n-1; i++) cin>>u>>v, d[u].push_back(v), d[v].push_back(u);
    dfs(1, 1);
    for (int i=1; i<=m; i++) cin>>a[i], update(i);
    while (q--)
    {
        cin>>t;
        if (t==1) 
        {
            cin>>x>>vl;
            remove(x);
            a[x]=vl;
            update(x);
        }
        else
        {
            cin>>l>>r>>vl;
            auto itr=o[vl].lower_bound(l), itr2=s[vl].lower_bound(l);
            if (itr!=o[vl].end()&&(*itr)<=r) cout<<*itr<<' '<<*itr<<'\n';
            else if (itr2!=s[vl].end()&&(*itr2)<r) cout<<*itr2<<' '<<*itr2+1<<'\n';
            else cout<<-1<<' '<<-1<<'\n';
        }
    }
}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 25176 KB n=5
2 Correct 5 ms 25252 KB n=100
3 Correct 5 ms 25180 KB n=100
4 Correct 5 ms 25180 KB n=100
5 Correct 5 ms 25180 KB n=100
6 Correct 5 ms 25176 KB n=100
7 Correct 5 ms 25176 KB n=100
8 Correct 5 ms 25176 KB n=100
9 Correct 5 ms 25180 KB n=100
10 Correct 6 ms 25180 KB n=100
11 Correct 5 ms 25180 KB n=100
12 Correct 6 ms 25180 KB n=100
13 Correct 5 ms 25176 KB n=100
14 Correct 5 ms 25180 KB n=100
15 Correct 5 ms 25180 KB n=100
16 Correct 7 ms 25432 KB n=100
17 Correct 5 ms 25180 KB n=100
18 Correct 5 ms 25180 KB n=100
19 Correct 5 ms 25180 KB n=100
20 Correct 5 ms 25180 KB n=100
21 Correct 5 ms 25176 KB n=100
22 Correct 5 ms 25180 KB n=100
23 Correct 5 ms 25176 KB n=100
24 Correct 5 ms 25180 KB n=100
25 Correct 5 ms 25180 KB n=100
26 Correct 5 ms 25180 KB n=12
27 Correct 5 ms 25176 KB n=100
# Verdict Execution time Memory Grader output
1 Correct 5 ms 25176 KB n=5
2 Correct 5 ms 25252 KB n=100
3 Correct 5 ms 25180 KB n=100
4 Correct 5 ms 25180 KB n=100
5 Correct 5 ms 25180 KB n=100
6 Correct 5 ms 25176 KB n=100
7 Correct 5 ms 25176 KB n=100
8 Correct 5 ms 25176 KB n=100
9 Correct 5 ms 25180 KB n=100
10 Correct 6 ms 25180 KB n=100
11 Correct 5 ms 25180 KB n=100
12 Correct 6 ms 25180 KB n=100
13 Correct 5 ms 25176 KB n=100
14 Correct 5 ms 25180 KB n=100
15 Correct 5 ms 25180 KB n=100
16 Correct 7 ms 25432 KB n=100
17 Correct 5 ms 25180 KB n=100
18 Correct 5 ms 25180 KB n=100
19 Correct 5 ms 25180 KB n=100
20 Correct 5 ms 25180 KB n=100
21 Correct 5 ms 25176 KB n=100
22 Correct 5 ms 25180 KB n=100
23 Correct 5 ms 25176 KB n=100
24 Correct 5 ms 25180 KB n=100
25 Correct 5 ms 25180 KB n=100
26 Correct 5 ms 25180 KB n=12
27 Correct 5 ms 25176 KB n=100
28 Correct 6 ms 25176 KB n=500
29 Correct 6 ms 25180 KB n=500
30 Correct 6 ms 25276 KB n=500
31 Correct 6 ms 25176 KB n=500
32 Correct 6 ms 25180 KB n=500
33 Correct 5 ms 25180 KB n=500
34 Correct 6 ms 25176 KB n=500
35 Correct 6 ms 25176 KB n=500
36 Correct 5 ms 25180 KB n=500
37 Correct 6 ms 25180 KB n=500
38 Correct 6 ms 25188 KB n=500
39 Correct 6 ms 25180 KB n=500
40 Correct 6 ms 25180 KB n=500
41 Correct 6 ms 25180 KB n=500
42 Correct 6 ms 25180 KB n=500
43 Correct 6 ms 25228 KB n=500
44 Correct 6 ms 25180 KB n=500
45 Correct 6 ms 25216 KB n=500
46 Correct 6 ms 25180 KB n=500
47 Correct 5 ms 25180 KB n=500
48 Correct 6 ms 25180 KB n=500
49 Correct 5 ms 25180 KB n=500
50 Correct 6 ms 25176 KB n=500
51 Correct 6 ms 25376 KB n=500
52 Correct 5 ms 25176 KB n=500
53 Correct 6 ms 25176 KB n=500
54 Correct 6 ms 25264 KB n=500
55 Correct 6 ms 25180 KB n=278
56 Correct 6 ms 25212 KB n=500
57 Correct 7 ms 25176 KB n=500
58 Correct 6 ms 25180 KB n=500
# Verdict Execution time Memory Grader output
1 Correct 5 ms 25176 KB n=5
2 Correct 5 ms 25252 KB n=100
3 Correct 5 ms 25180 KB n=100
4 Correct 5 ms 25180 KB n=100
5 Correct 5 ms 25180 KB n=100
6 Correct 5 ms 25176 KB n=100
7 Correct 5 ms 25176 KB n=100
8 Correct 5 ms 25176 KB n=100
9 Correct 5 ms 25180 KB n=100
10 Correct 6 ms 25180 KB n=100
11 Correct 5 ms 25180 KB n=100
12 Correct 6 ms 25180 KB n=100
13 Correct 5 ms 25176 KB n=100
14 Correct 5 ms 25180 KB n=100
15 Correct 5 ms 25180 KB n=100
16 Correct 7 ms 25432 KB n=100
17 Correct 5 ms 25180 KB n=100
18 Correct 5 ms 25180 KB n=100
19 Correct 5 ms 25180 KB n=100
20 Correct 5 ms 25180 KB n=100
21 Correct 5 ms 25176 KB n=100
22 Correct 5 ms 25180 KB n=100
23 Correct 5 ms 25176 KB n=100
24 Correct 5 ms 25180 KB n=100
25 Correct 5 ms 25180 KB n=100
26 Correct 5 ms 25180 KB n=12
27 Correct 5 ms 25176 KB n=100
28 Correct 6 ms 25176 KB n=500
29 Correct 6 ms 25180 KB n=500
30 Correct 6 ms 25276 KB n=500
31 Correct 6 ms 25176 KB n=500
32 Correct 6 ms 25180 KB n=500
33 Correct 5 ms 25180 KB n=500
34 Correct 6 ms 25176 KB n=500
35 Correct 6 ms 25176 KB n=500
36 Correct 5 ms 25180 KB n=500
37 Correct 6 ms 25180 KB n=500
38 Correct 6 ms 25188 KB n=500
39 Correct 6 ms 25180 KB n=500
40 Correct 6 ms 25180 KB n=500
41 Correct 6 ms 25180 KB n=500
42 Correct 6 ms 25180 KB n=500
43 Correct 6 ms 25228 KB n=500
44 Correct 6 ms 25180 KB n=500
45 Correct 6 ms 25216 KB n=500
46 Correct 6 ms 25180 KB n=500
47 Correct 5 ms 25180 KB n=500
48 Correct 6 ms 25180 KB n=500
49 Correct 5 ms 25180 KB n=500
50 Correct 6 ms 25176 KB n=500
51 Correct 6 ms 25376 KB n=500
52 Correct 5 ms 25176 KB n=500
53 Correct 6 ms 25176 KB n=500
54 Correct 6 ms 25264 KB n=500
55 Correct 6 ms 25180 KB n=278
56 Correct 6 ms 25212 KB n=500
57 Correct 7 ms 25176 KB n=500
58 Correct 6 ms 25180 KB n=500
59 Correct 9 ms 25436 KB n=2000
60 Correct 8 ms 25692 KB n=2000
61 Correct 8 ms 25688 KB n=2000
62 Correct 8 ms 25688 KB n=2000
63 Correct 8 ms 25692 KB n=2000
64 Correct 9 ms 25484 KB n=2000
65 Correct 9 ms 25436 KB n=2000
66 Correct 10 ms 25688 KB n=2000
67 Correct 10 ms 25432 KB n=2000
68 Correct 8 ms 25692 KB n=2000
69 Correct 7 ms 25528 KB n=2000
70 Correct 8 ms 25436 KB n=2000
71 Correct 8 ms 25688 KB n=2000
72 Correct 7 ms 25692 KB n=2000
73 Correct 10 ms 25436 KB n=2000
74 Correct 8 ms 25432 KB n=1844
75 Correct 8 ms 25688 KB n=2000
76 Correct 9 ms 25432 KB n=2000
77 Correct 10 ms 25432 KB n=2000
78 Correct 8 ms 25436 KB n=2000
79 Correct 9 ms 25436 KB n=2000
80 Correct 8 ms 25692 KB n=2000
81 Correct 8 ms 25944 KB n=2000
82 Correct 9 ms 25520 KB n=2000
83 Correct 8 ms 25688 KB n=2000
84 Correct 8 ms 25692 KB n=2000
85 Correct 8 ms 25692 KB n=2000
86 Correct 9 ms 25692 KB n=2000
87 Correct 8 ms 25436 KB n=2000
88 Correct 8 ms 25736 KB n=2000
89 Correct 8 ms 25516 KB n=2000
90 Correct 9 ms 25692 KB n=2000
91 Correct 9 ms 25436 KB n=2000
# Verdict Execution time Memory Grader output
1 Correct 5 ms 25176 KB n=5
2 Correct 5 ms 25252 KB n=100
3 Correct 5 ms 25180 KB n=100
4 Correct 5 ms 25180 KB n=100
5 Correct 5 ms 25180 KB n=100
6 Correct 5 ms 25176 KB n=100
7 Correct 5 ms 25176 KB n=100
8 Correct 5 ms 25176 KB n=100
9 Correct 5 ms 25180 KB n=100
10 Correct 6 ms 25180 KB n=100
11 Correct 5 ms 25180 KB n=100
12 Correct 6 ms 25180 KB n=100
13 Correct 5 ms 25176 KB n=100
14 Correct 5 ms 25180 KB n=100
15 Correct 5 ms 25180 KB n=100
16 Correct 7 ms 25432 KB n=100
17 Correct 5 ms 25180 KB n=100
18 Correct 5 ms 25180 KB n=100
19 Correct 5 ms 25180 KB n=100
20 Correct 5 ms 25180 KB n=100
21 Correct 5 ms 25176 KB n=100
22 Correct 5 ms 25180 KB n=100
23 Correct 5 ms 25176 KB n=100
24 Correct 5 ms 25180 KB n=100
25 Correct 5 ms 25180 KB n=100
26 Correct 5 ms 25180 KB n=12
27 Correct 5 ms 25176 KB n=100
28 Correct 6 ms 25176 KB n=500
29 Correct 6 ms 25180 KB n=500
30 Correct 6 ms 25276 KB n=500
31 Correct 6 ms 25176 KB n=500
32 Correct 6 ms 25180 KB n=500
33 Correct 5 ms 25180 KB n=500
34 Correct 6 ms 25176 KB n=500
35 Correct 6 ms 25176 KB n=500
36 Correct 5 ms 25180 KB n=500
37 Correct 6 ms 25180 KB n=500
38 Correct 6 ms 25188 KB n=500
39 Correct 6 ms 25180 KB n=500
40 Correct 6 ms 25180 KB n=500
41 Correct 6 ms 25180 KB n=500
42 Correct 6 ms 25180 KB n=500
43 Correct 6 ms 25228 KB n=500
44 Correct 6 ms 25180 KB n=500
45 Correct 6 ms 25216 KB n=500
46 Correct 6 ms 25180 KB n=500
47 Correct 5 ms 25180 KB n=500
48 Correct 6 ms 25180 KB n=500
49 Correct 5 ms 25180 KB n=500
50 Correct 6 ms 25176 KB n=500
51 Correct 6 ms 25376 KB n=500
52 Correct 5 ms 25176 KB n=500
53 Correct 6 ms 25176 KB n=500
54 Correct 6 ms 25264 KB n=500
55 Correct 6 ms 25180 KB n=278
56 Correct 6 ms 25212 KB n=500
57 Correct 7 ms 25176 KB n=500
58 Correct 6 ms 25180 KB n=500
59 Correct 9 ms 25436 KB n=2000
60 Correct 8 ms 25692 KB n=2000
61 Correct 8 ms 25688 KB n=2000
62 Correct 8 ms 25688 KB n=2000
63 Correct 8 ms 25692 KB n=2000
64 Correct 9 ms 25484 KB n=2000
65 Correct 9 ms 25436 KB n=2000
66 Correct 10 ms 25688 KB n=2000
67 Correct 10 ms 25432 KB n=2000
68 Correct 8 ms 25692 KB n=2000
69 Correct 7 ms 25528 KB n=2000
70 Correct 8 ms 25436 KB n=2000
71 Correct 8 ms 25688 KB n=2000
72 Correct 7 ms 25692 KB n=2000
73 Correct 10 ms 25436 KB n=2000
74 Correct 8 ms 25432 KB n=1844
75 Correct 8 ms 25688 KB n=2000
76 Correct 9 ms 25432 KB n=2000
77 Correct 10 ms 25432 KB n=2000
78 Correct 8 ms 25436 KB n=2000
79 Correct 9 ms 25436 KB n=2000
80 Correct 8 ms 25692 KB n=2000
81 Correct 8 ms 25944 KB n=2000
82 Correct 9 ms 25520 KB n=2000
83 Correct 8 ms 25688 KB n=2000
84 Correct 8 ms 25692 KB n=2000
85 Correct 8 ms 25692 KB n=2000
86 Correct 9 ms 25692 KB n=2000
87 Correct 8 ms 25436 KB n=2000
88 Correct 8 ms 25736 KB n=2000
89 Correct 8 ms 25516 KB n=2000
90 Correct 9 ms 25692 KB n=2000
91 Correct 9 ms 25436 KB n=2000
92 Correct 755 ms 79548 KB n=200000
93 Correct 934 ms 85588 KB n=200000
94 Correct 870 ms 90736 KB n=200000
95 Correct 693 ms 82288 KB n=200000
96 Correct 730 ms 82240 KB n=200000
97 Correct 974 ms 86268 KB n=200000
98 Correct 738 ms 82128 KB n=200000
99 Correct 841 ms 82364 KB n=200000
100 Correct 737 ms 82408 KB n=200000
101 Correct 847 ms 91916 KB n=200000
102 Correct 411 ms 83552 KB n=200000
103 Correct 409 ms 83536 KB n=200000
104 Correct 443 ms 83456 KB n=200000
105 Correct 458 ms 84052 KB n=200000
106 Correct 436 ms 83940 KB n=200000
107 Correct 414 ms 83796 KB n=200000
108 Correct 801 ms 82740 KB n=200000
109 Correct 737 ms 82400 KB n=200000
110 Correct 726 ms 82324 KB n=200000
111 Correct 701 ms 81736 KB n=200000
112 Correct 861 ms 91152 KB n=200000
113 Correct 894 ms 86396 KB n=200000
114 Correct 767 ms 81692 KB n=200000
115 Correct 991 ms 84268 KB n=200000
116 Correct 697 ms 82496 KB n=200000
117 Correct 851 ms 91272 KB n=200000
118 Correct 972 ms 85548 KB n=200000
119 Correct 670 ms 82504 KB n=200000
120 Correct 788 ms 91044 KB n=200000
121 Correct 723 ms 90960 KB n=200000
122 Correct 753 ms 91212 KB n=200000
123 Correct 488 ms 84104 KB n=200000
124 Correct 164 ms 43860 KB n=25264