Submission #464062

# Submission time Handle Problem Language Result Execution time Memory
464062 2021-08-12T10:28:08 Z AmShZ Inside information (BOI21_servers) C++11
100 / 100
614 ms 46016 KB
//khodaya khodet komak kon
# include <bits/stdc++.h>

using namespace std;

typedef long long                                        ll;
typedef long double                                      ld;
typedef pair <int, int>                                  pii;
typedef pair <pii, int>                                  ppi;
typedef pair <int, pii>                                  pip;
typedef pair <pii, pii>                                  ppp;
typedef pair <ll, ll>                                    pll;

# define A                                               first
# define B                                               second
# define endl                                            '\n'
# define sep                                             ' '
# define all(x)                                          x.begin(), x.end()
# define kill(x)                                         return cout << x << endl, 0
# define SZ(x)                                           int(x.size())
# define lc                                              id << 1
# define rc                                              id << 1 | 1
# define fast_io                                         ios::sync_with_stdio(0);cin.tie(0); cout.tie(0);

ll power(ll a, ll b, ll md) {return (!b ? 1 : (b & 1 ? a * power(a * a % md, b / 2, md) % md : power(a * a % md, b / 2, md) % md));}

const int xn = 3e5 + 10;
const int xm = - 20 + 10;
const int sq = 320;
const int inf = 1e9 + 10;
const ll INF = 1e18 + 10;
const ld eps = 1e-15;
const int mod = 1e9 + 7;//998244353;
const int base = 257;

int n, k, sz[xn], ans[xn], fen[xn], a[xn], qt[xn];
vector <int> QG[xn], vec, V;
vector <pii> adj[xn], Q[xn];
bool hide[xn], mark[xn], fl[2][xn];

void plant(int v, int p = - 1){
	sz[v] = 1;
	for (pii u : adj[v])
		if (!hide[u.A] && u.A != p)
			plant(u.A, v), sz[v] += sz[u.A];
}
int find_centroid(int v, int s, int p = - 1){
	for (pii u : adj[v])
		if (!hide[u.A] && u.A != p && s < sz[u.A] * 2)
			return find_centroid(u.A, s, v);
	return v;
}
bool cmp(pii x, pii y){
	return y.B < x.B;
}
void DFS(int v, int p = - 1){
	fl[0][v] = fl[0][p];
	if (!hide[p])
		fl[0][v] &= (a[v] < a[p]);
	fl[1][v] = fl[1][p];
	if (!hide[p])
		fl[1][v] &= (a[p] < a[v]);
	vec.push_back(v);
	for (pii u : adj[v])
		if (!hide[u.A] && u.A != p)
			a[u.A] = u.B, DFS(u.A, v);
}
void mofen(int pos, int val){
	for (pos += 5; pos < xn; pos += pos & - pos)
		fen[pos] += val;
}
int gefen(int pos){
	int res = 0;
	for (pos += 5; 0 < pos; pos -= pos & - pos)
		res += fen[pos];
	return res;
}
void solve(int v){
	plant(v);
	v = find_centroid(v, sz[v]);
	hide[v] = true;
	sort(all(adj[v]), cmp);
	a[v] = 0, mofen(0, 1);
	mark[v] = true, V.clear();
	V.push_back(v);
	fl[0][v] = fl[1][v] = true;
	for (pii u : adj[v]){
		if (hide[u.A])
			continue;
		vec.clear();
		a[u.A] = u.B, DFS(u.A, v);
		for (int x : vec){
			V.push_back(x);
			for (pii y : Q[x])
				if (mark[y.A])
					ans[y.B] = (fl[1][y.A] && fl[0][x] && max(a[y.A], u.B) <= y.B);
			for (int y : QG[x])
				if (fl[0][x] && u.B <= y)
					ans[y] += gefen(y);
		}
		for (int x : vec)
			if (fl[1][x])
				mofen(a[x], 1), mark[x] = true;
	}
	for (pii y : Q[v])
		if (mark[y.A])
			ans[y.B] = (fl[1][y.A] && a[y.A] <= y.B);
	for (int y : QG[v])
		ans[y] += gefen(y);
	for (int x : V)
		if (fl[1][x])
			mofen(a[x], - 1), mark[x] = false;
	for (pii u : adj[v])
		if (!hide[u.A])
			solve(u.A);
}

int main(){
	fast_io;

	cin >> n >> k;
	for (int i = 1; i < n + k; ++ i){
		char c;
		int x, y;
		cin >> c;
		if (c == 'S'){
			cin >> x >> y;
			adj[x].push_back({y, i});
			adj[y].push_back({x, i});
		}
		else if (c == 'Q'){
			cin >> x >> y;
			Q[y].push_back({x, i});
			qt[i] = 1;
		}
		else{
			cin >> x;
			QG[x].push_back(i);
			qt[i] = 2;
		}
	}
	solve(1);
	for (int i = 1; i < n + k; ++ i){
		if (qt[i] == 2)
			cout << ans[i] << endl;
		else if (qt[i] == 1){
			if (ans[i])
				cout << "yes\n";
			else
				cout << "no\n";
		}
	}

	return 0;
}
/*
6 13
C 1
S 1 2
C 1
S 1 3
C 1
S 3 4
C 1
Q 5 1
S 4 5
S 1 6
Q 5 1
Q 1 5
C 1
C 2
C 3
C 4
C 5
C 6

*/
# Verdict Execution time Memory Grader output
1 Correct 40 ms 24640 KB Output is correct
2 Correct 53 ms 25224 KB Output is correct
3 Correct 51 ms 25216 KB Output is correct
4 Correct 55 ms 25408 KB Output is correct
5 Correct 53 ms 25984 KB Output is correct
6 Correct 52 ms 26180 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 40 ms 24640 KB Output is correct
2 Correct 53 ms 25224 KB Output is correct
3 Correct 51 ms 25216 KB Output is correct
4 Correct 55 ms 25408 KB Output is correct
5 Correct 53 ms 25984 KB Output is correct
6 Correct 52 ms 26180 KB Output is correct
7 Correct 50 ms 25540 KB Output is correct
8 Correct 58 ms 25824 KB Output is correct
9 Correct 52 ms 25736 KB Output is correct
10 Correct 61 ms 25924 KB Output is correct
11 Correct 57 ms 25704 KB Output is correct
12 Correct 50 ms 25524 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 39 ms 24628 KB Output is correct
2 Correct 211 ms 35920 KB Output is correct
3 Correct 233 ms 37008 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 39 ms 24628 KB Output is correct
2 Correct 211 ms 35920 KB Output is correct
3 Correct 233 ms 37008 KB Output is correct
4 Correct 40 ms 25528 KB Output is correct
5 Correct 200 ms 36508 KB Output is correct
6 Correct 137 ms 34192 KB Output is correct
7 Correct 149 ms 34400 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 39 ms 24636 KB Output is correct
2 Correct 415 ms 42616 KB Output is correct
3 Correct 413 ms 42592 KB Output is correct
4 Correct 278 ms 44796 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 39 ms 24636 KB Output is correct
2 Correct 415 ms 42616 KB Output is correct
3 Correct 413 ms 42592 KB Output is correct
4 Correct 278 ms 44796 KB Output is correct
5 Correct 40 ms 25540 KB Output is correct
6 Correct 437 ms 45876 KB Output is correct
7 Correct 298 ms 46016 KB Output is correct
8 Correct 412 ms 45008 KB Output is correct
9 Correct 403 ms 45156 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 39 ms 24660 KB Output is correct
2 Correct 255 ms 35320 KB Output is correct
3 Correct 314 ms 36920 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 39 ms 24660 KB Output is correct
2 Correct 255 ms 35320 KB Output is correct
3 Correct 314 ms 36920 KB Output is correct
4 Correct 39 ms 25484 KB Output is correct
5 Correct 281 ms 37244 KB Output is correct
6 Correct 335 ms 36916 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 39 ms 24580 KB Output is correct
2 Correct 391 ms 42632 KB Output is correct
3 Correct 364 ms 42584 KB Output is correct
4 Correct 297 ms 44932 KB Output is correct
5 Correct 40 ms 25540 KB Output is correct
6 Correct 250 ms 37080 KB Output is correct
7 Correct 309 ms 36952 KB Output is correct
8 Correct 341 ms 37548 KB Output is correct
9 Correct 396 ms 37960 KB Output is correct
10 Correct 411 ms 41788 KB Output is correct
11 Correct 446 ms 40492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 39 ms 24580 KB Output is correct
2 Correct 391 ms 42632 KB Output is correct
3 Correct 364 ms 42584 KB Output is correct
4 Correct 297 ms 44932 KB Output is correct
5 Correct 40 ms 25540 KB Output is correct
6 Correct 250 ms 37080 KB Output is correct
7 Correct 309 ms 36952 KB Output is correct
8 Correct 341 ms 37548 KB Output is correct
9 Correct 396 ms 37960 KB Output is correct
10 Correct 411 ms 41788 KB Output is correct
11 Correct 446 ms 40492 KB Output is correct
12 Correct 41 ms 25484 KB Output is correct
13 Correct 453 ms 45888 KB Output is correct
14 Correct 310 ms 45888 KB Output is correct
15 Correct 422 ms 45044 KB Output is correct
16 Correct 405 ms 45100 KB Output is correct
17 Correct 40 ms 25528 KB Output is correct
18 Correct 297 ms 37292 KB Output is correct
19 Correct 360 ms 36856 KB Output is correct
20 Correct 457 ms 37800 KB Output is correct
21 Correct 395 ms 38160 KB Output is correct
22 Correct 456 ms 40204 KB Output is correct
23 Correct 564 ms 40812 KB Output is correct
24 Correct 528 ms 40220 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 46 ms 24664 KB Output is correct
2 Correct 56 ms 25236 KB Output is correct
3 Correct 50 ms 25048 KB Output is correct
4 Correct 57 ms 25384 KB Output is correct
5 Correct 55 ms 25924 KB Output is correct
6 Correct 52 ms 26332 KB Output is correct
7 Correct 42 ms 25560 KB Output is correct
8 Correct 227 ms 36152 KB Output is correct
9 Correct 280 ms 36812 KB Output is correct
10 Correct 40 ms 25540 KB Output is correct
11 Correct 408 ms 45960 KB Output is correct
12 Correct 399 ms 45884 KB Output is correct
13 Correct 267 ms 45632 KB Output is correct
14 Correct 41 ms 25504 KB Output is correct
15 Correct 260 ms 37136 KB Output is correct
16 Correct 328 ms 36916 KB Output is correct
17 Correct 352 ms 37668 KB Output is correct
18 Correct 384 ms 38084 KB Output is correct
19 Correct 449 ms 41972 KB Output is correct
20 Correct 447 ms 40248 KB Output is correct
21 Correct 240 ms 37680 KB Output is correct
22 Correct 256 ms 37692 KB Output is correct
23 Correct 341 ms 37640 KB Output is correct
24 Correct 330 ms 37728 KB Output is correct
25 Correct 515 ms 41916 KB Output is correct
26 Correct 359 ms 35644 KB Output is correct
27 Correct 307 ms 35532 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 46 ms 24664 KB Output is correct
2 Correct 56 ms 25236 KB Output is correct
3 Correct 50 ms 25048 KB Output is correct
4 Correct 57 ms 25384 KB Output is correct
5 Correct 55 ms 25924 KB Output is correct
6 Correct 52 ms 26332 KB Output is correct
7 Correct 42 ms 25560 KB Output is correct
8 Correct 227 ms 36152 KB Output is correct
9 Correct 280 ms 36812 KB Output is correct
10 Correct 40 ms 25540 KB Output is correct
11 Correct 408 ms 45960 KB Output is correct
12 Correct 399 ms 45884 KB Output is correct
13 Correct 267 ms 45632 KB Output is correct
14 Correct 41 ms 25504 KB Output is correct
15 Correct 260 ms 37136 KB Output is correct
16 Correct 328 ms 36916 KB Output is correct
17 Correct 352 ms 37668 KB Output is correct
18 Correct 384 ms 38084 KB Output is correct
19 Correct 449 ms 41972 KB Output is correct
20 Correct 447 ms 40248 KB Output is correct
21 Correct 240 ms 37680 KB Output is correct
22 Correct 256 ms 37692 KB Output is correct
23 Correct 341 ms 37640 KB Output is correct
24 Correct 330 ms 37728 KB Output is correct
25 Correct 515 ms 41916 KB Output is correct
26 Correct 359 ms 35644 KB Output is correct
27 Correct 307 ms 35532 KB Output is correct
28 Correct 42 ms 25560 KB Output is correct
29 Correct 58 ms 25912 KB Output is correct
30 Correct 52 ms 25672 KB Output is correct
31 Correct 75 ms 25964 KB Output is correct
32 Correct 58 ms 25668 KB Output is correct
33 Correct 52 ms 25648 KB Output is correct
34 Correct 42 ms 25544 KB Output is correct
35 Correct 231 ms 36516 KB Output is correct
36 Correct 144 ms 34188 KB Output is correct
37 Correct 167 ms 34404 KB Output is correct
38 Correct 42 ms 25452 KB Output is correct
39 Correct 436 ms 45924 KB Output is correct
40 Correct 309 ms 45884 KB Output is correct
41 Correct 439 ms 45188 KB Output is correct
42 Correct 435 ms 45076 KB Output is correct
43 Correct 42 ms 25440 KB Output is correct
44 Correct 290 ms 37224 KB Output is correct
45 Correct 380 ms 36832 KB Output is correct
46 Correct 392 ms 37820 KB Output is correct
47 Correct 417 ms 38188 KB Output is correct
48 Correct 455 ms 40192 KB Output is correct
49 Correct 614 ms 40796 KB Output is correct
50 Correct 593 ms 40216 KB Output is correct
51 Correct 183 ms 35764 KB Output is correct
52 Correct 156 ms 35272 KB Output is correct
53 Correct 155 ms 34868 KB Output is correct
54 Correct 162 ms 35404 KB Output is correct
55 Correct 165 ms 35372 KB Output is correct
56 Correct 305 ms 36620 KB Output is correct
57 Correct 401 ms 39664 KB Output is correct
58 Correct 422 ms 36148 KB Output is correct
59 Correct 323 ms 35636 KB Output is correct