Submission #90585

# Submission time Handle Problem Language Result Execution time Memory
90585 2018-12-22T15:25:38 Z mrtsima22 Birthday gift (IZhO18_treearray) C++17
30 / 100
4000 ms 3560 KB
#include <iostream>
#include <vector>
using namespace std;
int n,k,q,t_out[100003],fin,p[100003][22],deep[100003];
vector<int>a[100003];
int ba[100003],t_in[100004],T,x;
bool is_it(int a,int b)
{
	return (t_in[a]<=t_in[b])&&(t_out[b]<=t_out[a]);
}
void go(int s,int parent,int DEEP)
{
	t_in[s]=++T;
	p[s][1]=parent;
	deep[s]=DEEP;
	for(int i=0;i<(int)a[s].size();i++)
	{
		if(a[s][i]==parent)continue;
		go(a[s][i],s,DEEP+1);
	}
	t_out[s]=++T;
}
void mshobelize(int Par,int sad)
{
	for(int j=2;j<=19;j++)
	{
		p[sad][j]=p[p[sad][j-1]][j-1];
	}
	for(int i=0;i<(int)a[sad].size();i++)
	{
		if(a[sad][i]!=Par)
		{
			mshobelize(sad,a[sad][i]);
		}
	}
}
int lca(int a,int b)
{
	int A=deep[a];
	int B=deep[b];
	if(A>B)
	{
		swap(a,b);
		swap(A,B);
	}
	for(int i=19;i>=0;i--)
	{
		if(deep[p[b][i]]>=deep[a])
		{
			b=p[b][i];
		}
	}
	if(a==b)
	{
		return a;
	}
    for (int i = 19; i >= 0; i--) 
	{
        if (p[b][i] != p[a][i]) 
		{
            b = p[b][i];       
            a = p[a][i];
        }
    }
    return p[a][1];
}
int u,v,tp;
int main() {ios_base::sync_with_stdio(false);
cin>>n>>k>>q;
for(int i=0;i<n-1;i++)
{
	cin>>v>>u;
	a[v].push_back(u);
	a[u].push_back(v);
}
for(int i=1;i<=k;i++)
{
	cin>>ba[i];
}
go(1,0,0);
mshobelize(1,1);
t_out[0]=999999999;
while(q--)
{
	cin>>tp;
	if(tp==1)
	{
		cin>>u>>v;
		ba[u]=v;
	}
	else if(tp==2){
	cin>>u>>v>>x;
	fin=0;
		for(int L=u;!fin&&L<=v;L++)
		{
			int c=ba[L];
			int c1=c;
			for(int R=L;!fin&&R<=v;R++)
			{
				while(!is_it(c,ba[R]))c=p[c][1];
				c1=lca(c1,ba[R]);
//				if(c1!=c)
//					cout<<6/0<<endl;
				if(!is_it(x,c))break;
				if(x==c)
				{
					fin=1;
					cout<<L<<" "<<R<<endl;
				}
			}
		}
		if(!fin)
		{
			cout<<"-1 -1"<<endl;
		}
	}
	
}
 
 
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 4 ms 2680 KB n=5
2 Correct 4 ms 2828 KB n=100
3 Correct 4 ms 2832 KB n=100
4 Correct 4 ms 2832 KB n=100
5 Correct 4 ms 2832 KB n=100
6 Correct 3 ms 2832 KB n=100
7 Correct 4 ms 2832 KB n=100
8 Correct 4 ms 2872 KB n=100
9 Correct 4 ms 2916 KB n=100
10 Correct 4 ms 2944 KB n=100
11 Correct 4 ms 2944 KB n=100
12 Correct 4 ms 2944 KB n=100
13 Correct 4 ms 2944 KB n=100
14 Correct 4 ms 2944 KB n=100
15 Correct 4 ms 2944 KB n=100
16 Correct 4 ms 2944 KB n=100
17 Correct 4 ms 2944 KB n=100
18 Correct 4 ms 2944 KB n=100
19 Correct 4 ms 2944 KB n=100
20 Correct 4 ms 2944 KB n=100
21 Correct 4 ms 2944 KB n=100
22 Correct 4 ms 2960 KB n=100
23 Correct 4 ms 2960 KB n=100
24 Correct 4 ms 2960 KB n=100
25 Correct 4 ms 2960 KB n=100
26 Correct 4 ms 2960 KB n=12
27 Correct 4 ms 2960 KB n=100
# Verdict Execution time Memory Grader output
1 Correct 4 ms 2680 KB n=5
2 Correct 4 ms 2828 KB n=100
3 Correct 4 ms 2832 KB n=100
4 Correct 4 ms 2832 KB n=100
5 Correct 4 ms 2832 KB n=100
6 Correct 3 ms 2832 KB n=100
7 Correct 4 ms 2832 KB n=100
8 Correct 4 ms 2872 KB n=100
9 Correct 4 ms 2916 KB n=100
10 Correct 4 ms 2944 KB n=100
11 Correct 4 ms 2944 KB n=100
12 Correct 4 ms 2944 KB n=100
13 Correct 4 ms 2944 KB n=100
14 Correct 4 ms 2944 KB n=100
15 Correct 4 ms 2944 KB n=100
16 Correct 4 ms 2944 KB n=100
17 Correct 4 ms 2944 KB n=100
18 Correct 4 ms 2944 KB n=100
19 Correct 4 ms 2944 KB n=100
20 Correct 4 ms 2944 KB n=100
21 Correct 4 ms 2944 KB n=100
22 Correct 4 ms 2960 KB n=100
23 Correct 4 ms 2960 KB n=100
24 Correct 4 ms 2960 KB n=100
25 Correct 4 ms 2960 KB n=100
26 Correct 4 ms 2960 KB n=12
27 Correct 4 ms 2960 KB n=100
28 Correct 4 ms 2960 KB n=500
29 Correct 16 ms 3040 KB n=500
30 Correct 10 ms 3040 KB n=500
31 Correct 11 ms 3040 KB n=500
32 Correct 4 ms 3152 KB n=500
33 Correct 8 ms 3152 KB n=500
34 Correct 4 ms 3152 KB n=500
35 Correct 13 ms 3152 KB n=500
36 Correct 6 ms 3152 KB n=500
37 Correct 6 ms 3152 KB n=500
38 Correct 6 ms 3152 KB n=500
39 Correct 5 ms 3152 KB n=500
40 Correct 6 ms 3152 KB n=500
41 Correct 5 ms 3152 KB n=500
42 Correct 4 ms 3152 KB n=500
43 Correct 4 ms 3160 KB n=500
44 Correct 5 ms 3160 KB n=500
45 Correct 4 ms 3160 KB n=500
46 Correct 15 ms 3160 KB n=500
47 Correct 12 ms 3160 KB n=500
48 Correct 4 ms 3160 KB n=500
49 Correct 12 ms 3160 KB n=500
50 Correct 4 ms 3160 KB n=500
51 Correct 9 ms 3160 KB n=500
52 Correct 20 ms 3160 KB n=500
53 Correct 7 ms 3160 KB n=500
54 Correct 25 ms 3160 KB n=500
55 Correct 5 ms 3160 KB n=278
56 Correct 142 ms 3160 KB n=500
57 Correct 147 ms 3160 KB n=500
58 Correct 5 ms 3160 KB n=500
# Verdict Execution time Memory Grader output
1 Correct 4 ms 2680 KB n=5
2 Correct 4 ms 2828 KB n=100
3 Correct 4 ms 2832 KB n=100
4 Correct 4 ms 2832 KB n=100
5 Correct 4 ms 2832 KB n=100
6 Correct 3 ms 2832 KB n=100
7 Correct 4 ms 2832 KB n=100
8 Correct 4 ms 2872 KB n=100
9 Correct 4 ms 2916 KB n=100
10 Correct 4 ms 2944 KB n=100
11 Correct 4 ms 2944 KB n=100
12 Correct 4 ms 2944 KB n=100
13 Correct 4 ms 2944 KB n=100
14 Correct 4 ms 2944 KB n=100
15 Correct 4 ms 2944 KB n=100
16 Correct 4 ms 2944 KB n=100
17 Correct 4 ms 2944 KB n=100
18 Correct 4 ms 2944 KB n=100
19 Correct 4 ms 2944 KB n=100
20 Correct 4 ms 2944 KB n=100
21 Correct 4 ms 2944 KB n=100
22 Correct 4 ms 2960 KB n=100
23 Correct 4 ms 2960 KB n=100
24 Correct 4 ms 2960 KB n=100
25 Correct 4 ms 2960 KB n=100
26 Correct 4 ms 2960 KB n=12
27 Correct 4 ms 2960 KB n=100
28 Correct 4 ms 2960 KB n=500
29 Correct 16 ms 3040 KB n=500
30 Correct 10 ms 3040 KB n=500
31 Correct 11 ms 3040 KB n=500
32 Correct 4 ms 3152 KB n=500
33 Correct 8 ms 3152 KB n=500
34 Correct 4 ms 3152 KB n=500
35 Correct 13 ms 3152 KB n=500
36 Correct 6 ms 3152 KB n=500
37 Correct 6 ms 3152 KB n=500
38 Correct 6 ms 3152 KB n=500
39 Correct 5 ms 3152 KB n=500
40 Correct 6 ms 3152 KB n=500
41 Correct 5 ms 3152 KB n=500
42 Correct 4 ms 3152 KB n=500
43 Correct 4 ms 3160 KB n=500
44 Correct 5 ms 3160 KB n=500
45 Correct 4 ms 3160 KB n=500
46 Correct 15 ms 3160 KB n=500
47 Correct 12 ms 3160 KB n=500
48 Correct 4 ms 3160 KB n=500
49 Correct 12 ms 3160 KB n=500
50 Correct 4 ms 3160 KB n=500
51 Correct 9 ms 3160 KB n=500
52 Correct 20 ms 3160 KB n=500
53 Correct 7 ms 3160 KB n=500
54 Correct 25 ms 3160 KB n=500
55 Correct 5 ms 3160 KB n=278
56 Correct 142 ms 3160 KB n=500
57 Correct 147 ms 3160 KB n=500
58 Correct 5 ms 3160 KB n=500
59 Correct 7 ms 3180 KB n=2000
60 Correct 1189 ms 3436 KB n=2000
61 Correct 779 ms 3452 KB n=2000
62 Correct 212 ms 3560 KB n=2000
63 Correct 7 ms 3560 KB n=2000
64 Correct 438 ms 3560 KB n=2000
65 Correct 6 ms 3560 KB n=2000
66 Correct 1018 ms 3560 KB n=2000
67 Correct 7 ms 3560 KB n=2000
68 Correct 622 ms 3560 KB n=2000
69 Correct 42 ms 3560 KB n=2000
70 Correct 43 ms 3560 KB n=2000
71 Correct 42 ms 3560 KB n=2000
72 Correct 25 ms 3560 KB n=2000
73 Correct 26 ms 3560 KB n=2000
74 Correct 6 ms 3560 KB n=1844
75 Correct 26 ms 3560 KB n=2000
76 Correct 23 ms 3560 KB n=2000
77 Correct 24 ms 3560 KB n=2000
78 Correct 24 ms 3560 KB n=2000
79 Correct 7 ms 3560 KB n=2000
80 Correct 920 ms 3560 KB n=2000
81 Correct 409 ms 3560 KB n=2000
82 Correct 7 ms 3560 KB n=2000
83 Correct 812 ms 3560 KB n=2000
84 Correct 10 ms 3560 KB n=2000
85 Correct 284 ms 3560 KB n=2000
86 Correct 143 ms 3560 KB n=2000
87 Correct 11 ms 3560 KB n=2000
88 Execution timed out 4093 ms 3560 KB Time limit exceeded
89 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 2680 KB n=5
2 Correct 4 ms 2828 KB n=100
3 Correct 4 ms 2832 KB n=100
4 Correct 4 ms 2832 KB n=100
5 Correct 4 ms 2832 KB n=100
6 Correct 3 ms 2832 KB n=100
7 Correct 4 ms 2832 KB n=100
8 Correct 4 ms 2872 KB n=100
9 Correct 4 ms 2916 KB n=100
10 Correct 4 ms 2944 KB n=100
11 Correct 4 ms 2944 KB n=100
12 Correct 4 ms 2944 KB n=100
13 Correct 4 ms 2944 KB n=100
14 Correct 4 ms 2944 KB n=100
15 Correct 4 ms 2944 KB n=100
16 Correct 4 ms 2944 KB n=100
17 Correct 4 ms 2944 KB n=100
18 Correct 4 ms 2944 KB n=100
19 Correct 4 ms 2944 KB n=100
20 Correct 4 ms 2944 KB n=100
21 Correct 4 ms 2944 KB n=100
22 Correct 4 ms 2960 KB n=100
23 Correct 4 ms 2960 KB n=100
24 Correct 4 ms 2960 KB n=100
25 Correct 4 ms 2960 KB n=100
26 Correct 4 ms 2960 KB n=12
27 Correct 4 ms 2960 KB n=100
28 Correct 4 ms 2960 KB n=500
29 Correct 16 ms 3040 KB n=500
30 Correct 10 ms 3040 KB n=500
31 Correct 11 ms 3040 KB n=500
32 Correct 4 ms 3152 KB n=500
33 Correct 8 ms 3152 KB n=500
34 Correct 4 ms 3152 KB n=500
35 Correct 13 ms 3152 KB n=500
36 Correct 6 ms 3152 KB n=500
37 Correct 6 ms 3152 KB n=500
38 Correct 6 ms 3152 KB n=500
39 Correct 5 ms 3152 KB n=500
40 Correct 6 ms 3152 KB n=500
41 Correct 5 ms 3152 KB n=500
42 Correct 4 ms 3152 KB n=500
43 Correct 4 ms 3160 KB n=500
44 Correct 5 ms 3160 KB n=500
45 Correct 4 ms 3160 KB n=500
46 Correct 15 ms 3160 KB n=500
47 Correct 12 ms 3160 KB n=500
48 Correct 4 ms 3160 KB n=500
49 Correct 12 ms 3160 KB n=500
50 Correct 4 ms 3160 KB n=500
51 Correct 9 ms 3160 KB n=500
52 Correct 20 ms 3160 KB n=500
53 Correct 7 ms 3160 KB n=500
54 Correct 25 ms 3160 KB n=500
55 Correct 5 ms 3160 KB n=278
56 Correct 142 ms 3160 KB n=500
57 Correct 147 ms 3160 KB n=500
58 Correct 5 ms 3160 KB n=500
59 Correct 7 ms 3180 KB n=2000
60 Correct 1189 ms 3436 KB n=2000
61 Correct 779 ms 3452 KB n=2000
62 Correct 212 ms 3560 KB n=2000
63 Correct 7 ms 3560 KB n=2000
64 Correct 438 ms 3560 KB n=2000
65 Correct 6 ms 3560 KB n=2000
66 Correct 1018 ms 3560 KB n=2000
67 Correct 7 ms 3560 KB n=2000
68 Correct 622 ms 3560 KB n=2000
69 Correct 42 ms 3560 KB n=2000
70 Correct 43 ms 3560 KB n=2000
71 Correct 42 ms 3560 KB n=2000
72 Correct 25 ms 3560 KB n=2000
73 Correct 26 ms 3560 KB n=2000
74 Correct 6 ms 3560 KB n=1844
75 Correct 26 ms 3560 KB n=2000
76 Correct 23 ms 3560 KB n=2000
77 Correct 24 ms 3560 KB n=2000
78 Correct 24 ms 3560 KB n=2000
79 Correct 7 ms 3560 KB n=2000
80 Correct 920 ms 3560 KB n=2000
81 Correct 409 ms 3560 KB n=2000
82 Correct 7 ms 3560 KB n=2000
83 Correct 812 ms 3560 KB n=2000
84 Correct 10 ms 3560 KB n=2000
85 Correct 284 ms 3560 KB n=2000
86 Correct 143 ms 3560 KB n=2000
87 Correct 11 ms 3560 KB n=2000
88 Execution timed out 4093 ms 3560 KB Time limit exceeded
89 Halted 0 ms 0 KB -