Submission #379179

# Submission time Handle Problem Language Result Execution time Memory
379179 2021-03-17T12:50:56 Z YJU Birthday gift (IZhO18_treearray) C++14
100 / 100
1460 ms 103020 KB
#include<bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector,Ofast")
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
const ll N=2e5+5;
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define lwb lower_bound

ll depth[N],anc[N][20];

ll lca(ll nda,ll ndb){
    if(depth[nda]<depth[ndb])swap(nda,ndb);
    for(int i=19;i>=0;i--){
		if(depth[anc[nda][i]]>=depth[ndb]){
			nda=anc[nda][i];
		}
    }
    if(nda==ndb)return nda;
    for(int i=19;i>=0;i--){
		if(anc[nda][i]!=anc[ndb][i]){
			nda=anc[nda][i];
			ndb=anc[ndb][i];
		}
    }
    return anc[nda][0];
}

ll n,m,x,y,q,u[N],as[N];
vector<ll> v[N];

set<ll> loc[N],is[N];

void build_LCA(ll nd,ll pa){
	depth[nd]=depth[pa]+1;
	anc[nd][0]=pa;
	REP1(i,19)anc[nd][i]=anc[anc[nd][i-1]][i-1];
	for(ll i:v[nd]){
		if(i==pa)continue;
		build_LCA(i,nd);
	}
}

int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);
    cin>>n>>m>>q;
    REP(i,n-1){
		cin>>x>>y;
		v[x].pb(y);v[y].pb(x);
    }
    build_LCA(1,0);
    REP1(i,m)cin>>u[i],is[u[i]].insert(i);
    REP1(i,m-1)as[i]=lca(u[i],u[i+1]),loc[as[i]].insert(i);

    while(q--){
		ll ty,now;
        cin>>ty;
        if(ty==1){
			cin>>x>>y;
			if(x>1)loc[as[x-1]].erase(x-1);
			if(x<m)loc[as[x]].erase(x);
			is[u[x]].erase(x);
			u[x]=y;
			is[u[x]].insert(x);
			if(x>1)as[x-1]=lca(u[x-1],u[x]),loc[as[x-1]].insert(x-1);
			if(x<m)as[x]=lca(u[x],u[x+1]),loc[as[x]].insert(x);
        }else{
			cin>>x>>y>>now;
			auto it=loc[now].lwb(x),where=is[now].lwb(x);
			if((it==loc[now].end()||(*it)>=y)&&(where==is[now].end()||*where>y)){
				cout<<"-1 -1\n";
			}else{
				if(where!=is[now].end()&&*where<=y){
					cout<<*where<<" "<<*where<<"\n";
				}else{
					cout<<*it<<" "<<*it+1<<"\n";
				}
			}
		}
	}
	return 0;
}
/*
5 4 4
1 2
3 1
3 4
5 3
4 5 2 3
2 1 3 1
1 3 5
2 3 4 5
2 1 3 1


*/
# Verdict Execution time Memory Grader output
1 Correct 17 ms 23788 KB n=5
2 Correct 16 ms 23916 KB n=100
3 Correct 17 ms 23936 KB n=100
4 Correct 17 ms 23916 KB n=100
5 Correct 16 ms 23916 KB n=100
6 Correct 17 ms 23916 KB n=100
7 Correct 16 ms 23916 KB n=100
8 Correct 17 ms 23916 KB n=100
9 Correct 16 ms 23916 KB n=100
10 Correct 17 ms 24064 KB n=100
11 Correct 17 ms 23916 KB n=100
12 Correct 16 ms 23916 KB n=100
13 Correct 16 ms 23916 KB n=100
14 Correct 17 ms 23916 KB n=100
15 Correct 17 ms 23916 KB n=100
16 Correct 18 ms 23916 KB n=100
17 Correct 16 ms 23916 KB n=100
18 Correct 18 ms 23916 KB n=100
19 Correct 16 ms 23916 KB n=100
20 Correct 17 ms 23916 KB n=100
21 Correct 16 ms 23916 KB n=100
22 Correct 16 ms 23916 KB n=100
23 Correct 18 ms 23916 KB n=100
24 Correct 17 ms 23916 KB n=100
25 Correct 17 ms 23916 KB n=100
26 Correct 18 ms 23788 KB n=12
27 Correct 17 ms 23916 KB n=100
# Verdict Execution time Memory Grader output
1 Correct 17 ms 23788 KB n=5
2 Correct 16 ms 23916 KB n=100
3 Correct 17 ms 23936 KB n=100
4 Correct 17 ms 23916 KB n=100
5 Correct 16 ms 23916 KB n=100
6 Correct 17 ms 23916 KB n=100
7 Correct 16 ms 23916 KB n=100
8 Correct 17 ms 23916 KB n=100
9 Correct 16 ms 23916 KB n=100
10 Correct 17 ms 24064 KB n=100
11 Correct 17 ms 23916 KB n=100
12 Correct 16 ms 23916 KB n=100
13 Correct 16 ms 23916 KB n=100
14 Correct 17 ms 23916 KB n=100
15 Correct 17 ms 23916 KB n=100
16 Correct 18 ms 23916 KB n=100
17 Correct 16 ms 23916 KB n=100
18 Correct 18 ms 23916 KB n=100
19 Correct 16 ms 23916 KB n=100
20 Correct 17 ms 23916 KB n=100
21 Correct 16 ms 23916 KB n=100
22 Correct 16 ms 23916 KB n=100
23 Correct 18 ms 23916 KB n=100
24 Correct 17 ms 23916 KB n=100
25 Correct 17 ms 23916 KB n=100
26 Correct 18 ms 23788 KB n=12
27 Correct 17 ms 23916 KB n=100
28 Correct 18 ms 24056 KB n=500
29 Correct 18 ms 24044 KB n=500
30 Correct 17 ms 24044 KB n=500
31 Correct 18 ms 24172 KB n=500
32 Correct 17 ms 24044 KB n=500
33 Correct 17 ms 24044 KB n=500
34 Correct 17 ms 24044 KB n=500
35 Correct 17 ms 24044 KB n=500
36 Correct 17 ms 24044 KB n=500
37 Correct 17 ms 24044 KB n=500
38 Correct 17 ms 24044 KB n=500
39 Correct 19 ms 24044 KB n=500
40 Correct 18 ms 24044 KB n=500
41 Correct 18 ms 24044 KB n=500
42 Correct 17 ms 24044 KB n=500
43 Correct 17 ms 24044 KB n=500
44 Correct 17 ms 24044 KB n=500
45 Correct 17 ms 24044 KB n=500
46 Correct 17 ms 24044 KB n=500
47 Correct 18 ms 24044 KB n=500
48 Correct 18 ms 24044 KB n=500
49 Correct 18 ms 24044 KB n=500
50 Correct 17 ms 24072 KB n=500
51 Correct 17 ms 24044 KB n=500
52 Correct 18 ms 24044 KB n=500
53 Correct 17 ms 24044 KB n=500
54 Correct 17 ms 24044 KB n=500
55 Correct 19 ms 23916 KB n=278
56 Correct 17 ms 24044 KB n=500
57 Correct 17 ms 24044 KB n=500
58 Correct 17 ms 24044 KB n=500
# Verdict Execution time Memory Grader output
1 Correct 17 ms 23788 KB n=5
2 Correct 16 ms 23916 KB n=100
3 Correct 17 ms 23936 KB n=100
4 Correct 17 ms 23916 KB n=100
5 Correct 16 ms 23916 KB n=100
6 Correct 17 ms 23916 KB n=100
7 Correct 16 ms 23916 KB n=100
8 Correct 17 ms 23916 KB n=100
9 Correct 16 ms 23916 KB n=100
10 Correct 17 ms 24064 KB n=100
11 Correct 17 ms 23916 KB n=100
12 Correct 16 ms 23916 KB n=100
13 Correct 16 ms 23916 KB n=100
14 Correct 17 ms 23916 KB n=100
15 Correct 17 ms 23916 KB n=100
16 Correct 18 ms 23916 KB n=100
17 Correct 16 ms 23916 KB n=100
18 Correct 18 ms 23916 KB n=100
19 Correct 16 ms 23916 KB n=100
20 Correct 17 ms 23916 KB n=100
21 Correct 16 ms 23916 KB n=100
22 Correct 16 ms 23916 KB n=100
23 Correct 18 ms 23916 KB n=100
24 Correct 17 ms 23916 KB n=100
25 Correct 17 ms 23916 KB n=100
26 Correct 18 ms 23788 KB n=12
27 Correct 17 ms 23916 KB n=100
28 Correct 18 ms 24056 KB n=500
29 Correct 18 ms 24044 KB n=500
30 Correct 17 ms 24044 KB n=500
31 Correct 18 ms 24172 KB n=500
32 Correct 17 ms 24044 KB n=500
33 Correct 17 ms 24044 KB n=500
34 Correct 17 ms 24044 KB n=500
35 Correct 17 ms 24044 KB n=500
36 Correct 17 ms 24044 KB n=500
37 Correct 17 ms 24044 KB n=500
38 Correct 17 ms 24044 KB n=500
39 Correct 19 ms 24044 KB n=500
40 Correct 18 ms 24044 KB n=500
41 Correct 18 ms 24044 KB n=500
42 Correct 17 ms 24044 KB n=500
43 Correct 17 ms 24044 KB n=500
44 Correct 17 ms 24044 KB n=500
45 Correct 17 ms 24044 KB n=500
46 Correct 17 ms 24044 KB n=500
47 Correct 18 ms 24044 KB n=500
48 Correct 18 ms 24044 KB n=500
49 Correct 18 ms 24044 KB n=500
50 Correct 17 ms 24072 KB n=500
51 Correct 17 ms 24044 KB n=500
52 Correct 18 ms 24044 KB n=500
53 Correct 17 ms 24044 KB n=500
54 Correct 17 ms 24044 KB n=500
55 Correct 19 ms 23916 KB n=278
56 Correct 17 ms 24044 KB n=500
57 Correct 17 ms 24044 KB n=500
58 Correct 17 ms 24044 KB n=500
59 Correct 20 ms 24556 KB n=2000
60 Correct 21 ms 24556 KB n=2000
61 Correct 21 ms 24556 KB n=2000
62 Correct 20 ms 24556 KB n=2000
63 Correct 20 ms 24556 KB n=2000
64 Correct 22 ms 24556 KB n=2000
65 Correct 20 ms 24556 KB n=2000
66 Correct 20 ms 24556 KB n=2000
67 Correct 21 ms 24556 KB n=2000
68 Correct 24 ms 24556 KB n=2000
69 Correct 19 ms 24556 KB n=2000
70 Correct 19 ms 24576 KB n=2000
71 Correct 19 ms 24556 KB n=2000
72 Correct 19 ms 24556 KB n=2000
73 Correct 20 ms 24556 KB n=2000
74 Correct 20 ms 24556 KB n=1844
75 Correct 20 ms 24564 KB n=2000
76 Correct 21 ms 24556 KB n=2000
77 Correct 25 ms 24556 KB n=2000
78 Correct 20 ms 24556 KB n=2000
79 Correct 20 ms 24556 KB n=2000
80 Correct 20 ms 24556 KB n=2000
81 Correct 20 ms 24556 KB n=2000
82 Correct 22 ms 24556 KB n=2000
83 Correct 20 ms 24556 KB n=2000
84 Correct 20 ms 24556 KB n=2000
85 Correct 20 ms 24556 KB n=2000
86 Correct 20 ms 24684 KB n=2000
87 Correct 20 ms 24556 KB n=2000
88 Correct 21 ms 24556 KB n=2000
89 Correct 21 ms 24556 KB n=2000
90 Correct 20 ms 24556 KB n=2000
91 Correct 20 ms 24556 KB n=2000
# Verdict Execution time Memory Grader output
1 Correct 17 ms 23788 KB n=5
2 Correct 16 ms 23916 KB n=100
3 Correct 17 ms 23936 KB n=100
4 Correct 17 ms 23916 KB n=100
5 Correct 16 ms 23916 KB n=100
6 Correct 17 ms 23916 KB n=100
7 Correct 16 ms 23916 KB n=100
8 Correct 17 ms 23916 KB n=100
9 Correct 16 ms 23916 KB n=100
10 Correct 17 ms 24064 KB n=100
11 Correct 17 ms 23916 KB n=100
12 Correct 16 ms 23916 KB n=100
13 Correct 16 ms 23916 KB n=100
14 Correct 17 ms 23916 KB n=100
15 Correct 17 ms 23916 KB n=100
16 Correct 18 ms 23916 KB n=100
17 Correct 16 ms 23916 KB n=100
18 Correct 18 ms 23916 KB n=100
19 Correct 16 ms 23916 KB n=100
20 Correct 17 ms 23916 KB n=100
21 Correct 16 ms 23916 KB n=100
22 Correct 16 ms 23916 KB n=100
23 Correct 18 ms 23916 KB n=100
24 Correct 17 ms 23916 KB n=100
25 Correct 17 ms 23916 KB n=100
26 Correct 18 ms 23788 KB n=12
27 Correct 17 ms 23916 KB n=100
28 Correct 18 ms 24056 KB n=500
29 Correct 18 ms 24044 KB n=500
30 Correct 17 ms 24044 KB n=500
31 Correct 18 ms 24172 KB n=500
32 Correct 17 ms 24044 KB n=500
33 Correct 17 ms 24044 KB n=500
34 Correct 17 ms 24044 KB n=500
35 Correct 17 ms 24044 KB n=500
36 Correct 17 ms 24044 KB n=500
37 Correct 17 ms 24044 KB n=500
38 Correct 17 ms 24044 KB n=500
39 Correct 19 ms 24044 KB n=500
40 Correct 18 ms 24044 KB n=500
41 Correct 18 ms 24044 KB n=500
42 Correct 17 ms 24044 KB n=500
43 Correct 17 ms 24044 KB n=500
44 Correct 17 ms 24044 KB n=500
45 Correct 17 ms 24044 KB n=500
46 Correct 17 ms 24044 KB n=500
47 Correct 18 ms 24044 KB n=500
48 Correct 18 ms 24044 KB n=500
49 Correct 18 ms 24044 KB n=500
50 Correct 17 ms 24072 KB n=500
51 Correct 17 ms 24044 KB n=500
52 Correct 18 ms 24044 KB n=500
53 Correct 17 ms 24044 KB n=500
54 Correct 17 ms 24044 KB n=500
55 Correct 19 ms 23916 KB n=278
56 Correct 17 ms 24044 KB n=500
57 Correct 17 ms 24044 KB n=500
58 Correct 17 ms 24044 KB n=500
59 Correct 20 ms 24556 KB n=2000
60 Correct 21 ms 24556 KB n=2000
61 Correct 21 ms 24556 KB n=2000
62 Correct 20 ms 24556 KB n=2000
63 Correct 20 ms 24556 KB n=2000
64 Correct 22 ms 24556 KB n=2000
65 Correct 20 ms 24556 KB n=2000
66 Correct 20 ms 24556 KB n=2000
67 Correct 21 ms 24556 KB n=2000
68 Correct 24 ms 24556 KB n=2000
69 Correct 19 ms 24556 KB n=2000
70 Correct 19 ms 24576 KB n=2000
71 Correct 19 ms 24556 KB n=2000
72 Correct 19 ms 24556 KB n=2000
73 Correct 20 ms 24556 KB n=2000
74 Correct 20 ms 24556 KB n=1844
75 Correct 20 ms 24564 KB n=2000
76 Correct 21 ms 24556 KB n=2000
77 Correct 25 ms 24556 KB n=2000
78 Correct 20 ms 24556 KB n=2000
79 Correct 20 ms 24556 KB n=2000
80 Correct 20 ms 24556 KB n=2000
81 Correct 20 ms 24556 KB n=2000
82 Correct 22 ms 24556 KB n=2000
83 Correct 20 ms 24556 KB n=2000
84 Correct 20 ms 24556 KB n=2000
85 Correct 20 ms 24556 KB n=2000
86 Correct 20 ms 24684 KB n=2000
87 Correct 20 ms 24556 KB n=2000
88 Correct 21 ms 24556 KB n=2000
89 Correct 21 ms 24556 KB n=2000
90 Correct 20 ms 24556 KB n=2000
91 Correct 20 ms 24556 KB n=2000
92 Correct 867 ms 94312 KB n=200000
93 Correct 1319 ms 99388 KB n=200000
94 Correct 1259 ms 102052 KB n=200000
95 Correct 862 ms 93916 KB n=200000
96 Correct 824 ms 94300 KB n=200000
97 Correct 1356 ms 98412 KB n=200000
98 Correct 828 ms 94272 KB n=200000
99 Correct 1044 ms 94572 KB n=200000
100 Correct 845 ms 94344 KB n=200000
101 Correct 1278 ms 103020 KB n=200000
102 Correct 535 ms 95596 KB n=200000
103 Correct 532 ms 95468 KB n=200000
104 Correct 538 ms 95340 KB n=200000
105 Correct 568 ms 95812 KB n=200000
106 Correct 547 ms 96100 KB n=200000
107 Correct 538 ms 95772 KB n=200000
108 Correct 961 ms 94316 KB n=200000
109 Correct 960 ms 94444 KB n=200000
110 Correct 975 ms 94444 KB n=200000
111 Correct 875 ms 93532 KB n=200000
112 Correct 1278 ms 102292 KB n=200000
113 Correct 1412 ms 98588 KB n=200000
114 Correct 878 ms 93604 KB n=200000
115 Correct 1460 ms 96312 KB n=200000
116 Correct 807 ms 94276 KB n=200000
117 Correct 1261 ms 102528 KB n=200000
118 Correct 1421 ms 97432 KB n=200000
119 Correct 800 ms 94172 KB n=200000
120 Correct 1186 ms 101812 KB n=200000
121 Correct 1198 ms 102124 KB n=200000
122 Correct 1225 ms 102124 KB n=200000
123 Correct 542 ms 95596 KB n=200000
124 Correct 310 ms 42092 KB n=25264