Submission #544176

# Submission time Handle Problem Language Result Execution time Memory
544176 2022-04-01T09:37:08 Z SavicS Birthday gift (IZhO18_treearray) C++17
100 / 100
1051 ms 87228 KB
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <bits/stdc++.h>
 
using namespace std;
using namespace __gnu_pbds;
 
typedef long long ll;
typedef long double ld;
 
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
 
#define ff(i,a,b) for(int i = a; i <= b; i++)
#define fb(i,b,a) for(int i = b; i >= a; i--)
#define trav(a,x) for (auto& a : x)
 
#define sz(a) (int)(a).size()
#define pb push_back
#define fi first
#define se second
#define lb lower_bound
#define ub upper_bound
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

template<typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

// os.order_of_key(k) the number of elements in the os less than k
// *os.find_by_order(k)  print the k-th smallest number in os(0-based)

const int mod = 1000000007;
const int inf = 1e9 + 5;
const int mxN = 200005; 

int n, m, q;
int niz[mxN];

vector<int> g[mxN];

set<int> s[mxN];
set<int> gde[mxN];

int d[mxN];
int deda[mxN][20];
void dfs(int v, int p){
	deda[v][0] = p;
	ff(i,1,19)deda[v][i] = deda[deda[v][i - 1]][i - 1];
	for(auto u : g[v]){
		if(u != p){
			d[u] = d[v] + 1;
			dfs(u, v);
		}
	}
}

int LCA(int x, int y){
	if(d[x] < d[y])swap(x, y);
	fb(i,19,0)if((d[x] - d[y]) & (1 << i))x = deda[x][i];
	fb(i,19,0)if(deda[x][i] != deda[y][i])x = deda[x][i], y = deda[y][i];
	return (x == y ? x : deda[x][0]);
}

int main() {
    cin.tie(0)->sync_with_stdio(0);
		
	cin >> n >> m >> q;
	ff(i,1,n - 1){
		int u, v;
		cin >> u >> v;
		g[u].pb(v);
		g[v].pb(u);
	}
	
	ff(i,1,m)cin >> niz[i];
	
	dfs(1, 0);
	
	ff(i,2,m){
		int lca = LCA(niz[i - 1], niz[i]);
		s[lca].insert(i); 
	}
	
	ff(i,1,m)gde[niz[i]].insert(i);
	
	while(q--){
		int t;
		cin >> t;
		
		if(t == 1){
			int pos, val;
			cin >> pos >> val;
			
			gde[niz[pos]].erase(pos);
			
			if(pos != 1){
				int lca = LCA(niz[pos - 1], niz[pos]);
				s[lca].erase(pos);
			}
			
			if(pos != n){
				int lca = LCA(niz[pos], niz[pos + 1]);
				s[lca].erase(pos + 1);
			}
			
			niz[pos] = val; gde[niz[pos]].insert(pos);
			
			if(pos != 1){
				int lca = LCA(niz[pos - 1], niz[pos]);
				s[lca].insert(pos);
			}
			
			if(pos != n){
				int lca = LCA(niz[pos], niz[pos + 1]);
				s[lca].insert(pos + 1);
			}
			
		}
		
		if(t == 2){
			int l, r, v;
			cin >> l >> r >> v;
			
			bool ok = 0;
			
			auto a = s[v].ub(l); 
			if(a != s[v].end() && *a <= r){
				cout << *a - 1 << " " << *a << '\n';
				continue;
			}
			
			auto b = gde[v].lb(l);
			if(b != gde[v].end() && *b <= r){
				cout << *b << " " << *b << '\n';
				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
 
// probati bojenje sahovski
*/
 
 
 
 
 

Compilation message

treearray.cpp: In function 'int main()':
treearray.cpp:128:9: warning: unused variable 'ok' [-Wunused-variable]
  128 |    bool ok = 0;
      |         ^~
# Verdict Execution time Memory Grader output
1 Correct 14 ms 23800 KB n=5
2 Correct 13 ms 23728 KB n=100
3 Correct 13 ms 23892 KB n=100
4 Correct 14 ms 23764 KB n=100
5 Correct 14 ms 23752 KB n=100
6 Correct 13 ms 23828 KB n=100
7 Correct 13 ms 23764 KB n=100
8 Correct 13 ms 23764 KB n=100
9 Correct 13 ms 23764 KB n=100
10 Correct 12 ms 23764 KB n=100
11 Correct 13 ms 23764 KB n=100
12 Correct 13 ms 23792 KB n=100
13 Correct 12 ms 23764 KB n=100
14 Correct 13 ms 23764 KB n=100
15 Correct 14 ms 23764 KB n=100
16 Correct 12 ms 23752 KB n=100
17 Correct 13 ms 23784 KB n=100
18 Correct 12 ms 23764 KB n=100
19 Correct 13 ms 23764 KB n=100
20 Correct 13 ms 23824 KB n=100
21 Correct 13 ms 23736 KB n=100
22 Correct 13 ms 23824 KB n=100
23 Correct 13 ms 23828 KB n=100
24 Correct 12 ms 23764 KB n=100
25 Correct 12 ms 23824 KB n=100
26 Correct 13 ms 23824 KB n=12
27 Correct 12 ms 23764 KB n=100
# Verdict Execution time Memory Grader output
1 Correct 14 ms 23800 KB n=5
2 Correct 13 ms 23728 KB n=100
3 Correct 13 ms 23892 KB n=100
4 Correct 14 ms 23764 KB n=100
5 Correct 14 ms 23752 KB n=100
6 Correct 13 ms 23828 KB n=100
7 Correct 13 ms 23764 KB n=100
8 Correct 13 ms 23764 KB n=100
9 Correct 13 ms 23764 KB n=100
10 Correct 12 ms 23764 KB n=100
11 Correct 13 ms 23764 KB n=100
12 Correct 13 ms 23792 KB n=100
13 Correct 12 ms 23764 KB n=100
14 Correct 13 ms 23764 KB n=100
15 Correct 14 ms 23764 KB n=100
16 Correct 12 ms 23752 KB n=100
17 Correct 13 ms 23784 KB n=100
18 Correct 12 ms 23764 KB n=100
19 Correct 13 ms 23764 KB n=100
20 Correct 13 ms 23824 KB n=100
21 Correct 13 ms 23736 KB n=100
22 Correct 13 ms 23824 KB n=100
23 Correct 13 ms 23828 KB n=100
24 Correct 12 ms 23764 KB n=100
25 Correct 12 ms 23824 KB n=100
26 Correct 13 ms 23824 KB n=12
27 Correct 12 ms 23764 KB n=100
28 Correct 13 ms 23892 KB n=500
29 Correct 14 ms 23892 KB n=500
30 Correct 14 ms 23892 KB n=500
31 Correct 14 ms 23916 KB n=500
32 Correct 14 ms 23892 KB n=500
33 Correct 14 ms 23960 KB n=500
34 Correct 15 ms 23892 KB n=500
35 Correct 14 ms 23948 KB n=500
36 Correct 13 ms 23948 KB n=500
37 Correct 13 ms 23892 KB n=500
38 Correct 13 ms 23892 KB n=500
39 Correct 13 ms 23892 KB n=500
40 Correct 13 ms 23864 KB n=500
41 Correct 14 ms 23892 KB n=500
42 Correct 13 ms 23928 KB n=500
43 Correct 13 ms 23892 KB n=500
44 Correct 13 ms 23900 KB n=500
45 Correct 13 ms 23904 KB n=500
46 Correct 13 ms 23892 KB n=500
47 Correct 13 ms 23892 KB n=500
48 Correct 13 ms 23956 KB n=500
49 Correct 13 ms 23972 KB n=500
50 Correct 13 ms 23832 KB n=500
51 Correct 13 ms 23892 KB n=500
52 Correct 13 ms 24020 KB n=500
53 Correct 13 ms 23892 KB n=500
54 Correct 14 ms 23852 KB n=500
55 Correct 13 ms 23892 KB n=278
56 Correct 13 ms 23892 KB n=500
57 Correct 13 ms 23892 KB n=500
58 Correct 13 ms 23952 KB n=500
# Verdict Execution time Memory Grader output
1 Correct 14 ms 23800 KB n=5
2 Correct 13 ms 23728 KB n=100
3 Correct 13 ms 23892 KB n=100
4 Correct 14 ms 23764 KB n=100
5 Correct 14 ms 23752 KB n=100
6 Correct 13 ms 23828 KB n=100
7 Correct 13 ms 23764 KB n=100
8 Correct 13 ms 23764 KB n=100
9 Correct 13 ms 23764 KB n=100
10 Correct 12 ms 23764 KB n=100
11 Correct 13 ms 23764 KB n=100
12 Correct 13 ms 23792 KB n=100
13 Correct 12 ms 23764 KB n=100
14 Correct 13 ms 23764 KB n=100
15 Correct 14 ms 23764 KB n=100
16 Correct 12 ms 23752 KB n=100
17 Correct 13 ms 23784 KB n=100
18 Correct 12 ms 23764 KB n=100
19 Correct 13 ms 23764 KB n=100
20 Correct 13 ms 23824 KB n=100
21 Correct 13 ms 23736 KB n=100
22 Correct 13 ms 23824 KB n=100
23 Correct 13 ms 23828 KB n=100
24 Correct 12 ms 23764 KB n=100
25 Correct 12 ms 23824 KB n=100
26 Correct 13 ms 23824 KB n=12
27 Correct 12 ms 23764 KB n=100
28 Correct 13 ms 23892 KB n=500
29 Correct 14 ms 23892 KB n=500
30 Correct 14 ms 23892 KB n=500
31 Correct 14 ms 23916 KB n=500
32 Correct 14 ms 23892 KB n=500
33 Correct 14 ms 23960 KB n=500
34 Correct 15 ms 23892 KB n=500
35 Correct 14 ms 23948 KB n=500
36 Correct 13 ms 23948 KB n=500
37 Correct 13 ms 23892 KB n=500
38 Correct 13 ms 23892 KB n=500
39 Correct 13 ms 23892 KB n=500
40 Correct 13 ms 23864 KB n=500
41 Correct 14 ms 23892 KB n=500
42 Correct 13 ms 23928 KB n=500
43 Correct 13 ms 23892 KB n=500
44 Correct 13 ms 23900 KB n=500
45 Correct 13 ms 23904 KB n=500
46 Correct 13 ms 23892 KB n=500
47 Correct 13 ms 23892 KB n=500
48 Correct 13 ms 23956 KB n=500
49 Correct 13 ms 23972 KB n=500
50 Correct 13 ms 23832 KB n=500
51 Correct 13 ms 23892 KB n=500
52 Correct 13 ms 24020 KB n=500
53 Correct 13 ms 23892 KB n=500
54 Correct 14 ms 23852 KB n=500
55 Correct 13 ms 23892 KB n=278
56 Correct 13 ms 23892 KB n=500
57 Correct 13 ms 23892 KB n=500
58 Correct 13 ms 23952 KB n=500
59 Correct 16 ms 24276 KB n=2000
60 Correct 17 ms 24404 KB n=2000
61 Correct 17 ms 24352 KB n=2000
62 Correct 16 ms 24404 KB n=2000
63 Correct 16 ms 24316 KB n=2000
64 Correct 16 ms 24276 KB n=2000
65 Correct 17 ms 24276 KB n=2000
66 Correct 16 ms 24292 KB n=2000
67 Correct 16 ms 24220 KB n=2000
68 Correct 17 ms 24332 KB n=2000
69 Correct 15 ms 24276 KB n=2000
70 Correct 14 ms 24276 KB n=2000
71 Correct 16 ms 24276 KB n=2000
72 Correct 15 ms 24276 KB n=2000
73 Correct 15 ms 24276 KB n=2000
74 Correct 16 ms 24276 KB n=1844
75 Correct 15 ms 24216 KB n=2000
76 Correct 16 ms 24276 KB n=2000
77 Correct 17 ms 24276 KB n=2000
78 Correct 16 ms 24276 KB n=2000
79 Correct 17 ms 24284 KB n=2000
80 Correct 16 ms 24404 KB n=2000
81 Correct 16 ms 24276 KB n=2000
82 Correct 18 ms 24288 KB n=2000
83 Correct 16 ms 24336 KB n=2000
84 Correct 18 ms 24220 KB n=2000
85 Correct 16 ms 24404 KB n=2000
86 Correct 15 ms 24260 KB n=2000
87 Correct 15 ms 24276 KB n=2000
88 Correct 16 ms 24404 KB n=2000
89 Correct 16 ms 24404 KB n=2000
90 Correct 17 ms 24328 KB n=2000
91 Correct 17 ms 24276 KB n=2000
# Verdict Execution time Memory Grader output
1 Correct 14 ms 23800 KB n=5
2 Correct 13 ms 23728 KB n=100
3 Correct 13 ms 23892 KB n=100
4 Correct 14 ms 23764 KB n=100
5 Correct 14 ms 23752 KB n=100
6 Correct 13 ms 23828 KB n=100
7 Correct 13 ms 23764 KB n=100
8 Correct 13 ms 23764 KB n=100
9 Correct 13 ms 23764 KB n=100
10 Correct 12 ms 23764 KB n=100
11 Correct 13 ms 23764 KB n=100
12 Correct 13 ms 23792 KB n=100
13 Correct 12 ms 23764 KB n=100
14 Correct 13 ms 23764 KB n=100
15 Correct 14 ms 23764 KB n=100
16 Correct 12 ms 23752 KB n=100
17 Correct 13 ms 23784 KB n=100
18 Correct 12 ms 23764 KB n=100
19 Correct 13 ms 23764 KB n=100
20 Correct 13 ms 23824 KB n=100
21 Correct 13 ms 23736 KB n=100
22 Correct 13 ms 23824 KB n=100
23 Correct 13 ms 23828 KB n=100
24 Correct 12 ms 23764 KB n=100
25 Correct 12 ms 23824 KB n=100
26 Correct 13 ms 23824 KB n=12
27 Correct 12 ms 23764 KB n=100
28 Correct 13 ms 23892 KB n=500
29 Correct 14 ms 23892 KB n=500
30 Correct 14 ms 23892 KB n=500
31 Correct 14 ms 23916 KB n=500
32 Correct 14 ms 23892 KB n=500
33 Correct 14 ms 23960 KB n=500
34 Correct 15 ms 23892 KB n=500
35 Correct 14 ms 23948 KB n=500
36 Correct 13 ms 23948 KB n=500
37 Correct 13 ms 23892 KB n=500
38 Correct 13 ms 23892 KB n=500
39 Correct 13 ms 23892 KB n=500
40 Correct 13 ms 23864 KB n=500
41 Correct 14 ms 23892 KB n=500
42 Correct 13 ms 23928 KB n=500
43 Correct 13 ms 23892 KB n=500
44 Correct 13 ms 23900 KB n=500
45 Correct 13 ms 23904 KB n=500
46 Correct 13 ms 23892 KB n=500
47 Correct 13 ms 23892 KB n=500
48 Correct 13 ms 23956 KB n=500
49 Correct 13 ms 23972 KB n=500
50 Correct 13 ms 23832 KB n=500
51 Correct 13 ms 23892 KB n=500
52 Correct 13 ms 24020 KB n=500
53 Correct 13 ms 23892 KB n=500
54 Correct 14 ms 23852 KB n=500
55 Correct 13 ms 23892 KB n=278
56 Correct 13 ms 23892 KB n=500
57 Correct 13 ms 23892 KB n=500
58 Correct 13 ms 23952 KB n=500
59 Correct 16 ms 24276 KB n=2000
60 Correct 17 ms 24404 KB n=2000
61 Correct 17 ms 24352 KB n=2000
62 Correct 16 ms 24404 KB n=2000
63 Correct 16 ms 24316 KB n=2000
64 Correct 16 ms 24276 KB n=2000
65 Correct 17 ms 24276 KB n=2000
66 Correct 16 ms 24292 KB n=2000
67 Correct 16 ms 24220 KB n=2000
68 Correct 17 ms 24332 KB n=2000
69 Correct 15 ms 24276 KB n=2000
70 Correct 14 ms 24276 KB n=2000
71 Correct 16 ms 24276 KB n=2000
72 Correct 15 ms 24276 KB n=2000
73 Correct 15 ms 24276 KB n=2000
74 Correct 16 ms 24276 KB n=1844
75 Correct 15 ms 24216 KB n=2000
76 Correct 16 ms 24276 KB n=2000
77 Correct 17 ms 24276 KB n=2000
78 Correct 16 ms 24276 KB n=2000
79 Correct 17 ms 24284 KB n=2000
80 Correct 16 ms 24404 KB n=2000
81 Correct 16 ms 24276 KB n=2000
82 Correct 18 ms 24288 KB n=2000
83 Correct 16 ms 24336 KB n=2000
84 Correct 18 ms 24220 KB n=2000
85 Correct 16 ms 24404 KB n=2000
86 Correct 15 ms 24260 KB n=2000
87 Correct 15 ms 24276 KB n=2000
88 Correct 16 ms 24404 KB n=2000
89 Correct 16 ms 24404 KB n=2000
90 Correct 17 ms 24328 KB n=2000
91 Correct 17 ms 24276 KB n=2000
92 Correct 694 ms 74492 KB n=200000
93 Correct 1022 ms 81148 KB n=200000
94 Correct 1002 ms 85388 KB n=200000
95 Correct 682 ms 74328 KB n=200000
96 Correct 690 ms 74308 KB n=200000
97 Correct 993 ms 79776 KB n=200000
98 Correct 690 ms 74424 KB n=200000
99 Correct 800 ms 74420 KB n=200000
100 Correct 711 ms 74284 KB n=200000
101 Correct 939 ms 87228 KB n=200000
102 Correct 385 ms 75588 KB n=200000
103 Correct 383 ms 75572 KB n=200000
104 Correct 381 ms 75504 KB n=200000
105 Correct 387 ms 75976 KB n=200000
106 Correct 371 ms 75856 KB n=200000
107 Correct 386 ms 75916 KB n=200000
108 Correct 755 ms 74452 KB n=200000
109 Correct 730 ms 74388 KB n=200000
110 Correct 752 ms 74388 KB n=200000
111 Correct 655 ms 73844 KB n=200000
112 Correct 954 ms 85880 KB n=200000
113 Correct 999 ms 79772 KB n=200000
114 Correct 685 ms 74040 KB n=200000
115 Correct 1039 ms 76992 KB n=200000
116 Correct 672 ms 74456 KB n=200000
117 Correct 955 ms 86240 KB n=200000
118 Correct 1051 ms 78248 KB n=200000
119 Correct 677 ms 74504 KB n=200000
120 Correct 951 ms 86164 KB n=200000
121 Correct 1035 ms 86032 KB n=200000
122 Correct 1022 ms 86392 KB n=200000
123 Correct 476 ms 75732 KB n=200000
124 Correct 263 ms 38984 KB n=25264