Submission #878639

# Submission time Handle Problem Language Result Execution time Memory
878639 2023-11-25T02:50:26 Z 8pete8 Birthday gift (IZhO18_treearray) C++14
100 / 100
1324 ms 113604 KB
#include<iostream>
#include<stack>
#include<map>
#include<vector>
#include<string>
#include<unordered_map>
#include <queue>
#include<cstring>
#include<limits.h>
#include<cmath>
#include<set>
#include<algorithm>
#include<bitset>
using namespace std;
#define ll long long
#define f first
#define endl "\n"
#define s second
#define pii pair<int,int>
#define ppii pair<pii,pii>
#define vi vector<int>
#define pb push_back
//#define p push
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define F(n) for(int i=0;i<n;i++)
#define lb lower_bound
#define ub upper_bound
#define fastio ios::sync_with_stdio(false);cin.tie(NULL);
#pragma GCC optimize ("03,unroll-lopps")
using namespace std;
#define int long long
const int mod=9901,mxn=3*1e5+5,inf=1e18,lg=30,minf=-1e18;
vector<int>adj[mxn+10];
int h[mxn+10],up[mxn+10][lg+5],v[mxn+10],d[mxn+10];
set<pii>t,t2;
void dfs(int cur,int p){for(auto i:adj[cur])if(i!=p)h[i]=h[cur]+1,up[i][0]=cur,dfs(i,cur);}
int lca(int a,int b){
	if(h[a]<h[b])swap(a,b);
	int k=h[a]-h[b];
	for(int i=0;i<=lg;i++)if(k&(1<<i))a=up[a][i];
	if(a==b)return a;
	for(int i=lg;i>=0;i--)if(up[a][i]!=up[b][i])a=up[a][i],b=up[b][i];
	return up[a][0];
}
void update(int pos,int val,int lval){
	auto it=t.lb({lval,pos});
	t.erase(it);
	t.insert({val,pos});
}
pii qry(int val,int l,int r){
	auto it=t.lb({val,l});
	if(it==t.end()||((*it).f!=val))return {-1,-1};
	if((*it).s>=r)return {-1,-1};
	return {((*it).s+1),((*it).s+2)};
}
int32_t main(){
	fastio
	int n,m,q;cin>>n>>m>>q;
	for(int i=0;i<n-1;i++){
		int a,b;cin>>a>>b;
		adj[a].pb(b);
		adj[b].pb(a);
	}
	dfs(1,-1);
	for(int i=1;i<=lg;i++)for(int j=1;j<=n;j++)up[j][i]=up[up[j][i-1]][i-1];
	for(int i=0;i<m;i++)cin>>v[i],t2.insert({v[i],i});
	for(int i=0;i<m-1;i++)d[i]=lca(v[i],v[i+1]),t.insert({d[i],i});
	int a;
	while(q--){
		int ty;cin>>ty;
		if(ty==1){
			int pos,val;cin>>pos>>val;
			pos--;
			auto it=t2.lb({v[pos],pos});
			t2.erase(it);
			t2.insert({val,pos});
			v[pos]=val;
			if(pos<m-1){
				a=lca(v[pos],v[pos+1]);
				update(pos,a,d[pos]);
				d[pos]=a;
			}
			if(pos>0){
				a=lca(v[pos-1],v[pos]);
				update(pos-1,a,d[pos-1]);
				d[pos-1]=a;
			}
		}
		else{
			int l,r,ver;cin>>l>>r>>ver;
			l--,r--;
			auto it=t2.lb({ver,l});
			if(it!=t2.end()&&(*it).f==ver&&(*it).s<=r){
				cout<<(*it).s+1<<' '<<(*it).s+1<<'\n';
				continue;
			}
			pii tmp=qry(ver,l,r);
			cout<<tmp.f<<" "<<tmp.s<<'\n';
		}
	}
}

Compilation message

treearray.cpp:30:40: warning: bad option '-funroll-lopps' to pragma 'optimize' [-Wpragmas]
   30 | #pragma GCC optimize ("03,unroll-lopps")
      |                                        ^
treearray.cpp:37:23: warning: bad option '-funroll-lopps' to attribute 'optimize' [-Wattributes]
   37 | void dfs(int cur,int p){for(auto i:adj[cur])if(i!=p)h[i]=h[cur]+1,up[i][0]=cur,dfs(i,cur);}
      |                       ^
treearray.cpp:38:20: warning: bad option '-funroll-lopps' to attribute 'optimize' [-Wattributes]
   38 | int lca(int a,int b){
      |                    ^
treearray.cpp:46:37: warning: bad option '-funroll-lopps' to attribute 'optimize' [-Wattributes]
   46 | void update(int pos,int val,int lval){
      |                                     ^
treearray.cpp:51:28: warning: bad option '-funroll-lopps' to attribute 'optimize' [-Wattributes]
   51 | pii qry(int val,int l,int r){
      |                            ^
treearray.cpp:57:14: warning: bad option '-funroll-lopps' to attribute 'optimize' [-Wattributes]
   57 | int32_t main(){
      |              ^
# Verdict Execution time Memory Grader output
1 Correct 3 ms 12376 KB n=5
2 Correct 2 ms 12380 KB n=100
3 Correct 3 ms 12380 KB n=100
4 Correct 3 ms 12380 KB n=100
5 Correct 2 ms 12380 KB n=100
6 Correct 2 ms 12376 KB n=100
7 Correct 3 ms 12632 KB n=100
8 Correct 2 ms 12380 KB n=100
9 Correct 2 ms 12380 KB n=100
10 Correct 4 ms 12376 KB n=100
11 Correct 3 ms 12380 KB n=100
12 Correct 3 ms 12376 KB n=100
13 Correct 3 ms 12380 KB n=100
14 Correct 3 ms 12380 KB n=100
15 Correct 2 ms 12380 KB n=100
16 Correct 3 ms 12632 KB n=100
17 Correct 2 ms 12380 KB n=100
18 Correct 3 ms 12380 KB n=100
19 Correct 3 ms 12380 KB n=100
20 Correct 3 ms 12380 KB n=100
21 Correct 2 ms 12380 KB n=100
22 Correct 3 ms 12380 KB n=100
23 Correct 3 ms 12376 KB n=100
24 Correct 2 ms 12380 KB n=100
25 Correct 2 ms 12380 KB n=100
26 Correct 3 ms 12380 KB n=12
27 Correct 3 ms 12380 KB n=100
# Verdict Execution time Memory Grader output
1 Correct 3 ms 12376 KB n=5
2 Correct 2 ms 12380 KB n=100
3 Correct 3 ms 12380 KB n=100
4 Correct 3 ms 12380 KB n=100
5 Correct 2 ms 12380 KB n=100
6 Correct 2 ms 12376 KB n=100
7 Correct 3 ms 12632 KB n=100
8 Correct 2 ms 12380 KB n=100
9 Correct 2 ms 12380 KB n=100
10 Correct 4 ms 12376 KB n=100
11 Correct 3 ms 12380 KB n=100
12 Correct 3 ms 12376 KB n=100
13 Correct 3 ms 12380 KB n=100
14 Correct 3 ms 12380 KB n=100
15 Correct 2 ms 12380 KB n=100
16 Correct 3 ms 12632 KB n=100
17 Correct 2 ms 12380 KB n=100
18 Correct 3 ms 12380 KB n=100
19 Correct 3 ms 12380 KB n=100
20 Correct 3 ms 12380 KB n=100
21 Correct 2 ms 12380 KB n=100
22 Correct 3 ms 12380 KB n=100
23 Correct 3 ms 12376 KB n=100
24 Correct 2 ms 12380 KB n=100
25 Correct 2 ms 12380 KB n=100
26 Correct 3 ms 12380 KB n=12
27 Correct 3 ms 12380 KB n=100
28 Correct 3 ms 12380 KB n=500
29 Correct 3 ms 12380 KB n=500
30 Correct 4 ms 12380 KB n=500
31 Correct 3 ms 12380 KB n=500
32 Correct 3 ms 12376 KB n=500
33 Correct 3 ms 12380 KB n=500
34 Correct 3 ms 12380 KB n=500
35 Correct 3 ms 12380 KB n=500
36 Correct 3 ms 12380 KB n=500
37 Correct 3 ms 12468 KB n=500
38 Correct 4 ms 12388 KB n=500
39 Correct 3 ms 12388 KB n=500
40 Correct 3 ms 12388 KB n=500
41 Correct 3 ms 12380 KB n=500
42 Correct 3 ms 12384 KB n=500
43 Correct 3 ms 12376 KB n=500
44 Correct 3 ms 12380 KB n=500
45 Correct 3 ms 12380 KB n=500
46 Correct 3 ms 12464 KB n=500
47 Correct 3 ms 12380 KB n=500
48 Correct 3 ms 12380 KB n=500
49 Correct 3 ms 12380 KB n=500
50 Correct 3 ms 12380 KB n=500
51 Correct 3 ms 12380 KB n=500
52 Correct 3 ms 12380 KB n=500
53 Correct 3 ms 12376 KB n=500
54 Correct 3 ms 12376 KB n=500
55 Correct 3 ms 12380 KB n=278
56 Correct 3 ms 12380 KB n=500
57 Correct 4 ms 12380 KB n=500
58 Correct 3 ms 12380 KB n=500
# Verdict Execution time Memory Grader output
1 Correct 3 ms 12376 KB n=5
2 Correct 2 ms 12380 KB n=100
3 Correct 3 ms 12380 KB n=100
4 Correct 3 ms 12380 KB n=100
5 Correct 2 ms 12380 KB n=100
6 Correct 2 ms 12376 KB n=100
7 Correct 3 ms 12632 KB n=100
8 Correct 2 ms 12380 KB n=100
9 Correct 2 ms 12380 KB n=100
10 Correct 4 ms 12376 KB n=100
11 Correct 3 ms 12380 KB n=100
12 Correct 3 ms 12376 KB n=100
13 Correct 3 ms 12380 KB n=100
14 Correct 3 ms 12380 KB n=100
15 Correct 2 ms 12380 KB n=100
16 Correct 3 ms 12632 KB n=100
17 Correct 2 ms 12380 KB n=100
18 Correct 3 ms 12380 KB n=100
19 Correct 3 ms 12380 KB n=100
20 Correct 3 ms 12380 KB n=100
21 Correct 2 ms 12380 KB n=100
22 Correct 3 ms 12380 KB n=100
23 Correct 3 ms 12376 KB n=100
24 Correct 2 ms 12380 KB n=100
25 Correct 2 ms 12380 KB n=100
26 Correct 3 ms 12380 KB n=12
27 Correct 3 ms 12380 KB n=100
28 Correct 3 ms 12380 KB n=500
29 Correct 3 ms 12380 KB n=500
30 Correct 4 ms 12380 KB n=500
31 Correct 3 ms 12380 KB n=500
32 Correct 3 ms 12376 KB n=500
33 Correct 3 ms 12380 KB n=500
34 Correct 3 ms 12380 KB n=500
35 Correct 3 ms 12380 KB n=500
36 Correct 3 ms 12380 KB n=500
37 Correct 3 ms 12468 KB n=500
38 Correct 4 ms 12388 KB n=500
39 Correct 3 ms 12388 KB n=500
40 Correct 3 ms 12388 KB n=500
41 Correct 3 ms 12380 KB n=500
42 Correct 3 ms 12384 KB n=500
43 Correct 3 ms 12376 KB n=500
44 Correct 3 ms 12380 KB n=500
45 Correct 3 ms 12380 KB n=500
46 Correct 3 ms 12464 KB n=500
47 Correct 3 ms 12380 KB n=500
48 Correct 3 ms 12380 KB n=500
49 Correct 3 ms 12380 KB n=500
50 Correct 3 ms 12380 KB n=500
51 Correct 3 ms 12380 KB n=500
52 Correct 3 ms 12380 KB n=500
53 Correct 3 ms 12376 KB n=500
54 Correct 3 ms 12376 KB n=500
55 Correct 3 ms 12380 KB n=278
56 Correct 3 ms 12380 KB n=500
57 Correct 4 ms 12380 KB n=500
58 Correct 3 ms 12380 KB n=500
59 Correct 5 ms 12636 KB n=2000
60 Correct 6 ms 12892 KB n=2000
61 Correct 5 ms 12888 KB n=2000
62 Correct 5 ms 12636 KB n=2000
63 Correct 6 ms 12636 KB n=2000
64 Correct 5 ms 12892 KB n=2000
65 Correct 5 ms 12700 KB n=2000
66 Correct 6 ms 12888 KB n=2000
67 Correct 5 ms 12636 KB n=2000
68 Correct 6 ms 12892 KB n=2000
69 Correct 5 ms 12636 KB n=2000
70 Correct 5 ms 12636 KB n=2000
71 Correct 5 ms 12696 KB n=2000
72 Correct 5 ms 12636 KB n=2000
73 Correct 5 ms 12632 KB n=2000
74 Correct 5 ms 12636 KB n=1844
75 Correct 5 ms 12808 KB n=2000
76 Correct 5 ms 12636 KB n=2000
77 Correct 5 ms 12632 KB n=2000
78 Correct 6 ms 12636 KB n=2000
79 Correct 6 ms 12636 KB n=2000
80 Correct 6 ms 12892 KB n=2000
81 Correct 6 ms 12632 KB n=2000
82 Correct 5 ms 12636 KB n=2000
83 Correct 6 ms 12892 KB n=2000
84 Correct 6 ms 12636 KB n=2000
85 Correct 6 ms 12880 KB n=2000
86 Correct 6 ms 12636 KB n=2000
87 Correct 5 ms 12640 KB n=2000
88 Correct 5 ms 12896 KB n=2000
89 Correct 6 ms 12904 KB n=2000
90 Correct 6 ms 12904 KB n=2000
91 Correct 5 ms 12640 KB n=2000
# Verdict Execution time Memory Grader output
1 Correct 3 ms 12376 KB n=5
2 Correct 2 ms 12380 KB n=100
3 Correct 3 ms 12380 KB n=100
4 Correct 3 ms 12380 KB n=100
5 Correct 2 ms 12380 KB n=100
6 Correct 2 ms 12376 KB n=100
7 Correct 3 ms 12632 KB n=100
8 Correct 2 ms 12380 KB n=100
9 Correct 2 ms 12380 KB n=100
10 Correct 4 ms 12376 KB n=100
11 Correct 3 ms 12380 KB n=100
12 Correct 3 ms 12376 KB n=100
13 Correct 3 ms 12380 KB n=100
14 Correct 3 ms 12380 KB n=100
15 Correct 2 ms 12380 KB n=100
16 Correct 3 ms 12632 KB n=100
17 Correct 2 ms 12380 KB n=100
18 Correct 3 ms 12380 KB n=100
19 Correct 3 ms 12380 KB n=100
20 Correct 3 ms 12380 KB n=100
21 Correct 2 ms 12380 KB n=100
22 Correct 3 ms 12380 KB n=100
23 Correct 3 ms 12376 KB n=100
24 Correct 2 ms 12380 KB n=100
25 Correct 2 ms 12380 KB n=100
26 Correct 3 ms 12380 KB n=12
27 Correct 3 ms 12380 KB n=100
28 Correct 3 ms 12380 KB n=500
29 Correct 3 ms 12380 KB n=500
30 Correct 4 ms 12380 KB n=500
31 Correct 3 ms 12380 KB n=500
32 Correct 3 ms 12376 KB n=500
33 Correct 3 ms 12380 KB n=500
34 Correct 3 ms 12380 KB n=500
35 Correct 3 ms 12380 KB n=500
36 Correct 3 ms 12380 KB n=500
37 Correct 3 ms 12468 KB n=500
38 Correct 4 ms 12388 KB n=500
39 Correct 3 ms 12388 KB n=500
40 Correct 3 ms 12388 KB n=500
41 Correct 3 ms 12380 KB n=500
42 Correct 3 ms 12384 KB n=500
43 Correct 3 ms 12376 KB n=500
44 Correct 3 ms 12380 KB n=500
45 Correct 3 ms 12380 KB n=500
46 Correct 3 ms 12464 KB n=500
47 Correct 3 ms 12380 KB n=500
48 Correct 3 ms 12380 KB n=500
49 Correct 3 ms 12380 KB n=500
50 Correct 3 ms 12380 KB n=500
51 Correct 3 ms 12380 KB n=500
52 Correct 3 ms 12380 KB n=500
53 Correct 3 ms 12376 KB n=500
54 Correct 3 ms 12376 KB n=500
55 Correct 3 ms 12380 KB n=278
56 Correct 3 ms 12380 KB n=500
57 Correct 4 ms 12380 KB n=500
58 Correct 3 ms 12380 KB n=500
59 Correct 5 ms 12636 KB n=2000
60 Correct 6 ms 12892 KB n=2000
61 Correct 5 ms 12888 KB n=2000
62 Correct 5 ms 12636 KB n=2000
63 Correct 6 ms 12636 KB n=2000
64 Correct 5 ms 12892 KB n=2000
65 Correct 5 ms 12700 KB n=2000
66 Correct 6 ms 12888 KB n=2000
67 Correct 5 ms 12636 KB n=2000
68 Correct 6 ms 12892 KB n=2000
69 Correct 5 ms 12636 KB n=2000
70 Correct 5 ms 12636 KB n=2000
71 Correct 5 ms 12696 KB n=2000
72 Correct 5 ms 12636 KB n=2000
73 Correct 5 ms 12632 KB n=2000
74 Correct 5 ms 12636 KB n=1844
75 Correct 5 ms 12808 KB n=2000
76 Correct 5 ms 12636 KB n=2000
77 Correct 5 ms 12632 KB n=2000
78 Correct 6 ms 12636 KB n=2000
79 Correct 6 ms 12636 KB n=2000
80 Correct 6 ms 12892 KB n=2000
81 Correct 6 ms 12632 KB n=2000
82 Correct 5 ms 12636 KB n=2000
83 Correct 6 ms 12892 KB n=2000
84 Correct 6 ms 12636 KB n=2000
85 Correct 6 ms 12880 KB n=2000
86 Correct 6 ms 12636 KB n=2000
87 Correct 5 ms 12640 KB n=2000
88 Correct 5 ms 12896 KB n=2000
89 Correct 6 ms 12904 KB n=2000
90 Correct 6 ms 12904 KB n=2000
91 Correct 5 ms 12640 KB n=2000
92 Correct 718 ms 108924 KB n=200000
93 Correct 1150 ms 111696 KB n=200000
94 Correct 1171 ms 113604 KB n=200000
95 Correct 695 ms 108756 KB n=200000
96 Correct 695 ms 108396 KB n=200000
97 Correct 1324 ms 111476 KB n=200000
98 Correct 830 ms 108704 KB n=200000
99 Correct 854 ms 109220 KB n=200000
100 Correct 734 ms 108536 KB n=200000
101 Correct 1260 ms 113504 KB n=200000
102 Correct 378 ms 110164 KB n=200000
103 Correct 370 ms 109908 KB n=200000
104 Correct 395 ms 110160 KB n=200000
105 Correct 378 ms 110504 KB n=200000
106 Correct 371 ms 110412 KB n=200000
107 Correct 379 ms 110348 KB n=200000
108 Correct 770 ms 108880 KB n=200000
109 Correct 774 ms 108936 KB n=200000
110 Correct 799 ms 109076 KB n=200000
111 Correct 670 ms 107776 KB n=200000
112 Correct 1188 ms 113300 KB n=200000
113 Correct 1194 ms 111444 KB n=200000
114 Correct 648 ms 108308 KB n=200000
115 Correct 1151 ms 109904 KB n=200000
116 Correct 708 ms 108732 KB n=200000
117 Correct 1272 ms 113456 KB n=200000
118 Correct 1240 ms 110504 KB n=200000
119 Correct 712 ms 108796 KB n=200000
120 Correct 1131 ms 112508 KB n=200000
121 Correct 1128 ms 112504 KB n=200000
122 Correct 1148 ms 113520 KB n=200000
123 Correct 386 ms 109904 KB n=200000
124 Correct 203 ms 35920 KB n=25264