Submission #492384

# Submission time Handle Problem Language Result Execution time Memory
492384 2021-12-07T03:59:59 Z NhatMinh0208 Birthday gift (IZhO18_treearray) C++14
100 / 100
806 ms 65064 KB
#ifndef CPL_TEMPLATE
#define CPL_TEMPLATE
/*
	Normie's Template v2.5
	Changes:
    Added warning against using pragmas on USACO.
*/
// Standard library in one include.
#include <bits/stdc++.h>
using namespace std;
 
// ordered_set library.
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set(el) tree<el,null_type,less<el>,rb_tree_tag,tree_order_statistics_node_update>
 
// AtCoder library. (Comment out these two lines if you're not submitting in AtCoder.) (Or if you want to use it in other judges, run expander.py first.)
//#include <atcoder/all>
//using namespace atcoder;

//Pragmas (Comment out these three lines if you're submitting in szkopul or USACO.)
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast,unroll-loops,tree-vectorize")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
 
//File I/O.
#define FILE_IN "cseq.inp"
#define FILE_OUT "cseq.out"
#define ofile freopen(FILE_IN,"r",stdin);freopen(FILE_OUT,"w",stdout)
 
//Fast I/O.
#define fio ios::sync_with_stdio(0);cin.tie(0)
#define nfio cin.tie(0)
#define endl "\n"
 
//Order checking.
#define ord(a,b,c) ((a>=b)and(b>=c))
 
//min/max redefines, so i dont have to resolve annoying compile errors.
#define min(a,b) (((a)<(b))?(a):(b))
#define max(a,b) (((a)>(b))?(a):(b))

// Fast min/max assigns to use with AVX.
// Requires g++ 9.2.0.
template<typename T>
__attribute__((always_inline)) void chkmin(T& a, const T& b) {
    a=(a<b)?a:b;
}

template<typename T>
__attribute__((always_inline)) void chkmax(T& a, const T& b) {
    a=(a>b)?a:b;
}
 
//Constants.
#define MOD (ll(998244353))
#define MAX 300001
#define mag 320
const long double PI=3.14159265358979;
 
//Pairs and 3-pairs.
#define p1 first
#define p2 second.first
#define p3 second.second
#define fi first
#define se second
#define pii(element_type) pair<element_type,element_type>
#define piii(element_type) pair<element_type,pii(element_type)>
 
//Quick power of 2.
#define pow2(x) (ll(1)<<x)
 
//Short for-loops.
#define ff(i,__,___) for(int i=__;i<=___;i++)
#define rr(i,__,___) for(int i=__;i>=___;i--)
 
//Typedefs.
#define bi BigInt
typedef long long ll;
typedef long double ld;
typedef short sh;

// Binpow and stuff
ll BOW(ll a, ll x, ll p)
{
	if (!x) return 1;
	ll res=BOW(a,x/2,p);
	res*=res;
	res%=p;
	if (x%2) res*=a;
	return res%p;
}
ll INV(ll a, ll p)
{
	return BOW(a,p-2,p);
}
//---------END-------//
#endif
vector<int> gt[200001];
int par[200001][20];
int dep[200001];
int n,m,i,j,k,t,t1,u,v,a,b;
int arr[400001];
set<int> buc[200001];
void dfs(int x, int p) {
	par[x][0]=p;
 // cout<<x<<' '<<p<<endl;
	dep[x]=dep[p]+1;
	for (int i=1;i<20;i++) {
		par[x][i]=par[par[x][i-1]][i-1];
	}
	for (auto g :gt[x]) if (g-p) dfs(g,x);
}
int lca(int u, int v) {
	for (int i=19;i>=0;i--) if (dep[u]-(1<<i)>=dep[v]) u=par[u][i];
	for (int i=19;i>=0;i--) if (dep[v]-(1<<i)>=dep[u]) v=par[v][i];
	if (u==v) return u;
	for (int i=19;i>=0;i--) if (par[u][i]!=par[v][i]) {
		u=par[u][i];
		v=par[v][i];
	}
	return par[u][0];
}
void change(int a, int b) {
	buc[arr[a*2-1]].erase(a*2-1);
	if (a>1) {
		buc[arr[a*2-2]].erase(a*2-2);
	}
	if (a<m) {
		buc[arr[a*2]].erase(a*2);
	}
	arr[2*a-1]=b;
	buc[arr[a*2-1]].insert(a*2-1);
	if (a>1) {
		arr[a*2-2]=lca(arr[a*2-3],arr[a*2-1]);
		buc[arr[a*2-2]].insert(a*2-2);
	}
	if (a<m) {
		arr[a*2]=lca(arr[a*2-1],arr[a*2+1]);
		buc[arr[a*2]].insert(a*2);
	}
}
int find(int l, int r, int x) {
	auto it = buc[x].lower_bound(2*l-1);
	if (it == buc[x].end() || (*it)>(2*r-1)) return -1;
	else return (*it);
}
int main()
{
	fio;
	cin>>n>>m>>t;
	for (i=1;i<n;i++) {
      cin>>u>>v;
		gt[u].push_back(v);
		gt[v].push_back(u);
	}
	dfs(1,1);
	for (i=1;i<=m;i++) {
		cin>>arr[i*2-1];
	}
	for (i=1;i<m;i++) {
		arr[i*2]=lca(arr[i*2-1],arr[i*2+1]);
	}
	for (i=1;i<=2*m-1;i++) {
		buc[arr[i]].insert(i);
	}
	for (t1=0;t1<t;t1++) {
		cin>>u;
     // for (i=1;i<=2*m-1;i++) cout<<arr[i]<<' '; cout<<endl;
		if (u==1) {
			cin>>a>>b;
			change(a,b);
		}
		else {
			cin>>a>>b>>v;
			u=find(a,b,v);
			if (u==-1) cout<<-1<<' '<<-1;
			else if (u&1) {
				cout<<(u+1)/2<<' '<<(u+1)/2;
			}
			else {
				cout<<(u/2)<<' '<<(u/2)+1;
			}
			cout<<endl;
		}
	}
}

Compilation message

treearray.cpp:23: warning: ignoring '#pragma comment ' [-Wunknown-pragmas]
   23 | #pragma comment(linker, "/stack:200000000")
      |
# Verdict Execution time Memory Grader output
1 Correct 7 ms 14412 KB n=5
2 Correct 8 ms 14440 KB n=100
3 Correct 9 ms 14412 KB n=100
4 Correct 7 ms 14412 KB n=100
5 Correct 11 ms 14416 KB n=100
6 Correct 9 ms 14440 KB n=100
7 Correct 8 ms 14412 KB n=100
8 Correct 8 ms 14412 KB n=100
9 Correct 7 ms 14412 KB n=100
10 Correct 8 ms 14412 KB n=100
11 Correct 7 ms 14412 KB n=100
12 Correct 7 ms 14440 KB n=100
13 Correct 8 ms 14360 KB n=100
14 Correct 8 ms 14412 KB n=100
15 Correct 9 ms 14320 KB n=100
16 Correct 9 ms 14408 KB n=100
17 Correct 8 ms 14412 KB n=100
18 Correct 10 ms 14412 KB n=100
19 Correct 9 ms 14440 KB n=100
20 Correct 9 ms 14412 KB n=100
21 Correct 8 ms 14412 KB n=100
22 Correct 8 ms 14412 KB n=100
23 Correct 8 ms 14412 KB n=100
24 Correct 8 ms 14412 KB n=100
25 Correct 7 ms 14412 KB n=100
26 Correct 7 ms 14416 KB n=12
27 Correct 8 ms 14320 KB n=100
# Verdict Execution time Memory Grader output
1 Correct 7 ms 14412 KB n=5
2 Correct 8 ms 14440 KB n=100
3 Correct 9 ms 14412 KB n=100
4 Correct 7 ms 14412 KB n=100
5 Correct 11 ms 14416 KB n=100
6 Correct 9 ms 14440 KB n=100
7 Correct 8 ms 14412 KB n=100
8 Correct 8 ms 14412 KB n=100
9 Correct 7 ms 14412 KB n=100
10 Correct 8 ms 14412 KB n=100
11 Correct 7 ms 14412 KB n=100
12 Correct 7 ms 14440 KB n=100
13 Correct 8 ms 14360 KB n=100
14 Correct 8 ms 14412 KB n=100
15 Correct 9 ms 14320 KB n=100
16 Correct 9 ms 14408 KB n=100
17 Correct 8 ms 14412 KB n=100
18 Correct 10 ms 14412 KB n=100
19 Correct 9 ms 14440 KB n=100
20 Correct 9 ms 14412 KB n=100
21 Correct 8 ms 14412 KB n=100
22 Correct 8 ms 14412 KB n=100
23 Correct 8 ms 14412 KB n=100
24 Correct 8 ms 14412 KB n=100
25 Correct 7 ms 14412 KB n=100
26 Correct 7 ms 14416 KB n=12
27 Correct 8 ms 14320 KB n=100
28 Correct 11 ms 14532 KB n=500
29 Correct 9 ms 14540 KB n=500
30 Correct 11 ms 14532 KB n=500
31 Correct 8 ms 14412 KB n=500
32 Correct 9 ms 14412 KB n=500
33 Correct 11 ms 14412 KB n=500
34 Correct 9 ms 14412 KB n=500
35 Correct 8 ms 14468 KB n=500
36 Correct 7 ms 14540 KB n=500
37 Correct 8 ms 14520 KB n=500
38 Correct 7 ms 14412 KB n=500
39 Correct 8 ms 14516 KB n=500
40 Correct 7 ms 14412 KB n=500
41 Correct 7 ms 14412 KB n=500
42 Correct 7 ms 14412 KB n=500
43 Correct 8 ms 14412 KB n=500
44 Correct 8 ms 14528 KB n=500
45 Correct 12 ms 14500 KB n=500
46 Correct 9 ms 14436 KB n=500
47 Correct 9 ms 14536 KB n=500
48 Correct 10 ms 14440 KB n=500
49 Correct 7 ms 14540 KB n=500
50 Correct 8 ms 14412 KB n=500
51 Correct 8 ms 14504 KB n=500
52 Correct 7 ms 14548 KB n=500
53 Correct 7 ms 14540 KB n=500
54 Correct 8 ms 14540 KB n=500
55 Correct 8 ms 14540 KB n=278
56 Correct 8 ms 14548 KB n=500
57 Correct 9 ms 14540 KB n=500
58 Correct 11 ms 14540 KB n=500
# Verdict Execution time Memory Grader output
1 Correct 7 ms 14412 KB n=5
2 Correct 8 ms 14440 KB n=100
3 Correct 9 ms 14412 KB n=100
4 Correct 7 ms 14412 KB n=100
5 Correct 11 ms 14416 KB n=100
6 Correct 9 ms 14440 KB n=100
7 Correct 8 ms 14412 KB n=100
8 Correct 8 ms 14412 KB n=100
9 Correct 7 ms 14412 KB n=100
10 Correct 8 ms 14412 KB n=100
11 Correct 7 ms 14412 KB n=100
12 Correct 7 ms 14440 KB n=100
13 Correct 8 ms 14360 KB n=100
14 Correct 8 ms 14412 KB n=100
15 Correct 9 ms 14320 KB n=100
16 Correct 9 ms 14408 KB n=100
17 Correct 8 ms 14412 KB n=100
18 Correct 10 ms 14412 KB n=100
19 Correct 9 ms 14440 KB n=100
20 Correct 9 ms 14412 KB n=100
21 Correct 8 ms 14412 KB n=100
22 Correct 8 ms 14412 KB n=100
23 Correct 8 ms 14412 KB n=100
24 Correct 8 ms 14412 KB n=100
25 Correct 7 ms 14412 KB n=100
26 Correct 7 ms 14416 KB n=12
27 Correct 8 ms 14320 KB n=100
28 Correct 11 ms 14532 KB n=500
29 Correct 9 ms 14540 KB n=500
30 Correct 11 ms 14532 KB n=500
31 Correct 8 ms 14412 KB n=500
32 Correct 9 ms 14412 KB n=500
33 Correct 11 ms 14412 KB n=500
34 Correct 9 ms 14412 KB n=500
35 Correct 8 ms 14468 KB n=500
36 Correct 7 ms 14540 KB n=500
37 Correct 8 ms 14520 KB n=500
38 Correct 7 ms 14412 KB n=500
39 Correct 8 ms 14516 KB n=500
40 Correct 7 ms 14412 KB n=500
41 Correct 7 ms 14412 KB n=500
42 Correct 7 ms 14412 KB n=500
43 Correct 8 ms 14412 KB n=500
44 Correct 8 ms 14528 KB n=500
45 Correct 12 ms 14500 KB n=500
46 Correct 9 ms 14436 KB n=500
47 Correct 9 ms 14536 KB n=500
48 Correct 10 ms 14440 KB n=500
49 Correct 7 ms 14540 KB n=500
50 Correct 8 ms 14412 KB n=500
51 Correct 8 ms 14504 KB n=500
52 Correct 7 ms 14548 KB n=500
53 Correct 7 ms 14540 KB n=500
54 Correct 8 ms 14540 KB n=500
55 Correct 8 ms 14540 KB n=278
56 Correct 8 ms 14548 KB n=500
57 Correct 9 ms 14540 KB n=500
58 Correct 11 ms 14540 KB n=500
59 Correct 11 ms 14848 KB n=2000
60 Correct 11 ms 14916 KB n=2000
61 Correct 15 ms 14896 KB n=2000
62 Correct 14 ms 14844 KB n=2000
63 Correct 16 ms 14796 KB n=2000
64 Correct 10 ms 14808 KB n=2000
65 Correct 10 ms 14796 KB n=2000
66 Correct 10 ms 14880 KB n=2000
67 Correct 13 ms 14860 KB n=2000
68 Correct 11 ms 14796 KB n=2000
69 Correct 11 ms 14796 KB n=2000
70 Correct 9 ms 14856 KB n=2000
71 Correct 10 ms 14796 KB n=2000
72 Correct 9 ms 14784 KB n=2000
73 Correct 12 ms 14796 KB n=2000
74 Correct 10 ms 14796 KB n=1844
75 Correct 14 ms 14796 KB n=2000
76 Correct 12 ms 14796 KB n=2000
77 Correct 10 ms 14796 KB n=2000
78 Correct 10 ms 14796 KB n=2000
79 Correct 10 ms 14864 KB n=2000
80 Correct 10 ms 14904 KB n=2000
81 Correct 11 ms 14880 KB n=2000
82 Correct 13 ms 14796 KB n=2000
83 Correct 12 ms 14908 KB n=2000
84 Correct 11 ms 14872 KB n=2000
85 Correct 13 ms 14796 KB n=2000
86 Correct 11 ms 14820 KB n=2000
87 Correct 10 ms 14796 KB n=2000
88 Correct 10 ms 14924 KB n=2000
89 Correct 10 ms 14904 KB n=2000
90 Correct 10 ms 14880 KB n=2000
91 Correct 10 ms 14796 KB n=2000
# Verdict Execution time Memory Grader output
1 Correct 7 ms 14412 KB n=5
2 Correct 8 ms 14440 KB n=100
3 Correct 9 ms 14412 KB n=100
4 Correct 7 ms 14412 KB n=100
5 Correct 11 ms 14416 KB n=100
6 Correct 9 ms 14440 KB n=100
7 Correct 8 ms 14412 KB n=100
8 Correct 8 ms 14412 KB n=100
9 Correct 7 ms 14412 KB n=100
10 Correct 8 ms 14412 KB n=100
11 Correct 7 ms 14412 KB n=100
12 Correct 7 ms 14440 KB n=100
13 Correct 8 ms 14360 KB n=100
14 Correct 8 ms 14412 KB n=100
15 Correct 9 ms 14320 KB n=100
16 Correct 9 ms 14408 KB n=100
17 Correct 8 ms 14412 KB n=100
18 Correct 10 ms 14412 KB n=100
19 Correct 9 ms 14440 KB n=100
20 Correct 9 ms 14412 KB n=100
21 Correct 8 ms 14412 KB n=100
22 Correct 8 ms 14412 KB n=100
23 Correct 8 ms 14412 KB n=100
24 Correct 8 ms 14412 KB n=100
25 Correct 7 ms 14412 KB n=100
26 Correct 7 ms 14416 KB n=12
27 Correct 8 ms 14320 KB n=100
28 Correct 11 ms 14532 KB n=500
29 Correct 9 ms 14540 KB n=500
30 Correct 11 ms 14532 KB n=500
31 Correct 8 ms 14412 KB n=500
32 Correct 9 ms 14412 KB n=500
33 Correct 11 ms 14412 KB n=500
34 Correct 9 ms 14412 KB n=500
35 Correct 8 ms 14468 KB n=500
36 Correct 7 ms 14540 KB n=500
37 Correct 8 ms 14520 KB n=500
38 Correct 7 ms 14412 KB n=500
39 Correct 8 ms 14516 KB n=500
40 Correct 7 ms 14412 KB n=500
41 Correct 7 ms 14412 KB n=500
42 Correct 7 ms 14412 KB n=500
43 Correct 8 ms 14412 KB n=500
44 Correct 8 ms 14528 KB n=500
45 Correct 12 ms 14500 KB n=500
46 Correct 9 ms 14436 KB n=500
47 Correct 9 ms 14536 KB n=500
48 Correct 10 ms 14440 KB n=500
49 Correct 7 ms 14540 KB n=500
50 Correct 8 ms 14412 KB n=500
51 Correct 8 ms 14504 KB n=500
52 Correct 7 ms 14548 KB n=500
53 Correct 7 ms 14540 KB n=500
54 Correct 8 ms 14540 KB n=500
55 Correct 8 ms 14540 KB n=278
56 Correct 8 ms 14548 KB n=500
57 Correct 9 ms 14540 KB n=500
58 Correct 11 ms 14540 KB n=500
59 Correct 11 ms 14848 KB n=2000
60 Correct 11 ms 14916 KB n=2000
61 Correct 15 ms 14896 KB n=2000
62 Correct 14 ms 14844 KB n=2000
63 Correct 16 ms 14796 KB n=2000
64 Correct 10 ms 14808 KB n=2000
65 Correct 10 ms 14796 KB n=2000
66 Correct 10 ms 14880 KB n=2000
67 Correct 13 ms 14860 KB n=2000
68 Correct 11 ms 14796 KB n=2000
69 Correct 11 ms 14796 KB n=2000
70 Correct 9 ms 14856 KB n=2000
71 Correct 10 ms 14796 KB n=2000
72 Correct 9 ms 14784 KB n=2000
73 Correct 12 ms 14796 KB n=2000
74 Correct 10 ms 14796 KB n=1844
75 Correct 14 ms 14796 KB n=2000
76 Correct 12 ms 14796 KB n=2000
77 Correct 10 ms 14796 KB n=2000
78 Correct 10 ms 14796 KB n=2000
79 Correct 10 ms 14864 KB n=2000
80 Correct 10 ms 14904 KB n=2000
81 Correct 11 ms 14880 KB n=2000
82 Correct 13 ms 14796 KB n=2000
83 Correct 12 ms 14908 KB n=2000
84 Correct 11 ms 14872 KB n=2000
85 Correct 13 ms 14796 KB n=2000
86 Correct 11 ms 14820 KB n=2000
87 Correct 10 ms 14796 KB n=2000
88 Correct 10 ms 14924 KB n=2000
89 Correct 10 ms 14904 KB n=2000
90 Correct 10 ms 14880 KB n=2000
91 Correct 10 ms 14796 KB n=2000
92 Correct 645 ms 59432 KB n=200000
93 Correct 767 ms 61752 KB n=200000
94 Correct 766 ms 64124 KB n=200000
95 Correct 611 ms 59224 KB n=200000
96 Correct 636 ms 59224 KB n=200000
97 Correct 795 ms 61232 KB n=200000
98 Correct 597 ms 59404 KB n=200000
99 Correct 748 ms 58780 KB n=200000
100 Correct 597 ms 59316 KB n=200000
101 Correct 704 ms 64992 KB n=200000
102 Correct 358 ms 60148 KB n=200000
103 Correct 351 ms 60268 KB n=200000
104 Correct 362 ms 60224 KB n=200000
105 Correct 367 ms 59988 KB n=200000
106 Correct 378 ms 59992 KB n=200000
107 Correct 370 ms 59960 KB n=200000
108 Correct 646 ms 58960 KB n=200000
109 Correct 649 ms 58888 KB n=200000
110 Correct 683 ms 58936 KB n=200000
111 Correct 611 ms 59244 KB n=200000
112 Correct 719 ms 64340 KB n=200000
113 Correct 744 ms 60996 KB n=200000
114 Correct 608 ms 59248 KB n=200000
115 Correct 806 ms 59600 KB n=200000
116 Correct 570 ms 59068 KB n=200000
117 Correct 717 ms 64492 KB n=200000
118 Correct 773 ms 60208 KB n=200000
119 Correct 544 ms 58992 KB n=200000
120 Correct 668 ms 64672 KB n=200000
121 Correct 661 ms 64708 KB n=200000
122 Correct 665 ms 65064 KB n=200000
123 Correct 400 ms 59588 KB n=200000
124 Correct 173 ms 27536 KB n=25264