Submission #83210

# Submission time Handle Problem Language Result Execution time Memory
83210 2018-11-06T03:40:12 Z Good Birthday gift (IZhO18_treearray) C++11
56 / 100
2049 ms 141956 KB
/*
ID: blackha5
TASK: test
LANG: C++
*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#define ff first
#define ss second
#define Maxn 200003
#define ll long long
#define pb push_back
#define Inf 1000000009
#define ppb() pop_back()
#define pii pair <int , int>
#define mid(x, y) (x + y) / 2
#define all(x) x.begin(),x.end()
#define llInf 1000000000000000009
#define tr(i, c) for(__typeof(c).begin() i = (c).begin() ; i != (c).end() ; i++)
using namespace std;
using namespace __gnu_pbds;
typedef tree <int, null_type, less <int>, rb_tree_tag, tree_order_statistics_node_update> order;

int n, m, q;
int A[Maxn];
int lvl[Maxn];
int mat[Maxn][21];

vector <int> adj[Maxn];
set <int> s[Maxn], t[Maxn];

void dfs (int nd, int p) {
	mat[nd][0] = p;
	lvl[nd] = lvl[p] + 1;
	
	for (auto i: adj[nd])
		if (i != p)
			dfs (i, nd);
}

void build () {
	for (int i = 1; i <= 19; i++)
		for (int j = 1; j <= n; j++)
			mat[j][i] = mat[mat[j][i - 1]][i - 1];
}

int lca (int x, int y) {
	if (lvl[x] < lvl[y])
		swap (x, y);
	
	for (int i = 19; i >= 0; i--)
		if (lvl[mat[x][i]] >= lvl[y])
			x = mat[x][i];
	
	if (x == y)
		return x;
	
	for (int i = 19; i >= 0; i--) 
		if (mat[x][i] != mat[y][i])
			x = mat[x][i], y = mat[y][i];
	
	return mat[x][0];					
}

int main () {
	//freopen ("file.in", "r", stdin);
	//freopen ("file.out", "w", stdout);
	
 	//srand ((unsigned) time ( NULL ));
	//int randomNumber = rand() % 10 + 1;

	scanf ("%d%d%d", &n, &m, &q);
	
	for (int i = 1; i < n; i++) {
		int u, v;
		
		scanf ("%d%d", &u, &v);
		adj[u].pb (v);
		adj[v].pb (u);
		s[i].insert (Inf);
		t[i].insert (Inf);
	}
	s[n].insert (Inf);
	t[n].insert (Inf);

	dfs (1, 0);
	build ();
	
	for (int i = 1; i <= m; i++) {
		scanf ("%d", A + i);
		t[A[i]].insert (i);
	}	
	
	for (int i = 1; i < m; i++)
		s[lca (A[i], A[i + 1])].insert (i);	
	
	while (q--) {
		int type, l, v;
		scanf ("%d%d", &type, &l);
		
		if (type == 2) {
			int r;
			scanf ("%d%d", &r, &v);
			int x = *s[v].lower_bound (l);
			int y = *t[v].lower_bound (l);
			
			if (y <= r)
				printf ("%d %d\n", y, y);
			else if (x <= r - 1)
				printf ("%d %d\n", x, x + 1);
			else
				puts ("-1 -1");		
		}	
		
		else {
			scanf ("%d", &v);
			t[A[l]].erase (l);
			t[v].insert (l);
			
			if (l > 1) {
				int x = lca (A[l - 1], A[l]);
				s[x].erase (l - 1);
				x = lca (A[l - 1], v);
				s[x].insert(l - 1);		
			}
			if (l < n) {
				int x = lca (A[l], A[l + 1]);
				s[x].erase (l);
				x = lca (v, A[l + 1]);
				s[x].insert (l);
			}
			A[l] = v;
		}
	}		
	return 0;
}

Compilation message

treearray.cpp: In function 'int main()':
treearray.cpp:73:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf ("%d%d%d", &n, &m, &q);
  ~~~~~~^~~~~~~~~~~~~~~~~~~~~~
treearray.cpp:78:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf ("%d%d", &u, &v);
   ~~~~~~^~~~~~~~~~~~~~~~
treearray.cpp:91:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf ("%d", A + i);
   ~~~~~~^~~~~~~~~~~~~
treearray.cpp:100:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf ("%d%d", &type, &l);
   ~~~~~~^~~~~~~~~~~~~~~~~~~
treearray.cpp:104:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    scanf ("%d%d", &r, &v);
    ~~~~~~^~~~~~~~~~~~~~~~
treearray.cpp:117:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    scanf ("%d", &v);
    ~~~~~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 30 ms 23800 KB n=5
2 Correct 26 ms 23924 KB n=100
3 Correct 24 ms 24132 KB n=100
4 Correct 25 ms 24132 KB n=100
5 Correct 24 ms 24132 KB n=100
6 Correct 25 ms 24132 KB n=100
7 Correct 24 ms 24132 KB n=100
8 Correct 25 ms 24132 KB n=100
9 Correct 24 ms 24132 KB n=100
10 Correct 24 ms 24132 KB n=100
11 Correct 24 ms 24136 KB n=100
12 Correct 24 ms 24136 KB n=100
13 Correct 28 ms 24136 KB n=100
14 Correct 24 ms 24136 KB n=100
15 Correct 24 ms 24164 KB n=100
16 Correct 24 ms 24164 KB n=100
17 Correct 24 ms 24164 KB n=100
18 Correct 24 ms 24164 KB n=100
19 Correct 24 ms 24164 KB n=100
20 Correct 29 ms 24204 KB n=100
21 Correct 23 ms 24320 KB n=100
22 Correct 24 ms 24320 KB n=100
23 Correct 23 ms 24320 KB n=100
24 Correct 24 ms 24320 KB n=100
25 Correct 23 ms 24320 KB n=100
26 Correct 24 ms 24320 KB n=12
27 Correct 24 ms 24320 KB n=100
# Verdict Execution time Memory Grader output
1 Correct 30 ms 23800 KB n=5
2 Correct 26 ms 23924 KB n=100
3 Correct 24 ms 24132 KB n=100
4 Correct 25 ms 24132 KB n=100
5 Correct 24 ms 24132 KB n=100
6 Correct 25 ms 24132 KB n=100
7 Correct 24 ms 24132 KB n=100
8 Correct 25 ms 24132 KB n=100
9 Correct 24 ms 24132 KB n=100
10 Correct 24 ms 24132 KB n=100
11 Correct 24 ms 24136 KB n=100
12 Correct 24 ms 24136 KB n=100
13 Correct 28 ms 24136 KB n=100
14 Correct 24 ms 24136 KB n=100
15 Correct 24 ms 24164 KB n=100
16 Correct 24 ms 24164 KB n=100
17 Correct 24 ms 24164 KB n=100
18 Correct 24 ms 24164 KB n=100
19 Correct 24 ms 24164 KB n=100
20 Correct 29 ms 24204 KB n=100
21 Correct 23 ms 24320 KB n=100
22 Correct 24 ms 24320 KB n=100
23 Correct 23 ms 24320 KB n=100
24 Correct 24 ms 24320 KB n=100
25 Correct 23 ms 24320 KB n=100
26 Correct 24 ms 24320 KB n=12
27 Correct 24 ms 24320 KB n=100
28 Correct 25 ms 24404 KB n=500
29 Correct 26 ms 24412 KB n=500
30 Correct 29 ms 24412 KB n=500
31 Correct 25 ms 24412 KB n=500
32 Correct 28 ms 24412 KB n=500
33 Correct 25 ms 24476 KB n=500
34 Correct 25 ms 24476 KB n=500
35 Correct 28 ms 24504 KB n=500
36 Correct 24 ms 24504 KB n=500
37 Correct 27 ms 24532 KB n=500
38 Correct 30 ms 24532 KB n=500
39 Correct 25 ms 24532 KB n=500
40 Correct 44 ms 24648 KB n=500
41 Correct 32 ms 24648 KB n=500
42 Correct 25 ms 24648 KB n=500
43 Correct 32 ms 24648 KB n=500
44 Correct 25 ms 24648 KB n=500
45 Correct 25 ms 24648 KB n=500
46 Correct 24 ms 24648 KB n=500
47 Correct 27 ms 24648 KB n=500
48 Correct 26 ms 24648 KB n=500
49 Correct 25 ms 24648 KB n=500
50 Correct 30 ms 24648 KB n=500
51 Correct 25 ms 24648 KB n=500
52 Correct 25 ms 24676 KB n=500
53 Correct 26 ms 24676 KB n=500
54 Correct 26 ms 24676 KB n=500
55 Correct 25 ms 24676 KB n=278
56 Correct 25 ms 24676 KB n=500
57 Correct 25 ms 24676 KB n=500
58 Correct 25 ms 24688 KB n=500
# Verdict Execution time Memory Grader output
1 Correct 30 ms 23800 KB n=5
2 Correct 26 ms 23924 KB n=100
3 Correct 24 ms 24132 KB n=100
4 Correct 25 ms 24132 KB n=100
5 Correct 24 ms 24132 KB n=100
6 Correct 25 ms 24132 KB n=100
7 Correct 24 ms 24132 KB n=100
8 Correct 25 ms 24132 KB n=100
9 Correct 24 ms 24132 KB n=100
10 Correct 24 ms 24132 KB n=100
11 Correct 24 ms 24136 KB n=100
12 Correct 24 ms 24136 KB n=100
13 Correct 28 ms 24136 KB n=100
14 Correct 24 ms 24136 KB n=100
15 Correct 24 ms 24164 KB n=100
16 Correct 24 ms 24164 KB n=100
17 Correct 24 ms 24164 KB n=100
18 Correct 24 ms 24164 KB n=100
19 Correct 24 ms 24164 KB n=100
20 Correct 29 ms 24204 KB n=100
21 Correct 23 ms 24320 KB n=100
22 Correct 24 ms 24320 KB n=100
23 Correct 23 ms 24320 KB n=100
24 Correct 24 ms 24320 KB n=100
25 Correct 23 ms 24320 KB n=100
26 Correct 24 ms 24320 KB n=12
27 Correct 24 ms 24320 KB n=100
28 Correct 25 ms 24404 KB n=500
29 Correct 26 ms 24412 KB n=500
30 Correct 29 ms 24412 KB n=500
31 Correct 25 ms 24412 KB n=500
32 Correct 28 ms 24412 KB n=500
33 Correct 25 ms 24476 KB n=500
34 Correct 25 ms 24476 KB n=500
35 Correct 28 ms 24504 KB n=500
36 Correct 24 ms 24504 KB n=500
37 Correct 27 ms 24532 KB n=500
38 Correct 30 ms 24532 KB n=500
39 Correct 25 ms 24532 KB n=500
40 Correct 44 ms 24648 KB n=500
41 Correct 32 ms 24648 KB n=500
42 Correct 25 ms 24648 KB n=500
43 Correct 32 ms 24648 KB n=500
44 Correct 25 ms 24648 KB n=500
45 Correct 25 ms 24648 KB n=500
46 Correct 24 ms 24648 KB n=500
47 Correct 27 ms 24648 KB n=500
48 Correct 26 ms 24648 KB n=500
49 Correct 25 ms 24648 KB n=500
50 Correct 30 ms 24648 KB n=500
51 Correct 25 ms 24648 KB n=500
52 Correct 25 ms 24676 KB n=500
53 Correct 26 ms 24676 KB n=500
54 Correct 26 ms 24676 KB n=500
55 Correct 25 ms 24676 KB n=278
56 Correct 25 ms 24676 KB n=500
57 Correct 25 ms 24676 KB n=500
58 Correct 25 ms 24688 KB n=500
59 Correct 30 ms 25216 KB n=2000
60 Correct 29 ms 25400 KB n=2000
61 Correct 29 ms 25468 KB n=2000
62 Correct 30 ms 25468 KB n=2000
63 Correct 29 ms 25468 KB n=2000
64 Correct 35 ms 25648 KB n=2000
65 Correct 30 ms 25704 KB n=2000
66 Correct 33 ms 25776 KB n=2000
67 Correct 31 ms 25800 KB n=2000
68 Correct 29 ms 25884 KB n=2000
69 Correct 30 ms 25884 KB n=2000
70 Correct 36 ms 25884 KB n=2000
71 Correct 34 ms 25932 KB n=2000
72 Correct 28 ms 26092 KB n=2000
73 Correct 28 ms 26168 KB n=2000
74 Correct 30 ms 26168 KB n=1844
75 Correct 27 ms 26168 KB n=2000
76 Correct 32 ms 26200 KB n=2000
77 Correct 30 ms 26248 KB n=2000
78 Correct 30 ms 26316 KB n=2000
79 Correct 30 ms 26480 KB n=2000
80 Correct 29 ms 26532 KB n=2000
81 Correct 32 ms 26588 KB n=2000
82 Correct 29 ms 26588 KB n=2000
83 Correct 31 ms 26772 KB n=2000
84 Correct 29 ms 26772 KB n=2000
85 Correct 29 ms 26788 KB n=2000
86 Correct 30 ms 26788 KB n=2000
87 Correct 31 ms 26788 KB n=2000
88 Correct 29 ms 26960 KB n=2000
89 Correct 30 ms 27072 KB n=2000
90 Correct 29 ms 27072 KB n=2000
91 Correct 29 ms 27072 KB n=2000
# Verdict Execution time Memory Grader output
1 Correct 30 ms 23800 KB n=5
2 Correct 26 ms 23924 KB n=100
3 Correct 24 ms 24132 KB n=100
4 Correct 25 ms 24132 KB n=100
5 Correct 24 ms 24132 KB n=100
6 Correct 25 ms 24132 KB n=100
7 Correct 24 ms 24132 KB n=100
8 Correct 25 ms 24132 KB n=100
9 Correct 24 ms 24132 KB n=100
10 Correct 24 ms 24132 KB n=100
11 Correct 24 ms 24136 KB n=100
12 Correct 24 ms 24136 KB n=100
13 Correct 28 ms 24136 KB n=100
14 Correct 24 ms 24136 KB n=100
15 Correct 24 ms 24164 KB n=100
16 Correct 24 ms 24164 KB n=100
17 Correct 24 ms 24164 KB n=100
18 Correct 24 ms 24164 KB n=100
19 Correct 24 ms 24164 KB n=100
20 Correct 29 ms 24204 KB n=100
21 Correct 23 ms 24320 KB n=100
22 Correct 24 ms 24320 KB n=100
23 Correct 23 ms 24320 KB n=100
24 Correct 24 ms 24320 KB n=100
25 Correct 23 ms 24320 KB n=100
26 Correct 24 ms 24320 KB n=12
27 Correct 24 ms 24320 KB n=100
28 Correct 25 ms 24404 KB n=500
29 Correct 26 ms 24412 KB n=500
30 Correct 29 ms 24412 KB n=500
31 Correct 25 ms 24412 KB n=500
32 Correct 28 ms 24412 KB n=500
33 Correct 25 ms 24476 KB n=500
34 Correct 25 ms 24476 KB n=500
35 Correct 28 ms 24504 KB n=500
36 Correct 24 ms 24504 KB n=500
37 Correct 27 ms 24532 KB n=500
38 Correct 30 ms 24532 KB n=500
39 Correct 25 ms 24532 KB n=500
40 Correct 44 ms 24648 KB n=500
41 Correct 32 ms 24648 KB n=500
42 Correct 25 ms 24648 KB n=500
43 Correct 32 ms 24648 KB n=500
44 Correct 25 ms 24648 KB n=500
45 Correct 25 ms 24648 KB n=500
46 Correct 24 ms 24648 KB n=500
47 Correct 27 ms 24648 KB n=500
48 Correct 26 ms 24648 KB n=500
49 Correct 25 ms 24648 KB n=500
50 Correct 30 ms 24648 KB n=500
51 Correct 25 ms 24648 KB n=500
52 Correct 25 ms 24676 KB n=500
53 Correct 26 ms 24676 KB n=500
54 Correct 26 ms 24676 KB n=500
55 Correct 25 ms 24676 KB n=278
56 Correct 25 ms 24676 KB n=500
57 Correct 25 ms 24676 KB n=500
58 Correct 25 ms 24688 KB n=500
59 Correct 30 ms 25216 KB n=2000
60 Correct 29 ms 25400 KB n=2000
61 Correct 29 ms 25468 KB n=2000
62 Correct 30 ms 25468 KB n=2000
63 Correct 29 ms 25468 KB n=2000
64 Correct 35 ms 25648 KB n=2000
65 Correct 30 ms 25704 KB n=2000
66 Correct 33 ms 25776 KB n=2000
67 Correct 31 ms 25800 KB n=2000
68 Correct 29 ms 25884 KB n=2000
69 Correct 30 ms 25884 KB n=2000
70 Correct 36 ms 25884 KB n=2000
71 Correct 34 ms 25932 KB n=2000
72 Correct 28 ms 26092 KB n=2000
73 Correct 28 ms 26168 KB n=2000
74 Correct 30 ms 26168 KB n=1844
75 Correct 27 ms 26168 KB n=2000
76 Correct 32 ms 26200 KB n=2000
77 Correct 30 ms 26248 KB n=2000
78 Correct 30 ms 26316 KB n=2000
79 Correct 30 ms 26480 KB n=2000
80 Correct 29 ms 26532 KB n=2000
81 Correct 32 ms 26588 KB n=2000
82 Correct 29 ms 26588 KB n=2000
83 Correct 31 ms 26772 KB n=2000
84 Correct 29 ms 26772 KB n=2000
85 Correct 29 ms 26788 KB n=2000
86 Correct 30 ms 26788 KB n=2000
87 Correct 31 ms 26788 KB n=2000
88 Correct 29 ms 26960 KB n=2000
89 Correct 30 ms 27072 KB n=2000
90 Correct 29 ms 27072 KB n=2000
91 Correct 29 ms 27072 KB n=2000
92 Correct 1263 ms 90388 KB n=200000
93 Correct 2033 ms 93952 KB n=200000
94 Correct 1824 ms 97336 KB n=200000
95 Correct 1278 ms 97336 KB n=200000
96 Correct 1225 ms 97336 KB n=200000
97 Correct 1801 ms 97336 KB n=200000
98 Correct 1266 ms 97336 KB n=200000
99 Correct 1567 ms 97336 KB n=200000
100 Correct 1316 ms 97336 KB n=200000
101 Correct 2001 ms 98648 KB n=200000
102 Correct 839 ms 98648 KB n=200000
103 Correct 768 ms 98648 KB n=200000
104 Correct 802 ms 98648 KB n=200000
105 Correct 750 ms 98648 KB n=200000
106 Correct 819 ms 98648 KB n=200000
107 Correct 854 ms 98648 KB n=200000
108 Correct 1434 ms 98648 KB n=200000
109 Correct 1388 ms 98648 KB n=200000
110 Correct 1514 ms 98648 KB n=200000
111 Correct 1309 ms 98648 KB n=200000
112 Correct 1977 ms 98648 KB n=200000
113 Correct 1971 ms 98648 KB n=200000
114 Correct 1333 ms 98648 KB n=200000
115 Correct 2039 ms 98648 KB n=200000
116 Correct 1319 ms 98648 KB n=200000
117 Correct 1965 ms 105768 KB n=200000
118 Correct 2049 ms 107404 KB n=200000
119 Correct 1324 ms 112320 KB n=200000
120 Correct 1777 ms 127576 KB n=200000
121 Correct 1750 ms 134688 KB n=200000
122 Correct 1783 ms 141956 KB n=200000
123 Correct 786 ms 141956 KB n=200000
124 Incorrect 371 ms 141956 KB Wrong range.