Submission #245584

# Submission time Handle Problem Language Result Execution time Memory
245584 2020-07-06T20:19:41 Z Yera Birthday gift (IZhO18_treearray) C++17
56 / 100
175 ms 136032 KB
// In The Name Of God
//#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <iostream>
#include <iomanip>
#include <fstream>
#include <vector>
#include <set>
#include <map>
#include <cstring>
#include <string>
#include <bitset>
#include <cmath>
#include <cassert>
#include <ctime>
#include <algorithm>
#include <sstream>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <cstdlib>
#include <cstdio>
#include <iterator>
#include <functional>
#include <unordered_set>
#include <unordered_map>
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
 
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define sagyndym_seni ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
 
const ll N = 2e5+5, p1 = 911382323, p2 = 972663749, INF = 1e9+123;
 
inline int read(){
	char c = getchar_unlocked();
	bool minus = 0;
	while (c < '0' || '9' < c){
		if(c == '-'){ minus = 1;}
		c = getchar_unlocked();
		if(c == '-'){ minus = 1;}
	}
	int res = 0;
	while ('0' <= c && c <= '9') {
		res = (res << 3) + (res << 1) + c - '0';
		c = getchar_unlocked();
	}
	if(minus){ res = (~res) + 1;}
	return res;
}
 
int n, m, q, tick = 0;
int depth[N], pos[N], LOG[N], tin[N], tout[N];
pair<int, int> st[N][30];
vector<int> vec, g[N];
vector<pair<int, int>> order;
 
void dfs(int v, int p){
	order.pb({depth[v], v});
	pos[v] = sz(order)-1;
 
	tin[v] = tick++;
	for(auto to : g[v]){
		if(to == p){ continue;}
		depth[to] = depth[v] + 1;
		dfs(to, v);
		order.pb({depth[v], v});
	}
	tout[v] = tick++;
}
 
void precalc(){
	LOG[1] = 0;
	for(int i = 2; i < N; i++){
		LOG[i] = LOG[i >> 1] + 1;
	}
	for(int i = 0; i < sz(order); i++){
		st[i][0] = order[i];
	}
	for(int j = 1; j < 30; j++){
		for(int i = 0; i + (1 << j) < sz(order); i++){
			st[i][j] = min(st[i][j-1], st[i + (1 << (j-1))][j-1]);
		}
	}
}
 
int mn(int l, int r){
	if(r < l){ swap(l, r);}
	int j = LOG[r - l + 1];
	pair<int, int> res = min(st[l][j], st[r - (1 << j) + 1][j]);
	return res.s;
}
 
bool isChild(int v, int p){
	return tin[p] <= tin[v] && tout[v] <= tout[p];
}
 
int main(){
	n = read(); m = read(); q = read();
	vec.resize(m);
	for(int i = 1; i < n; i++){
		int v = read()-1, u = read()-1;
		g[v].pb(u);
		g[u].pb(v);
	}
	for(int i = 0; i < m; i++){
		vec[i] = read()-1;
	}
	dfs(0, 0);
	precalc();
	while(q--){
		int tp = read();
		if(tp == 1){
			int pos = read()-1, v = read()-1;
			vec[pos] = v;
		}else{
			int left = read()-1, right = read()-1, p = read()-1;
			int ansL = -2, ansR = -2;
			for(int i = left; i <= right; i++){
				if(i < right){
					if(isChild(vec[i], p) && isChild(vec[i+1], p) && mn(pos[vec[i]], pos[vec[i + 1]]) == p){
						ansL = i; ansR = i + 1; break;
					}
				}
				if(vec[i] == p){ ansL = i; ansR = i; break;}
			}
			cout<<'\n'<<ansL + 1<<' '<<ansR + 1;
		}
	}
	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
/* TIMUS: 292220YC*/
# Verdict Execution time Memory Grader output
1 Correct 8 ms 5760 KB n=5
2 Correct 9 ms 5888 KB n=100
3 Correct 9 ms 5888 KB n=100
4 Correct 8 ms 5888 KB n=100
5 Correct 8 ms 5888 KB n=100
6 Correct 8 ms 5888 KB n=100
7 Correct 11 ms 5888 KB n=100
8 Correct 8 ms 5888 KB n=100
9 Correct 8 ms 5888 KB n=100
10 Correct 8 ms 5888 KB n=100
11 Correct 8 ms 5888 KB n=100
12 Correct 8 ms 5888 KB n=100
13 Correct 9 ms 5888 KB n=100
14 Correct 8 ms 5888 KB n=100
15 Correct 8 ms 5888 KB n=100
16 Correct 8 ms 5888 KB n=100
17 Correct 8 ms 5888 KB n=100
18 Correct 9 ms 5888 KB n=100
19 Correct 8 ms 5888 KB n=100
20 Correct 8 ms 5888 KB n=100
21 Correct 8 ms 5888 KB n=100
22 Correct 8 ms 5888 KB n=100
23 Correct 8 ms 5888 KB n=100
24 Correct 8 ms 5888 KB n=100
25 Correct 8 ms 5888 KB n=100
26 Correct 8 ms 5760 KB n=12
27 Correct 8 ms 5888 KB n=100
# Verdict Execution time Memory Grader output
1 Correct 8 ms 5760 KB n=5
2 Correct 9 ms 5888 KB n=100
3 Correct 9 ms 5888 KB n=100
4 Correct 8 ms 5888 KB n=100
5 Correct 8 ms 5888 KB n=100
6 Correct 8 ms 5888 KB n=100
7 Correct 11 ms 5888 KB n=100
8 Correct 8 ms 5888 KB n=100
9 Correct 8 ms 5888 KB n=100
10 Correct 8 ms 5888 KB n=100
11 Correct 8 ms 5888 KB n=100
12 Correct 8 ms 5888 KB n=100
13 Correct 9 ms 5888 KB n=100
14 Correct 8 ms 5888 KB n=100
15 Correct 8 ms 5888 KB n=100
16 Correct 8 ms 5888 KB n=100
17 Correct 8 ms 5888 KB n=100
18 Correct 9 ms 5888 KB n=100
19 Correct 8 ms 5888 KB n=100
20 Correct 8 ms 5888 KB n=100
21 Correct 8 ms 5888 KB n=100
22 Correct 8 ms 5888 KB n=100
23 Correct 8 ms 5888 KB n=100
24 Correct 8 ms 5888 KB n=100
25 Correct 8 ms 5888 KB n=100
26 Correct 8 ms 5760 KB n=12
27 Correct 8 ms 5888 KB n=100
28 Correct 9 ms 6144 KB n=500
29 Correct 9 ms 6144 KB n=500
30 Correct 9 ms 6144 KB n=500
31 Correct 8 ms 6144 KB n=500
32 Correct 8 ms 6144 KB n=500
33 Correct 8 ms 6144 KB n=500
34 Correct 9 ms 6144 KB n=500
35 Correct 8 ms 6144 KB n=500
36 Correct 8 ms 6144 KB n=500
37 Correct 9 ms 6144 KB n=500
38 Correct 8 ms 6144 KB n=500
39 Correct 8 ms 6144 KB n=500
40 Correct 9 ms 6144 KB n=500
41 Correct 9 ms 6144 KB n=500
42 Correct 8 ms 6144 KB n=500
43 Correct 8 ms 6144 KB n=500
44 Correct 8 ms 6144 KB n=500
45 Correct 9 ms 6144 KB n=500
46 Correct 8 ms 6144 KB n=500
47 Correct 8 ms 6144 KB n=500
48 Correct 9 ms 6144 KB n=500
49 Correct 9 ms 6192 KB n=500
50 Correct 9 ms 6144 KB n=500
51 Correct 11 ms 6144 KB n=500
52 Correct 8 ms 6144 KB n=500
53 Correct 10 ms 6144 KB n=500
54 Correct 8 ms 6144 KB n=500
55 Correct 8 ms 6016 KB n=278
56 Correct 10 ms 6144 KB n=500
57 Correct 14 ms 6144 KB n=500
58 Correct 8 ms 6144 KB n=500
# Verdict Execution time Memory Grader output
1 Correct 8 ms 5760 KB n=5
2 Correct 9 ms 5888 KB n=100
3 Correct 9 ms 5888 KB n=100
4 Correct 8 ms 5888 KB n=100
5 Correct 8 ms 5888 KB n=100
6 Correct 8 ms 5888 KB n=100
7 Correct 11 ms 5888 KB n=100
8 Correct 8 ms 5888 KB n=100
9 Correct 8 ms 5888 KB n=100
10 Correct 8 ms 5888 KB n=100
11 Correct 8 ms 5888 KB n=100
12 Correct 8 ms 5888 KB n=100
13 Correct 9 ms 5888 KB n=100
14 Correct 8 ms 5888 KB n=100
15 Correct 8 ms 5888 KB n=100
16 Correct 8 ms 5888 KB n=100
17 Correct 8 ms 5888 KB n=100
18 Correct 9 ms 5888 KB n=100
19 Correct 8 ms 5888 KB n=100
20 Correct 8 ms 5888 KB n=100
21 Correct 8 ms 5888 KB n=100
22 Correct 8 ms 5888 KB n=100
23 Correct 8 ms 5888 KB n=100
24 Correct 8 ms 5888 KB n=100
25 Correct 8 ms 5888 KB n=100
26 Correct 8 ms 5760 KB n=12
27 Correct 8 ms 5888 KB n=100
28 Correct 9 ms 6144 KB n=500
29 Correct 9 ms 6144 KB n=500
30 Correct 9 ms 6144 KB n=500
31 Correct 8 ms 6144 KB n=500
32 Correct 8 ms 6144 KB n=500
33 Correct 8 ms 6144 KB n=500
34 Correct 9 ms 6144 KB n=500
35 Correct 8 ms 6144 KB n=500
36 Correct 8 ms 6144 KB n=500
37 Correct 9 ms 6144 KB n=500
38 Correct 8 ms 6144 KB n=500
39 Correct 8 ms 6144 KB n=500
40 Correct 9 ms 6144 KB n=500
41 Correct 9 ms 6144 KB n=500
42 Correct 8 ms 6144 KB n=500
43 Correct 8 ms 6144 KB n=500
44 Correct 8 ms 6144 KB n=500
45 Correct 9 ms 6144 KB n=500
46 Correct 8 ms 6144 KB n=500
47 Correct 8 ms 6144 KB n=500
48 Correct 9 ms 6144 KB n=500
49 Correct 9 ms 6192 KB n=500
50 Correct 9 ms 6144 KB n=500
51 Correct 11 ms 6144 KB n=500
52 Correct 8 ms 6144 KB n=500
53 Correct 10 ms 6144 KB n=500
54 Correct 8 ms 6144 KB n=500
55 Correct 8 ms 6016 KB n=278
56 Correct 10 ms 6144 KB n=500
57 Correct 14 ms 6144 KB n=500
58 Correct 8 ms 6144 KB n=500
59 Correct 9 ms 6912 KB n=2000
60 Correct 13 ms 7040 KB n=2000
61 Correct 13 ms 7040 KB n=2000
62 Correct 13 ms 7092 KB n=2000
63 Correct 9 ms 6912 KB n=2000
64 Correct 13 ms 7040 KB n=2000
65 Correct 9 ms 6912 KB n=2000
66 Correct 13 ms 7040 KB n=2000
67 Correct 10 ms 6912 KB n=2000
68 Correct 13 ms 7040 KB n=2000
69 Correct 14 ms 6912 KB n=2000
70 Correct 19 ms 6912 KB n=2000
71 Correct 14 ms 6912 KB n=2000
72 Correct 15 ms 6944 KB n=2000
73 Correct 11 ms 6912 KB n=2000
74 Correct 12 ms 6784 KB n=1844
75 Correct 12 ms 6912 KB n=2000
76 Correct 19 ms 6912 KB n=2000
77 Correct 14 ms 6912 KB n=2000
78 Correct 19 ms 6912 KB n=2000
79 Correct 11 ms 6912 KB n=2000
80 Correct 14 ms 7040 KB n=2000
81 Correct 12 ms 6912 KB n=2000
82 Correct 9 ms 6912 KB n=2000
83 Correct 13 ms 7040 KB n=2000
84 Correct 13 ms 6912 KB n=2000
85 Correct 13 ms 6912 KB n=2000
86 Correct 14 ms 6912 KB n=2000
87 Correct 13 ms 6912 KB n=2000
88 Correct 34 ms 7040 KB n=2000
89 Correct 32 ms 7040 KB n=2000
90 Correct 21 ms 7040 KB n=2000
91 Correct 19 ms 6912 KB n=2000
# Verdict Execution time Memory Grader output
1 Correct 8 ms 5760 KB n=5
2 Correct 9 ms 5888 KB n=100
3 Correct 9 ms 5888 KB n=100
4 Correct 8 ms 5888 KB n=100
5 Correct 8 ms 5888 KB n=100
6 Correct 8 ms 5888 KB n=100
7 Correct 11 ms 5888 KB n=100
8 Correct 8 ms 5888 KB n=100
9 Correct 8 ms 5888 KB n=100
10 Correct 8 ms 5888 KB n=100
11 Correct 8 ms 5888 KB n=100
12 Correct 8 ms 5888 KB n=100
13 Correct 9 ms 5888 KB n=100
14 Correct 8 ms 5888 KB n=100
15 Correct 8 ms 5888 KB n=100
16 Correct 8 ms 5888 KB n=100
17 Correct 8 ms 5888 KB n=100
18 Correct 9 ms 5888 KB n=100
19 Correct 8 ms 5888 KB n=100
20 Correct 8 ms 5888 KB n=100
21 Correct 8 ms 5888 KB n=100
22 Correct 8 ms 5888 KB n=100
23 Correct 8 ms 5888 KB n=100
24 Correct 8 ms 5888 KB n=100
25 Correct 8 ms 5888 KB n=100
26 Correct 8 ms 5760 KB n=12
27 Correct 8 ms 5888 KB n=100
28 Correct 9 ms 6144 KB n=500
29 Correct 9 ms 6144 KB n=500
30 Correct 9 ms 6144 KB n=500
31 Correct 8 ms 6144 KB n=500
32 Correct 8 ms 6144 KB n=500
33 Correct 8 ms 6144 KB n=500
34 Correct 9 ms 6144 KB n=500
35 Correct 8 ms 6144 KB n=500
36 Correct 8 ms 6144 KB n=500
37 Correct 9 ms 6144 KB n=500
38 Correct 8 ms 6144 KB n=500
39 Correct 8 ms 6144 KB n=500
40 Correct 9 ms 6144 KB n=500
41 Correct 9 ms 6144 KB n=500
42 Correct 8 ms 6144 KB n=500
43 Correct 8 ms 6144 KB n=500
44 Correct 8 ms 6144 KB n=500
45 Correct 9 ms 6144 KB n=500
46 Correct 8 ms 6144 KB n=500
47 Correct 8 ms 6144 KB n=500
48 Correct 9 ms 6144 KB n=500
49 Correct 9 ms 6192 KB n=500
50 Correct 9 ms 6144 KB n=500
51 Correct 11 ms 6144 KB n=500
52 Correct 8 ms 6144 KB n=500
53 Correct 10 ms 6144 KB n=500
54 Correct 8 ms 6144 KB n=500
55 Correct 8 ms 6016 KB n=278
56 Correct 10 ms 6144 KB n=500
57 Correct 14 ms 6144 KB n=500
58 Correct 8 ms 6144 KB n=500
59 Correct 9 ms 6912 KB n=2000
60 Correct 13 ms 7040 KB n=2000
61 Correct 13 ms 7040 KB n=2000
62 Correct 13 ms 7092 KB n=2000
63 Correct 9 ms 6912 KB n=2000
64 Correct 13 ms 7040 KB n=2000
65 Correct 9 ms 6912 KB n=2000
66 Correct 13 ms 7040 KB n=2000
67 Correct 10 ms 6912 KB n=2000
68 Correct 13 ms 7040 KB n=2000
69 Correct 14 ms 6912 KB n=2000
70 Correct 19 ms 6912 KB n=2000
71 Correct 14 ms 6912 KB n=2000
72 Correct 15 ms 6944 KB n=2000
73 Correct 11 ms 6912 KB n=2000
74 Correct 12 ms 6784 KB n=1844
75 Correct 12 ms 6912 KB n=2000
76 Correct 19 ms 6912 KB n=2000
77 Correct 14 ms 6912 KB n=2000
78 Correct 19 ms 6912 KB n=2000
79 Correct 11 ms 6912 KB n=2000
80 Correct 14 ms 7040 KB n=2000
81 Correct 12 ms 6912 KB n=2000
82 Correct 9 ms 6912 KB n=2000
83 Correct 13 ms 7040 KB n=2000
84 Correct 13 ms 6912 KB n=2000
85 Correct 13 ms 6912 KB n=2000
86 Correct 14 ms 6912 KB n=2000
87 Correct 13 ms 6912 KB n=2000
88 Correct 34 ms 7040 KB n=2000
89 Correct 32 ms 7040 KB n=2000
90 Correct 21 ms 7040 KB n=2000
91 Correct 19 ms 6912 KB n=2000
92 Runtime error 175 ms 136032 KB Execution killed with signal 11 (could be triggered by violating memory limits)
93 Halted 0 ms 0 KB -