Submission #523387

# Submission time Handle Problem Language Result Execution time Memory
523387 2022-02-07T15:08:53 Z Kalashnikov Birthday gift (IZhO18_treearray) C++17
56 / 100
4000 ms 37388 KB
#include <bits/stdc++.h>
 
#define ios ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define file(s) if (fopen(s".in", "r")) freopen(s".in", "r", stdin), freopen(s".out", "w", stdout)
#define all(a) a.begin() , a.end()
#define F first
#define S second
 
using namespace std;
using ll = long long;
 
const int N = 2e5+5 , inf = 2e9 + 7;
const ll INF = 1e18 ,   mod = 1e9+7 , P = 6547;

int a[N];
vector<int> g[N];
int tin[N] , tout[N] , timer;
int up[N][20];

void dfs(int v = 1, int p = 0) {
	up[v][0] = p;
	for(int i = 1; i < 20; i ++) {
		up[v][i] = up[up[v][i-1]][i-1];
	}
	tin[v] = ++timer;
	
	for(auto to: g[v]) {
		if(to != p) {
			dfs(to , v);
		}
	}
	tout[v] = ++timer;
}

bool upper(int a , int b) {
	return tin[a] <= tin[b] && tout[a] >= tout[b];
}

int lca(int a , int b) {
	if(upper(a , b)) return a;
	if(upper(b , a)) return b;
	
	for(int i = 19; i >= 0; i --) {
		if(up[a][i] && !upper(up[a][i] , b)) {
			a = up[a][i];
		}
	}
	
	return up[a][0];
}

void solve(int tc) {
	int n , m , q;
	cin >> n >> m >> q;
	for(int i = 1; i < n; i ++) {
		int a , b;
		cin >> a >> b;
		g[a].push_back(b);
		g[b].push_back(a);
	}
	dfs();
	for(int i = 1; i <= m; i ++) {
		cin >> a[i];
	}
	
	while(q --) {
		int t;
		cin >> t;
		if(t == 2) {
			int l , r , v;
			cin >> l >> r >> v;
			int fnd = 0;	
			for(int i = l; i < r; i ++) {
				if(lca(a[i] , a[i+1]) == v) {
					cout << i << ' ' << i+1 << '\n';
					fnd = 1;
					break;
				}
			}
			if(fnd == 0) {
				for(int i = l; i <= r; i ++) {
					if(a[i] == v) {
						fnd = 1;
						cout << i << ' ' << i << '\n';
						break;
					}
				}
			}
			if(!fnd) {
				cout << "-1 -1\n";
				continue;
			}
			
		}
		else {
			int pos , val;
			cin >> pos >> val;
			a[pos] = val;
		}
	}
}
/*
*/
main() {
    ios;
    int tt = 1 , tc = 0;
    // cin >> tt;
    while(tt --) {
        solve(++tc);
    }
    return 0;
}

Compilation message

treearray.cpp:104:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
  104 | main() {
      | ^~~~
# Verdict Execution time Memory Grader output
1 Correct 4 ms 4940 KB n=5
2 Correct 3 ms 4940 KB n=100
3 Correct 3 ms 4940 KB n=100
4 Correct 3 ms 4940 KB n=100
5 Correct 3 ms 4940 KB n=100
6 Correct 4 ms 4940 KB n=100
7 Correct 3 ms 4940 KB n=100
8 Correct 4 ms 4940 KB n=100
9 Correct 3 ms 4940 KB n=100
10 Correct 3 ms 4940 KB n=100
11 Correct 3 ms 5024 KB n=100
12 Correct 3 ms 4940 KB n=100
13 Correct 3 ms 4940 KB n=100
14 Correct 3 ms 5016 KB n=100
15 Correct 3 ms 4940 KB n=100
16 Correct 3 ms 5020 KB n=100
17 Correct 3 ms 4940 KB n=100
18 Correct 3 ms 4940 KB n=100
19 Correct 3 ms 4940 KB n=100
20 Correct 3 ms 4940 KB n=100
21 Correct 3 ms 5020 KB n=100
22 Correct 3 ms 5016 KB n=100
23 Correct 3 ms 4940 KB n=100
24 Correct 3 ms 4940 KB n=100
25 Correct 3 ms 5024 KB n=100
26 Correct 3 ms 4940 KB n=12
27 Correct 3 ms 5024 KB n=100
# Verdict Execution time Memory Grader output
1 Correct 4 ms 4940 KB n=5
2 Correct 3 ms 4940 KB n=100
3 Correct 3 ms 4940 KB n=100
4 Correct 3 ms 4940 KB n=100
5 Correct 3 ms 4940 KB n=100
6 Correct 4 ms 4940 KB n=100
7 Correct 3 ms 4940 KB n=100
8 Correct 4 ms 4940 KB n=100
9 Correct 3 ms 4940 KB n=100
10 Correct 3 ms 4940 KB n=100
11 Correct 3 ms 5024 KB n=100
12 Correct 3 ms 4940 KB n=100
13 Correct 3 ms 4940 KB n=100
14 Correct 3 ms 5016 KB n=100
15 Correct 3 ms 4940 KB n=100
16 Correct 3 ms 5020 KB n=100
17 Correct 3 ms 4940 KB n=100
18 Correct 3 ms 4940 KB n=100
19 Correct 3 ms 4940 KB n=100
20 Correct 3 ms 4940 KB n=100
21 Correct 3 ms 5020 KB n=100
22 Correct 3 ms 5016 KB n=100
23 Correct 3 ms 4940 KB n=100
24 Correct 3 ms 4940 KB n=100
25 Correct 3 ms 5024 KB n=100
26 Correct 3 ms 4940 KB n=12
27 Correct 3 ms 5024 KB n=100
28 Correct 3 ms 5068 KB n=500
29 Correct 3 ms 5068 KB n=500
30 Correct 4 ms 5068 KB n=500
31 Correct 4 ms 5068 KB n=500
32 Correct 3 ms 5068 KB n=500
33 Correct 4 ms 5068 KB n=500
34 Correct 3 ms 5032 KB n=500
35 Correct 3 ms 5068 KB n=500
36 Correct 8 ms 5080 KB n=500
37 Correct 9 ms 5104 KB n=500
38 Correct 9 ms 5024 KB n=500
39 Correct 6 ms 5068 KB n=500
40 Correct 5 ms 5036 KB n=500
41 Correct 5 ms 5068 KB n=500
42 Correct 6 ms 5032 KB n=500
43 Correct 6 ms 5068 KB n=500
44 Correct 8 ms 5104 KB n=500
45 Correct 3 ms 5024 KB n=500
46 Correct 3 ms 5068 KB n=500
47 Correct 3 ms 5068 KB n=500
48 Correct 4 ms 5068 KB n=500
49 Correct 4 ms 5068 KB n=500
50 Correct 4 ms 5068 KB n=500
51 Correct 4 ms 5068 KB n=500
52 Correct 4 ms 5068 KB n=500
53 Correct 6 ms 5088 KB n=500
54 Correct 3 ms 5068 KB n=500
55 Correct 3 ms 5068 KB n=278
56 Correct 4 ms 5024 KB n=500
57 Correct 4 ms 5024 KB n=500
58 Correct 7 ms 5028 KB n=500
# Verdict Execution time Memory Grader output
1 Correct 4 ms 4940 KB n=5
2 Correct 3 ms 4940 KB n=100
3 Correct 3 ms 4940 KB n=100
4 Correct 3 ms 4940 KB n=100
5 Correct 3 ms 4940 KB n=100
6 Correct 4 ms 4940 KB n=100
7 Correct 3 ms 4940 KB n=100
8 Correct 4 ms 4940 KB n=100
9 Correct 3 ms 4940 KB n=100
10 Correct 3 ms 4940 KB n=100
11 Correct 3 ms 5024 KB n=100
12 Correct 3 ms 4940 KB n=100
13 Correct 3 ms 4940 KB n=100
14 Correct 3 ms 5016 KB n=100
15 Correct 3 ms 4940 KB n=100
16 Correct 3 ms 5020 KB n=100
17 Correct 3 ms 4940 KB n=100
18 Correct 3 ms 4940 KB n=100
19 Correct 3 ms 4940 KB n=100
20 Correct 3 ms 4940 KB n=100
21 Correct 3 ms 5020 KB n=100
22 Correct 3 ms 5016 KB n=100
23 Correct 3 ms 4940 KB n=100
24 Correct 3 ms 4940 KB n=100
25 Correct 3 ms 5024 KB n=100
26 Correct 3 ms 4940 KB n=12
27 Correct 3 ms 5024 KB n=100
28 Correct 3 ms 5068 KB n=500
29 Correct 3 ms 5068 KB n=500
30 Correct 4 ms 5068 KB n=500
31 Correct 4 ms 5068 KB n=500
32 Correct 3 ms 5068 KB n=500
33 Correct 4 ms 5068 KB n=500
34 Correct 3 ms 5032 KB n=500
35 Correct 3 ms 5068 KB n=500
36 Correct 8 ms 5080 KB n=500
37 Correct 9 ms 5104 KB n=500
38 Correct 9 ms 5024 KB n=500
39 Correct 6 ms 5068 KB n=500
40 Correct 5 ms 5036 KB n=500
41 Correct 5 ms 5068 KB n=500
42 Correct 6 ms 5032 KB n=500
43 Correct 6 ms 5068 KB n=500
44 Correct 8 ms 5104 KB n=500
45 Correct 3 ms 5024 KB n=500
46 Correct 3 ms 5068 KB n=500
47 Correct 3 ms 5068 KB n=500
48 Correct 4 ms 5068 KB n=500
49 Correct 4 ms 5068 KB n=500
50 Correct 4 ms 5068 KB n=500
51 Correct 4 ms 5068 KB n=500
52 Correct 4 ms 5068 KB n=500
53 Correct 6 ms 5088 KB n=500
54 Correct 3 ms 5068 KB n=500
55 Correct 3 ms 5068 KB n=278
56 Correct 4 ms 5024 KB n=500
57 Correct 4 ms 5024 KB n=500
58 Correct 7 ms 5028 KB n=500
59 Correct 4 ms 5324 KB n=2000
60 Correct 7 ms 5324 KB n=2000
61 Correct 19 ms 5364 KB n=2000
62 Correct 15 ms 5352 KB n=2000
63 Correct 5 ms 5240 KB n=2000
64 Correct 15 ms 5324 KB n=2000
65 Correct 4 ms 5324 KB n=2000
66 Correct 11 ms 5396 KB n=2000
67 Correct 5 ms 5324 KB n=2000
68 Correct 13 ms 5368 KB n=2000
69 Correct 86 ms 5320 KB n=2000
70 Correct 106 ms 5328 KB n=2000
71 Correct 95 ms 5324 KB n=2000
72 Correct 45 ms 5328 KB n=2000
73 Correct 46 ms 5324 KB n=2000
74 Correct 4 ms 5324 KB n=1844
75 Correct 46 ms 5324 KB n=2000
76 Correct 54 ms 5308 KB n=2000
77 Correct 53 ms 5328 KB n=2000
78 Correct 49 ms 5304 KB n=2000
79 Correct 4 ms 5324 KB n=2000
80 Correct 13 ms 5324 KB n=2000
81 Correct 13 ms 5364 KB n=2000
82 Correct 5 ms 5324 KB n=2000
83 Correct 10 ms 5324 KB n=2000
84 Correct 34 ms 5288 KB n=2000
85 Correct 35 ms 5324 KB n=2000
86 Correct 39 ms 5284 KB n=2000
87 Correct 29 ms 5324 KB n=2000
88 Correct 17 ms 5324 KB n=2000
89 Correct 18 ms 5324 KB n=2000
90 Correct 10 ms 5324 KB n=2000
91 Correct 91 ms 5440 KB n=2000
# Verdict Execution time Memory Grader output
1 Correct 4 ms 4940 KB n=5
2 Correct 3 ms 4940 KB n=100
3 Correct 3 ms 4940 KB n=100
4 Correct 3 ms 4940 KB n=100
5 Correct 3 ms 4940 KB n=100
6 Correct 4 ms 4940 KB n=100
7 Correct 3 ms 4940 KB n=100
8 Correct 4 ms 4940 KB n=100
9 Correct 3 ms 4940 KB n=100
10 Correct 3 ms 4940 KB n=100
11 Correct 3 ms 5024 KB n=100
12 Correct 3 ms 4940 KB n=100
13 Correct 3 ms 4940 KB n=100
14 Correct 3 ms 5016 KB n=100
15 Correct 3 ms 4940 KB n=100
16 Correct 3 ms 5020 KB n=100
17 Correct 3 ms 4940 KB n=100
18 Correct 3 ms 4940 KB n=100
19 Correct 3 ms 4940 KB n=100
20 Correct 3 ms 4940 KB n=100
21 Correct 3 ms 5020 KB n=100
22 Correct 3 ms 5016 KB n=100
23 Correct 3 ms 4940 KB n=100
24 Correct 3 ms 4940 KB n=100
25 Correct 3 ms 5024 KB n=100
26 Correct 3 ms 4940 KB n=12
27 Correct 3 ms 5024 KB n=100
28 Correct 3 ms 5068 KB n=500
29 Correct 3 ms 5068 KB n=500
30 Correct 4 ms 5068 KB n=500
31 Correct 4 ms 5068 KB n=500
32 Correct 3 ms 5068 KB n=500
33 Correct 4 ms 5068 KB n=500
34 Correct 3 ms 5032 KB n=500
35 Correct 3 ms 5068 KB n=500
36 Correct 8 ms 5080 KB n=500
37 Correct 9 ms 5104 KB n=500
38 Correct 9 ms 5024 KB n=500
39 Correct 6 ms 5068 KB n=500
40 Correct 5 ms 5036 KB n=500
41 Correct 5 ms 5068 KB n=500
42 Correct 6 ms 5032 KB n=500
43 Correct 6 ms 5068 KB n=500
44 Correct 8 ms 5104 KB n=500
45 Correct 3 ms 5024 KB n=500
46 Correct 3 ms 5068 KB n=500
47 Correct 3 ms 5068 KB n=500
48 Correct 4 ms 5068 KB n=500
49 Correct 4 ms 5068 KB n=500
50 Correct 4 ms 5068 KB n=500
51 Correct 4 ms 5068 KB n=500
52 Correct 4 ms 5068 KB n=500
53 Correct 6 ms 5088 KB n=500
54 Correct 3 ms 5068 KB n=500
55 Correct 3 ms 5068 KB n=278
56 Correct 4 ms 5024 KB n=500
57 Correct 4 ms 5024 KB n=500
58 Correct 7 ms 5028 KB n=500
59 Correct 4 ms 5324 KB n=2000
60 Correct 7 ms 5324 KB n=2000
61 Correct 19 ms 5364 KB n=2000
62 Correct 15 ms 5352 KB n=2000
63 Correct 5 ms 5240 KB n=2000
64 Correct 15 ms 5324 KB n=2000
65 Correct 4 ms 5324 KB n=2000
66 Correct 11 ms 5396 KB n=2000
67 Correct 5 ms 5324 KB n=2000
68 Correct 13 ms 5368 KB n=2000
69 Correct 86 ms 5320 KB n=2000
70 Correct 106 ms 5328 KB n=2000
71 Correct 95 ms 5324 KB n=2000
72 Correct 45 ms 5328 KB n=2000
73 Correct 46 ms 5324 KB n=2000
74 Correct 4 ms 5324 KB n=1844
75 Correct 46 ms 5324 KB n=2000
76 Correct 54 ms 5308 KB n=2000
77 Correct 53 ms 5328 KB n=2000
78 Correct 49 ms 5304 KB n=2000
79 Correct 4 ms 5324 KB n=2000
80 Correct 13 ms 5324 KB n=2000
81 Correct 13 ms 5364 KB n=2000
82 Correct 5 ms 5324 KB n=2000
83 Correct 10 ms 5324 KB n=2000
84 Correct 34 ms 5288 KB n=2000
85 Correct 35 ms 5324 KB n=2000
86 Correct 39 ms 5284 KB n=2000
87 Correct 29 ms 5324 KB n=2000
88 Correct 17 ms 5324 KB n=2000
89 Correct 18 ms 5324 KB n=2000
90 Correct 10 ms 5324 KB n=2000
91 Correct 91 ms 5440 KB n=2000
92 Correct 474 ms 37388 KB n=200000
93 Execution timed out 4026 ms 37060 KB Time limit exceeded
94 Halted 0 ms 0 KB -