Submission #342301

# Submission time Handle Problem Language Result Execution time Memory
342301 2021-01-01T19:04:24 Z ogibogi2004 Birthday gift (IZhO18_treearray) C++14
100 / 100
1903 ms 97644 KB
#include<bits/stdc++.h>
using namespace std;
const int MAXN=2e5+6;
set<int>s1[MAXN];
set<int>s2[MAXN];
vector<int>g[MAXN];
int a[MAXN],n,m,q;
int dp[MAXN][20],depth[MAXN];
void dfs(int u,int p)
{
	dp[u][0]=p;
	depth[u]=depth[p]+1;
	for(auto v:g[u])
	{
		if(v==p)continue;
		dfs(v,u);
	}
}
void precompute()
{
	for(int s=1;s<20;s++)
	{
		for(int i=1;i<=n;i++)
		{
			dp[i][s]=dp[dp[i][s-1]][s-1];
		}
	}
}
int lca(int x,int y)
{
	if(depth[x]<depth[y])swap(x,y);
	int diff=depth[x]-depth[y];
	for(int i=0;i<20;i++)
	{
		if(diff&(1<<i))
		{
			x=dp[x][i];
		}
	}
	if(x==y)return x;
	for(int i=19;i>=0;i--)
	{
		if(dp[x][i]!=dp[y][i])
		{
			x=dp[x][i];
			y=dp[y][i];
		}
	}
	return dp[x][0];
}
int main()
{
	cin>>n>>m>>q;
	for(int i=1;i<n;i++)
	{
		int u,v;
		cin>>u>>v;
		g[u].push_back(v);
		g[v].push_back(u);
	}
	dfs(1,0);
	precompute();
	for(int i=1;i<=n;i++)
	{
		s1[i].insert(MAXN);
		s2[i].insert(MAXN);
	}
	for(int i=1;i<=m;i++)
	{
		cin>>a[i];
		s1[a[i]].insert(i);
	}
	for(int i=1;i<m;i++)
	{
		s2[lca(a[i],a[i+1])].insert(i);
	}
	for(int i=1;i<=q;i++)
	{
		int t;
		cin>>t;
		if(t==1)
		{
			int v,pos;
			cin>>pos>>v;
			if(pos!=m)
			{
				s2[lca(a[pos],a[pos+1])].erase(pos);
			}
			if(pos!=1)
			{
				s2[lca(a[pos-1],a[pos])].erase(pos-1);
			}
			s1[a[pos]].erase(pos);
			a[pos]=v;
			if(pos!=m)
			{
				s2[lca(a[pos],a[pos+1])].insert(pos);
			}
			if(pos!=1)
			{
				s2[lca(a[pos-1],a[pos])].insert(pos-1);
			}
			s1[a[pos]].insert(pos);
		}
		else
		{
			int l,r,v;
			cin>>l>>r>>v;
			int xd=(*s1[v].lower_bound(l));
			if(xd<=r)
			{
				cout<<xd<<" "<<xd<<endl;
				continue;
			}
			xd=(*s2[v].lower_bound(l));
			if(xd<r)
			{
				cout<<xd<<" "<<xd+1<<endl;
				continue;
			}
			cout<<"-1 -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 16 ms 23916 KB n=5
2 Correct 16 ms 23788 KB n=100
3 Correct 16 ms 23788 KB n=100
4 Correct 16 ms 23788 KB n=100
5 Correct 16 ms 23788 KB n=100
6 Correct 17 ms 23788 KB n=100
7 Correct 17 ms 23788 KB n=100
8 Correct 16 ms 23788 KB n=100
9 Correct 16 ms 23788 KB n=100
10 Correct 16 ms 23788 KB n=100
11 Correct 16 ms 23788 KB n=100
12 Correct 16 ms 23788 KB n=100
13 Correct 17 ms 23788 KB n=100
14 Correct 19 ms 23788 KB n=100
15 Correct 19 ms 23916 KB n=100
16 Correct 16 ms 23788 KB n=100
17 Correct 17 ms 24064 KB n=100
18 Correct 16 ms 23916 KB n=100
19 Correct 16 ms 23916 KB n=100
20 Correct 16 ms 23788 KB n=100
21 Correct 17 ms 23788 KB n=100
22 Correct 17 ms 23916 KB n=100
23 Correct 16 ms 23788 KB n=100
24 Correct 17 ms 23788 KB n=100
25 Correct 16 ms 23788 KB n=100
26 Correct 16 ms 23788 KB n=12
27 Correct 17 ms 23788 KB n=100
# Verdict Execution time Memory Grader output
1 Correct 16 ms 23916 KB n=5
2 Correct 16 ms 23788 KB n=100
3 Correct 16 ms 23788 KB n=100
4 Correct 16 ms 23788 KB n=100
5 Correct 16 ms 23788 KB n=100
6 Correct 17 ms 23788 KB n=100
7 Correct 17 ms 23788 KB n=100
8 Correct 16 ms 23788 KB n=100
9 Correct 16 ms 23788 KB n=100
10 Correct 16 ms 23788 KB n=100
11 Correct 16 ms 23788 KB n=100
12 Correct 16 ms 23788 KB n=100
13 Correct 17 ms 23788 KB n=100
14 Correct 19 ms 23788 KB n=100
15 Correct 19 ms 23916 KB n=100
16 Correct 16 ms 23788 KB n=100
17 Correct 17 ms 24064 KB n=100
18 Correct 16 ms 23916 KB n=100
19 Correct 16 ms 23916 KB n=100
20 Correct 16 ms 23788 KB n=100
21 Correct 17 ms 23788 KB n=100
22 Correct 17 ms 23916 KB n=100
23 Correct 16 ms 23788 KB n=100
24 Correct 17 ms 23788 KB n=100
25 Correct 16 ms 23788 KB n=100
26 Correct 16 ms 23788 KB n=12
27 Correct 17 ms 23788 KB n=100
28 Correct 18 ms 24044 KB n=500
29 Correct 18 ms 24044 KB n=500
30 Correct 18 ms 24044 KB n=500
31 Correct 18 ms 24064 KB n=500
32 Correct 18 ms 24044 KB n=500
33 Correct 18 ms 24044 KB n=500
34 Correct 18 ms 24172 KB n=500
35 Correct 18 ms 24044 KB n=500
36 Correct 18 ms 23916 KB n=500
37 Correct 19 ms 23916 KB n=500
38 Correct 19 ms 23916 KB n=500
39 Correct 18 ms 24044 KB n=500
40 Correct 18 ms 24044 KB n=500
41 Correct 18 ms 24044 KB n=500
42 Correct 18 ms 23916 KB n=500
43 Correct 18 ms 23916 KB n=500
44 Correct 18 ms 23916 KB n=500
45 Correct 19 ms 24044 KB n=500
46 Correct 21 ms 24044 KB n=500
47 Correct 19 ms 24044 KB n=500
48 Correct 18 ms 24044 KB n=500
49 Correct 18 ms 24044 KB n=500
50 Correct 18 ms 24044 KB n=500
51 Correct 19 ms 24044 KB n=500
52 Correct 18 ms 24044 KB n=500
53 Correct 18 ms 24044 KB n=500
54 Correct 18 ms 24044 KB n=500
55 Correct 17 ms 23948 KB n=278
56 Correct 18 ms 24044 KB n=500
57 Correct 18 ms 24044 KB n=500
58 Correct 19 ms 24044 KB n=500
# Verdict Execution time Memory Grader output
1 Correct 16 ms 23916 KB n=5
2 Correct 16 ms 23788 KB n=100
3 Correct 16 ms 23788 KB n=100
4 Correct 16 ms 23788 KB n=100
5 Correct 16 ms 23788 KB n=100
6 Correct 17 ms 23788 KB n=100
7 Correct 17 ms 23788 KB n=100
8 Correct 16 ms 23788 KB n=100
9 Correct 16 ms 23788 KB n=100
10 Correct 16 ms 23788 KB n=100
11 Correct 16 ms 23788 KB n=100
12 Correct 16 ms 23788 KB n=100
13 Correct 17 ms 23788 KB n=100
14 Correct 19 ms 23788 KB n=100
15 Correct 19 ms 23916 KB n=100
16 Correct 16 ms 23788 KB n=100
17 Correct 17 ms 24064 KB n=100
18 Correct 16 ms 23916 KB n=100
19 Correct 16 ms 23916 KB n=100
20 Correct 16 ms 23788 KB n=100
21 Correct 17 ms 23788 KB n=100
22 Correct 17 ms 23916 KB n=100
23 Correct 16 ms 23788 KB n=100
24 Correct 17 ms 23788 KB n=100
25 Correct 16 ms 23788 KB n=100
26 Correct 16 ms 23788 KB n=12
27 Correct 17 ms 23788 KB n=100
28 Correct 18 ms 24044 KB n=500
29 Correct 18 ms 24044 KB n=500
30 Correct 18 ms 24044 KB n=500
31 Correct 18 ms 24064 KB n=500
32 Correct 18 ms 24044 KB n=500
33 Correct 18 ms 24044 KB n=500
34 Correct 18 ms 24172 KB n=500
35 Correct 18 ms 24044 KB n=500
36 Correct 18 ms 23916 KB n=500
37 Correct 19 ms 23916 KB n=500
38 Correct 19 ms 23916 KB n=500
39 Correct 18 ms 24044 KB n=500
40 Correct 18 ms 24044 KB n=500
41 Correct 18 ms 24044 KB n=500
42 Correct 18 ms 23916 KB n=500
43 Correct 18 ms 23916 KB n=500
44 Correct 18 ms 23916 KB n=500
45 Correct 19 ms 24044 KB n=500
46 Correct 21 ms 24044 KB n=500
47 Correct 19 ms 24044 KB n=500
48 Correct 18 ms 24044 KB n=500
49 Correct 18 ms 24044 KB n=500
50 Correct 18 ms 24044 KB n=500
51 Correct 19 ms 24044 KB n=500
52 Correct 18 ms 24044 KB n=500
53 Correct 18 ms 24044 KB n=500
54 Correct 18 ms 24044 KB n=500
55 Correct 17 ms 23948 KB n=278
56 Correct 18 ms 24044 KB n=500
57 Correct 18 ms 24044 KB n=500
58 Correct 19 ms 24044 KB n=500
59 Correct 24 ms 24556 KB n=2000
60 Correct 24 ms 24556 KB n=2000
61 Correct 24 ms 24556 KB n=2000
62 Correct 25 ms 24556 KB n=2000
63 Correct 24 ms 24556 KB n=2000
64 Correct 25 ms 24556 KB n=2000
65 Correct 26 ms 24556 KB n=2000
66 Correct 24 ms 24556 KB n=2000
67 Correct 25 ms 24556 KB n=2000
68 Correct 24 ms 24556 KB n=2000
69 Correct 26 ms 24556 KB n=2000
70 Correct 26 ms 24556 KB n=2000
71 Correct 26 ms 24556 KB n=2000
72 Correct 25 ms 24576 KB n=2000
73 Correct 25 ms 24556 KB n=2000
74 Correct 23 ms 24428 KB n=1844
75 Correct 25 ms 24556 KB n=2000
76 Correct 25 ms 24556 KB n=2000
77 Correct 25 ms 24556 KB n=2000
78 Correct 25 ms 24556 KB n=2000
79 Correct 24 ms 24556 KB n=2000
80 Correct 24 ms 24684 KB n=2000
81 Correct 24 ms 24556 KB n=2000
82 Correct 24 ms 24556 KB n=2000
83 Correct 24 ms 24556 KB n=2000
84 Correct 25 ms 24684 KB n=2000
85 Correct 25 ms 24556 KB n=2000
86 Correct 25 ms 24556 KB n=2000
87 Correct 24 ms 24556 KB n=2000
88 Correct 24 ms 24556 KB n=2000
89 Correct 24 ms 24556 KB n=2000
90 Correct 24 ms 24556 KB n=2000
91 Correct 26 ms 24556 KB n=2000
# Verdict Execution time Memory Grader output
1 Correct 16 ms 23916 KB n=5
2 Correct 16 ms 23788 KB n=100
3 Correct 16 ms 23788 KB n=100
4 Correct 16 ms 23788 KB n=100
5 Correct 16 ms 23788 KB n=100
6 Correct 17 ms 23788 KB n=100
7 Correct 17 ms 23788 KB n=100
8 Correct 16 ms 23788 KB n=100
9 Correct 16 ms 23788 KB n=100
10 Correct 16 ms 23788 KB n=100
11 Correct 16 ms 23788 KB n=100
12 Correct 16 ms 23788 KB n=100
13 Correct 17 ms 23788 KB n=100
14 Correct 19 ms 23788 KB n=100
15 Correct 19 ms 23916 KB n=100
16 Correct 16 ms 23788 KB n=100
17 Correct 17 ms 24064 KB n=100
18 Correct 16 ms 23916 KB n=100
19 Correct 16 ms 23916 KB n=100
20 Correct 16 ms 23788 KB n=100
21 Correct 17 ms 23788 KB n=100
22 Correct 17 ms 23916 KB n=100
23 Correct 16 ms 23788 KB n=100
24 Correct 17 ms 23788 KB n=100
25 Correct 16 ms 23788 KB n=100
26 Correct 16 ms 23788 KB n=12
27 Correct 17 ms 23788 KB n=100
28 Correct 18 ms 24044 KB n=500
29 Correct 18 ms 24044 KB n=500
30 Correct 18 ms 24044 KB n=500
31 Correct 18 ms 24064 KB n=500
32 Correct 18 ms 24044 KB n=500
33 Correct 18 ms 24044 KB n=500
34 Correct 18 ms 24172 KB n=500
35 Correct 18 ms 24044 KB n=500
36 Correct 18 ms 23916 KB n=500
37 Correct 19 ms 23916 KB n=500
38 Correct 19 ms 23916 KB n=500
39 Correct 18 ms 24044 KB n=500
40 Correct 18 ms 24044 KB n=500
41 Correct 18 ms 24044 KB n=500
42 Correct 18 ms 23916 KB n=500
43 Correct 18 ms 23916 KB n=500
44 Correct 18 ms 23916 KB n=500
45 Correct 19 ms 24044 KB n=500
46 Correct 21 ms 24044 KB n=500
47 Correct 19 ms 24044 KB n=500
48 Correct 18 ms 24044 KB n=500
49 Correct 18 ms 24044 KB n=500
50 Correct 18 ms 24044 KB n=500
51 Correct 19 ms 24044 KB n=500
52 Correct 18 ms 24044 KB n=500
53 Correct 18 ms 24044 KB n=500
54 Correct 18 ms 24044 KB n=500
55 Correct 17 ms 23948 KB n=278
56 Correct 18 ms 24044 KB n=500
57 Correct 18 ms 24044 KB n=500
58 Correct 19 ms 24044 KB n=500
59 Correct 24 ms 24556 KB n=2000
60 Correct 24 ms 24556 KB n=2000
61 Correct 24 ms 24556 KB n=2000
62 Correct 25 ms 24556 KB n=2000
63 Correct 24 ms 24556 KB n=2000
64 Correct 25 ms 24556 KB n=2000
65 Correct 26 ms 24556 KB n=2000
66 Correct 24 ms 24556 KB n=2000
67 Correct 25 ms 24556 KB n=2000
68 Correct 24 ms 24556 KB n=2000
69 Correct 26 ms 24556 KB n=2000
70 Correct 26 ms 24556 KB n=2000
71 Correct 26 ms 24556 KB n=2000
72 Correct 25 ms 24576 KB n=2000
73 Correct 25 ms 24556 KB n=2000
74 Correct 23 ms 24428 KB n=1844
75 Correct 25 ms 24556 KB n=2000
76 Correct 25 ms 24556 KB n=2000
77 Correct 25 ms 24556 KB n=2000
78 Correct 25 ms 24556 KB n=2000
79 Correct 24 ms 24556 KB n=2000
80 Correct 24 ms 24684 KB n=2000
81 Correct 24 ms 24556 KB n=2000
82 Correct 24 ms 24556 KB n=2000
83 Correct 24 ms 24556 KB n=2000
84 Correct 25 ms 24684 KB n=2000
85 Correct 25 ms 24556 KB n=2000
86 Correct 25 ms 24556 KB n=2000
87 Correct 24 ms 24556 KB n=2000
88 Correct 24 ms 24556 KB n=2000
89 Correct 24 ms 24556 KB n=2000
90 Correct 24 ms 24556 KB n=2000
91 Correct 26 ms 24556 KB n=2000
92 Correct 1401 ms 89232 KB n=200000
93 Correct 1801 ms 93092 KB n=200000
94 Correct 1750 ms 96452 KB n=200000
95 Correct 1402 ms 88800 KB n=200000
96 Correct 1327 ms 88956 KB n=200000
97 Correct 1816 ms 92140 KB n=200000
98 Correct 1352 ms 88928 KB n=200000
99 Correct 1611 ms 88556 KB n=200000
100 Correct 1366 ms 89060 KB n=200000
101 Correct 1795 ms 97644 KB n=200000
102 Correct 1234 ms 90092 KB n=200000
103 Correct 1239 ms 89964 KB n=200000
104 Correct 1233 ms 89964 KB n=200000
105 Correct 1268 ms 89964 KB n=200000
106 Correct 1287 ms 89740 KB n=200000
107 Correct 1266 ms 89964 KB n=200000
108 Correct 1514 ms 88764 KB n=200000
109 Correct 1514 ms 88940 KB n=200000
110 Correct 1541 ms 88572 KB n=200000
111 Correct 1336 ms 88544 KB n=200000
112 Correct 1759 ms 96656 KB n=200000
113 Correct 1800 ms 92068 KB n=200000
114 Correct 1387 ms 88164 KB n=200000
115 Correct 1903 ms 89604 KB n=200000
116 Correct 1355 ms 88608 KB n=200000
117 Correct 1743 ms 96668 KB n=200000
118 Correct 1810 ms 90532 KB n=200000
119 Correct 1348 ms 88768 KB n=200000
120 Correct 1675 ms 97132 KB n=200000
121 Correct 1692 ms 97004 KB n=200000
122 Correct 1672 ms 97412 KB n=200000
123 Correct 1273 ms 89388 KB n=200000
124 Correct 444 ms 40300 KB n=25264