Submission #1100665

# Submission time Handle Problem Language Result Execution time Memory
1100665 2024-10-14T12:18:10 Z vjudge1 Birthday gift (IZhO18_treearray) C++17
30 / 100
4000 ms 11080 KB
//#pragma optimize ("g",on)
//#pragma GCC optimize ("unroll-loops")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define int long long
#define ll long long
#define db double
#define ld long double
#define pb push_back
#define pf push_front
#define ppb pop_back()
#define ppf pop_front()
#define len(x) (int)x.size()
#define vi vector<int>
#define vpii vector<pair<int,int>>
#define vvi vector<vi>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define mii map<int,int>
#define y1 u_will_not_notice_this15
#define hash u_will_not_notice_this
#define tm (tl+tr>>1)
#define ls v<<1,tl,tm
#define rs v<<1|1,tm+1,tr
#define pii pair<int,int>
#define lb lower_bound
#define ub upper_bound
#define f first
#define s second
#define ordered_set tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>
#define str string
#define ins insert
#define elif else if
using namespace std;
using namespace __gnu_pbds;
const int maxn=2e5+5,mod=1e9+7,inf=1e18,bir=1,nol=0;
const bool TEST=0;
const str tch="+abcdefghijklmnopqrstuvwxyz",Tch="+ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const str Monday_14_10_24[5]={"NO\n","YES\n","-1\n","0\n","1\n"};
void at(int ok){cout<<Monday_14_10_24[ok];}
bool bit(int mask,int i){return ((bir<<i)&mask);}
int gcd(int a,int b){while(b){if(a>b) swap(a,b);b%=a;}return a;}
int lcm(int a,int b){return a/gcd(a,b)*b;}
int rnd(){return (rand()<<15)^rand();}
int bpm(int a,int b){a%=mod;if(b==0) return 1;if(b&1)return bpm(a,b-1)*a%mod;int x=bpm(a,b>>1);return x*x%mod;}
int bp(int a,int b){if(b==0) return 1;if(b&1)return bp(a,b-1)*a;int x=bp(a,b>>1);return x*x;}
//CODE STARTS HERE:
//don't get stuck on one aproach
int n,m,q,a[maxn],t,tin[maxn],tout[maxn],up[maxn][30];
vi g[maxn];
void dfs(int v=1,int p=1){
	tin[v]=++t,up[v][0]=p;
	for(int j=1;j<=20;j++)up[v][j]=up[up[v][j-1]][j-1];
	for(auto to:g[v])if(to!=p)dfs(to,v);
	tout[v]=t;
}
bool f(int x,int y){
	return tin[x]<=tin[y]&&tout[x]>=tout[y];
}
int lca(int x,int y){
	if(f(x,y))return x;
	if(f(y,x))return y;
	int a=x,b=y;
	for(int i=20;i>=0;i--)if(!f(up[a][i],b))a=up[a][i];
	return up[a][0];
}
void whyareucopying(){
	cin>>n>>m>>q;
	for(int i=1;i<n;i++){
		int x,y;cin>>x>>y;g[x].pb(y),g[y].pb(x);
	}
	for(int i=1;i<=m;i++)cin>>a[i];
	dfs();
	while(q--){
		int tp;
		cin>>tp;
		if(tp==1){
			int pos,val;cin>>pos>>val;a[pos]=val;
		}
		else{
			int l,r,v;cin>>l>>r>>v;
			bool ok=0;
			for(int i=l;i<=r;i++){
				int lc=a[i];
				for(int j=i;j<=r;j++){
					lc=lca(lc,a[j]);
					if(lc==v){
						ok=1;cout<<i<<' '<<j<<'\n';break;
					}
				}
				if(ok)break;
			}
			if(!ok)cout<<"-1 -1\n";
		}
	}
}
/*
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
*/
signed main(){
//	freopen("txt.in","r",stdin),freopen("txt.out","w",stdout);
	ios_base::sync_with_stdio(0),cin.tie(0);
	srand(time(0));
	int T=1;
	if(TEST)cin>>T;
	for(int i=1;i<=T;i++){
//		cout<<"Case "<<i<<": ";
		whyareucopying();
	}
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 10832 KB n=5
2 Correct 2 ms 11000 KB n=100
3 Correct 2 ms 10832 KB n=100
4 Correct 2 ms 10832 KB n=100
5 Correct 2 ms 10832 KB n=100
6 Correct 3 ms 10832 KB n=100
7 Correct 4 ms 11000 KB n=100
8 Correct 2 ms 10832 KB n=100
9 Correct 3 ms 10832 KB n=100
10 Correct 4 ms 10832 KB n=100
11 Correct 3 ms 10896 KB n=100
12 Correct 2 ms 10832 KB n=100
13 Correct 3 ms 10832 KB n=100
14 Correct 2 ms 10832 KB n=100
15 Correct 2 ms 10832 KB n=100
16 Correct 2 ms 10832 KB n=100
17 Correct 3 ms 10832 KB n=100
18 Correct 2 ms 10832 KB n=100
19 Correct 2 ms 10832 KB n=100
20 Correct 2 ms 10832 KB n=100
21 Correct 3 ms 11004 KB n=100
22 Correct 2 ms 10832 KB n=100
23 Correct 3 ms 10832 KB n=100
24 Correct 3 ms 10832 KB n=100
25 Correct 2 ms 10832 KB n=100
26 Correct 2 ms 10832 KB n=12
27 Correct 3 ms 10832 KB n=100
# Verdict Execution time Memory Grader output
1 Correct 2 ms 10832 KB n=5
2 Correct 2 ms 11000 KB n=100
3 Correct 2 ms 10832 KB n=100
4 Correct 2 ms 10832 KB n=100
5 Correct 2 ms 10832 KB n=100
6 Correct 3 ms 10832 KB n=100
7 Correct 4 ms 11000 KB n=100
8 Correct 2 ms 10832 KB n=100
9 Correct 3 ms 10832 KB n=100
10 Correct 4 ms 10832 KB n=100
11 Correct 3 ms 10896 KB n=100
12 Correct 2 ms 10832 KB n=100
13 Correct 3 ms 10832 KB n=100
14 Correct 2 ms 10832 KB n=100
15 Correct 2 ms 10832 KB n=100
16 Correct 2 ms 10832 KB n=100
17 Correct 3 ms 10832 KB n=100
18 Correct 2 ms 10832 KB n=100
19 Correct 2 ms 10832 KB n=100
20 Correct 2 ms 10832 KB n=100
21 Correct 3 ms 11004 KB n=100
22 Correct 2 ms 10832 KB n=100
23 Correct 3 ms 10832 KB n=100
24 Correct 3 ms 10832 KB n=100
25 Correct 2 ms 10832 KB n=100
26 Correct 2 ms 10832 KB n=12
27 Correct 3 ms 10832 KB n=100
28 Correct 3 ms 10832 KB n=500
29 Correct 14 ms 10920 KB n=500
30 Correct 12 ms 10920 KB n=500
31 Correct 13 ms 10832 KB n=500
32 Correct 3 ms 10832 KB n=500
33 Correct 12 ms 10832 KB n=500
34 Correct 2 ms 10832 KB n=500
35 Correct 13 ms 10932 KB n=500
36 Correct 137 ms 11004 KB n=500
37 Correct 143 ms 11000 KB n=500
38 Correct 144 ms 10832 KB n=500
39 Correct 29 ms 10832 KB n=500
40 Correct 22 ms 10832 KB n=500
41 Correct 22 ms 10832 KB n=500
42 Correct 70 ms 10904 KB n=500
43 Correct 70 ms 10832 KB n=500
44 Correct 74 ms 10832 KB n=500
45 Correct 3 ms 10832 KB n=500
46 Correct 14 ms 10832 KB n=500
47 Correct 12 ms 10832 KB n=500
48 Correct 3 ms 10832 KB n=500
49 Correct 11 ms 10832 KB n=500
50 Correct 20 ms 10832 KB n=500
51 Correct 20 ms 11000 KB n=500
52 Correct 22 ms 10932 KB n=500
53 Correct 22 ms 10832 KB n=500
54 Correct 10 ms 10832 KB n=500
55 Correct 4 ms 10832 KB n=278
56 Correct 71 ms 10832 KB n=500
57 Correct 77 ms 10832 KB n=500
58 Correct 64 ms 10832 KB n=500
# Verdict Execution time Memory Grader output
1 Correct 2 ms 10832 KB n=5
2 Correct 2 ms 11000 KB n=100
3 Correct 2 ms 10832 KB n=100
4 Correct 2 ms 10832 KB n=100
5 Correct 2 ms 10832 KB n=100
6 Correct 3 ms 10832 KB n=100
7 Correct 4 ms 11000 KB n=100
8 Correct 2 ms 10832 KB n=100
9 Correct 3 ms 10832 KB n=100
10 Correct 4 ms 10832 KB n=100
11 Correct 3 ms 10896 KB n=100
12 Correct 2 ms 10832 KB n=100
13 Correct 3 ms 10832 KB n=100
14 Correct 2 ms 10832 KB n=100
15 Correct 2 ms 10832 KB n=100
16 Correct 2 ms 10832 KB n=100
17 Correct 3 ms 10832 KB n=100
18 Correct 2 ms 10832 KB n=100
19 Correct 2 ms 10832 KB n=100
20 Correct 2 ms 10832 KB n=100
21 Correct 3 ms 11004 KB n=100
22 Correct 2 ms 10832 KB n=100
23 Correct 3 ms 10832 KB n=100
24 Correct 3 ms 10832 KB n=100
25 Correct 2 ms 10832 KB n=100
26 Correct 2 ms 10832 KB n=12
27 Correct 3 ms 10832 KB n=100
28 Correct 3 ms 10832 KB n=500
29 Correct 14 ms 10920 KB n=500
30 Correct 12 ms 10920 KB n=500
31 Correct 13 ms 10832 KB n=500
32 Correct 3 ms 10832 KB n=500
33 Correct 12 ms 10832 KB n=500
34 Correct 2 ms 10832 KB n=500
35 Correct 13 ms 10932 KB n=500
36 Correct 137 ms 11004 KB n=500
37 Correct 143 ms 11000 KB n=500
38 Correct 144 ms 10832 KB n=500
39 Correct 29 ms 10832 KB n=500
40 Correct 22 ms 10832 KB n=500
41 Correct 22 ms 10832 KB n=500
42 Correct 70 ms 10904 KB n=500
43 Correct 70 ms 10832 KB n=500
44 Correct 74 ms 10832 KB n=500
45 Correct 3 ms 10832 KB n=500
46 Correct 14 ms 10832 KB n=500
47 Correct 12 ms 10832 KB n=500
48 Correct 3 ms 10832 KB n=500
49 Correct 11 ms 10832 KB n=500
50 Correct 20 ms 10832 KB n=500
51 Correct 20 ms 11000 KB n=500
52 Correct 22 ms 10932 KB n=500
53 Correct 22 ms 10832 KB n=500
54 Correct 10 ms 10832 KB n=500
55 Correct 4 ms 10832 KB n=278
56 Correct 71 ms 10832 KB n=500
57 Correct 77 ms 10832 KB n=500
58 Correct 64 ms 10832 KB n=500
59 Correct 11 ms 10832 KB n=2000
60 Correct 689 ms 11080 KB n=2000
61 Correct 690 ms 10832 KB n=2000
62 Correct 466 ms 10988 KB n=2000
63 Correct 20 ms 10832 KB n=2000
64 Correct 592 ms 10988 KB n=2000
65 Correct 5 ms 10832 KB n=2000
66 Correct 766 ms 11024 KB n=2000
67 Correct 37 ms 10832 KB n=2000
68 Correct 654 ms 11008 KB n=2000
69 Execution timed out 4035 ms 10964 KB Time limit exceeded
70 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 10832 KB n=5
2 Correct 2 ms 11000 KB n=100
3 Correct 2 ms 10832 KB n=100
4 Correct 2 ms 10832 KB n=100
5 Correct 2 ms 10832 KB n=100
6 Correct 3 ms 10832 KB n=100
7 Correct 4 ms 11000 KB n=100
8 Correct 2 ms 10832 KB n=100
9 Correct 3 ms 10832 KB n=100
10 Correct 4 ms 10832 KB n=100
11 Correct 3 ms 10896 KB n=100
12 Correct 2 ms 10832 KB n=100
13 Correct 3 ms 10832 KB n=100
14 Correct 2 ms 10832 KB n=100
15 Correct 2 ms 10832 KB n=100
16 Correct 2 ms 10832 KB n=100
17 Correct 3 ms 10832 KB n=100
18 Correct 2 ms 10832 KB n=100
19 Correct 2 ms 10832 KB n=100
20 Correct 2 ms 10832 KB n=100
21 Correct 3 ms 11004 KB n=100
22 Correct 2 ms 10832 KB n=100
23 Correct 3 ms 10832 KB n=100
24 Correct 3 ms 10832 KB n=100
25 Correct 2 ms 10832 KB n=100
26 Correct 2 ms 10832 KB n=12
27 Correct 3 ms 10832 KB n=100
28 Correct 3 ms 10832 KB n=500
29 Correct 14 ms 10920 KB n=500
30 Correct 12 ms 10920 KB n=500
31 Correct 13 ms 10832 KB n=500
32 Correct 3 ms 10832 KB n=500
33 Correct 12 ms 10832 KB n=500
34 Correct 2 ms 10832 KB n=500
35 Correct 13 ms 10932 KB n=500
36 Correct 137 ms 11004 KB n=500
37 Correct 143 ms 11000 KB n=500
38 Correct 144 ms 10832 KB n=500
39 Correct 29 ms 10832 KB n=500
40 Correct 22 ms 10832 KB n=500
41 Correct 22 ms 10832 KB n=500
42 Correct 70 ms 10904 KB n=500
43 Correct 70 ms 10832 KB n=500
44 Correct 74 ms 10832 KB n=500
45 Correct 3 ms 10832 KB n=500
46 Correct 14 ms 10832 KB n=500
47 Correct 12 ms 10832 KB n=500
48 Correct 3 ms 10832 KB n=500
49 Correct 11 ms 10832 KB n=500
50 Correct 20 ms 10832 KB n=500
51 Correct 20 ms 11000 KB n=500
52 Correct 22 ms 10932 KB n=500
53 Correct 22 ms 10832 KB n=500
54 Correct 10 ms 10832 KB n=500
55 Correct 4 ms 10832 KB n=278
56 Correct 71 ms 10832 KB n=500
57 Correct 77 ms 10832 KB n=500
58 Correct 64 ms 10832 KB n=500
59 Correct 11 ms 10832 KB n=2000
60 Correct 689 ms 11080 KB n=2000
61 Correct 690 ms 10832 KB n=2000
62 Correct 466 ms 10988 KB n=2000
63 Correct 20 ms 10832 KB n=2000
64 Correct 592 ms 10988 KB n=2000
65 Correct 5 ms 10832 KB n=2000
66 Correct 766 ms 11024 KB n=2000
67 Correct 37 ms 10832 KB n=2000
68 Correct 654 ms 11008 KB n=2000
69 Execution timed out 4035 ms 10964 KB Time limit exceeded
70 Halted 0 ms 0 KB -