답안 #529362

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
529362 2022-02-22T21:45:15 Z getac Inside information (BOI21_servers) C++14
100 / 100
396 ms 41952 KB
#include<bits/stdc++.h>
#define X first
#define Y second
using namespace std;
typedef int ll;
typedef pair<ll, ll> pi;
const ll inf = 1e9 + 7, xn = 3e5 + 9;
vector<pi> g[xn], qg[xn];
vector<ll> cnt[xn];
ll ans[xn], f[xn], sz[xn], ti[xn];
bool vis[xn];
void dfs1(ll v, ll p)
{
	sz[v] = 1;
	for(pi u : g[v]) if(u.Y != p && !vis[u.Y])
	{
		dfs1(u.Y, v);
		sz[v] += sz[u.Y];
	}
}
ll dojob(ll v, ll p, ll m)
{
	ll mx = 0;
	for(pi u : g[v]) if(u.Y != p && !vis[u.Y] && sz[mx] < sz[u.Y]) mx = u.Y;
	if(max(m - sz[v], sz[mx]) * 2 <= m) return v;
	return dojob(mx, v, m);
}
inline ll get(ll x)
{
	ll ret = 0;
	while(x > 0) ret += f[x], x -= (x & -x);
	return ret;
}
inline void upd(ll x, ll y)
{
	while(x < xn) f[x] += y, x += (x & -x);
}
void dfs2(ll v, ll p, ll ls)
{
	ti[v] = ls;
	upd(ls, 1);
	for(pi u : g[v]) if(u.Y != p && !vis[u.Y] && ls <= u.X) dfs2(u.Y, v, u.X);
}
void dfs3(ll v, ll p, ll ls)
{
	ti[v] = inf;
	upd(ls, -1);
	for(pi u : g[v]) if(u.Y != p && !vis[u.Y] && ls <= u.X) dfs3(u.Y, v, u.X);
}
inline void pans(ll x)
{
	for(ll i : cnt[x]) ans[i] += get(i);
	for(pi i : qg[x]) if(ti[i.Y] <= i.X) ans[i.X] = -1;
}
void dfs4(ll v, ll p, ll ls)
{
	pans(v);
	for(pi u : g[v]) if(u.Y != p && !vis[u.Y] && u.X <= ls) dfs4(u.Y, v, u.X);
}
void solve(ll v, ll p)
{
	dfs1(v, 0);
	ll cen = dojob(v, 0, sz[v]);
	sort(g[cen].begin(), g[cen].end());
	dfs2(cen, 0, 1), pans(cen);
	for(pi u : g[cen]) if(u.Y != p && !vis[u.Y])
	{
		dfs3(u.Y, cen, u.X), upd(ti[cen], -1);
		ti[cen] = u.X;
		upd(ti[cen], 1), dfs4(u.Y, cen, u.X);
	}
	vis[cen] = 1;
	upd(ti[cen], -1);
	ti[cen] = inf;
	for(pi u : g[cen]) if(u.Y != p && !vis[u.Y]) solve(u.Y, cen);
}
int main()
{
	ios_base::sync_with_stdio(NULL);cin.tie(0);cout.tie(0);
	ll n, q;
	cin >> n >> q;
	q += n, sz[0] = 0;
	for(ll i = 1; i < q; i++)
	{
		ll x, y;
		char c;
		cin >> c;
		if(c == 'S')
		{
			cin >> x >> y;
			g[x].push_back({i, y}), g[y].push_back({i, x});
			ans[i] = -3;
		}
		else if(c == 'C')
		{
			cin >> x;
			cnt[x].push_back(i);
			ans[i] = 0;
		}
		else
		{
			cin >> x >> y;
			qg[y].push_back({i, x});
			ans[i] = -2;
		}
	}
	for(ll i = 0; i < n + 2; i++) ti[i] = inf;
	solve(1, 0);
	for(ll i = 1; i < q; i++)
	{
		if(ans[i] == -3) continue;
		if(ans[i] >= 0) cout << ans[i] << "\n";
		else
		{
			if(ans[i] == -2) cout << "no";
			else cout << "yes";
			cout << "\n";
		}
	}
}
# 결과 실행 시간 메모리 Grader output
1 Correct 32 ms 25048 KB Output is correct
2 Correct 41 ms 26004 KB Output is correct
3 Correct 39 ms 25812 KB Output is correct
4 Correct 42 ms 26048 KB Output is correct
5 Correct 43 ms 25828 KB Output is correct
6 Correct 48 ms 25776 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 32 ms 25048 KB Output is correct
2 Correct 41 ms 26004 KB Output is correct
3 Correct 39 ms 25812 KB Output is correct
4 Correct 42 ms 26048 KB Output is correct
5 Correct 43 ms 25828 KB Output is correct
6 Correct 48 ms 25776 KB Output is correct
7 Correct 33 ms 25044 KB Output is correct
8 Correct 61 ms 25288 KB Output is correct
9 Correct 40 ms 25208 KB Output is correct
10 Correct 47 ms 25364 KB Output is correct
11 Correct 49 ms 25236 KB Output is correct
12 Correct 42 ms 25040 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 32 ms 25040 KB Output is correct
2 Correct 150 ms 34552 KB Output is correct
3 Correct 159 ms 34580 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 32 ms 25040 KB Output is correct
2 Correct 150 ms 34552 KB Output is correct
3 Correct 159 ms 34580 KB Output is correct
4 Correct 36 ms 25192 KB Output is correct
5 Correct 153 ms 34200 KB Output is correct
6 Correct 104 ms 31968 KB Output is correct
7 Correct 120 ms 32056 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 31 ms 25028 KB Output is correct
2 Correct 224 ms 41716 KB Output is correct
3 Correct 242 ms 41884 KB Output is correct
4 Correct 191 ms 41572 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 31 ms 25028 KB Output is correct
2 Correct 224 ms 41716 KB Output is correct
3 Correct 242 ms 41884 KB Output is correct
4 Correct 191 ms 41572 KB Output is correct
5 Correct 38 ms 24992 KB Output is correct
6 Correct 241 ms 41880 KB Output is correct
7 Correct 214 ms 41876 KB Output is correct
8 Correct 249 ms 41212 KB Output is correct
9 Correct 233 ms 41044 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 31 ms 25120 KB Output is correct
2 Correct 193 ms 35180 KB Output is correct
3 Correct 187 ms 35248 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 31 ms 25120 KB Output is correct
2 Correct 193 ms 35180 KB Output is correct
3 Correct 187 ms 35248 KB Output is correct
4 Correct 32 ms 25144 KB Output is correct
5 Correct 229 ms 35092 KB Output is correct
6 Correct 199 ms 35176 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 32 ms 25044 KB Output is correct
2 Correct 233 ms 41812 KB Output is correct
3 Correct 224 ms 41812 KB Output is correct
4 Correct 198 ms 41568 KB Output is correct
5 Correct 32 ms 25028 KB Output is correct
6 Correct 189 ms 34884 KB Output is correct
7 Correct 206 ms 35268 KB Output is correct
8 Correct 181 ms 35648 KB Output is correct
9 Correct 223 ms 35840 KB Output is correct
10 Correct 238 ms 38896 KB Output is correct
11 Correct 260 ms 37412 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 32 ms 25044 KB Output is correct
2 Correct 233 ms 41812 KB Output is correct
3 Correct 224 ms 41812 KB Output is correct
4 Correct 198 ms 41568 KB Output is correct
5 Correct 32 ms 25028 KB Output is correct
6 Correct 189 ms 34884 KB Output is correct
7 Correct 206 ms 35268 KB Output is correct
8 Correct 181 ms 35648 KB Output is correct
9 Correct 223 ms 35840 KB Output is correct
10 Correct 238 ms 38896 KB Output is correct
11 Correct 260 ms 37412 KB Output is correct
12 Correct 32 ms 25044 KB Output is correct
13 Correct 252 ms 41804 KB Output is correct
14 Correct 210 ms 41860 KB Output is correct
15 Correct 242 ms 40944 KB Output is correct
16 Correct 234 ms 40932 KB Output is correct
17 Correct 33 ms 25040 KB Output is correct
18 Correct 210 ms 35140 KB Output is correct
19 Correct 202 ms 35140 KB Output is correct
20 Correct 200 ms 35652 KB Output is correct
21 Correct 231 ms 36008 KB Output is correct
22 Correct 289 ms 37512 KB Output is correct
23 Correct 396 ms 38672 KB Output is correct
24 Correct 324 ms 38100 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 34 ms 25028 KB Output is correct
2 Correct 45 ms 26044 KB Output is correct
3 Correct 39 ms 25796 KB Output is correct
4 Correct 42 ms 26160 KB Output is correct
5 Correct 43 ms 25796 KB Output is correct
6 Correct 40 ms 25692 KB Output is correct
7 Correct 36 ms 25048 KB Output is correct
8 Correct 157 ms 34576 KB Output is correct
9 Correct 165 ms 34500 KB Output is correct
10 Correct 38 ms 25040 KB Output is correct
11 Correct 253 ms 41812 KB Output is correct
12 Correct 225 ms 41748 KB Output is correct
13 Correct 193 ms 41516 KB Output is correct
14 Correct 32 ms 25044 KB Output is correct
15 Correct 182 ms 35012 KB Output is correct
16 Correct 189 ms 35168 KB Output is correct
17 Correct 187 ms 35580 KB Output is correct
18 Correct 194 ms 35812 KB Output is correct
19 Correct 245 ms 38920 KB Output is correct
20 Correct 236 ms 37412 KB Output is correct
21 Correct 178 ms 35168 KB Output is correct
22 Correct 185 ms 35088 KB Output is correct
23 Correct 176 ms 35372 KB Output is correct
24 Correct 178 ms 35452 KB Output is correct
25 Correct 262 ms 38548 KB Output is correct
26 Correct 243 ms 34368 KB Output is correct
27 Correct 198 ms 34328 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 34 ms 25028 KB Output is correct
2 Correct 45 ms 26044 KB Output is correct
3 Correct 39 ms 25796 KB Output is correct
4 Correct 42 ms 26160 KB Output is correct
5 Correct 43 ms 25796 KB Output is correct
6 Correct 40 ms 25692 KB Output is correct
7 Correct 36 ms 25048 KB Output is correct
8 Correct 157 ms 34576 KB Output is correct
9 Correct 165 ms 34500 KB Output is correct
10 Correct 38 ms 25040 KB Output is correct
11 Correct 253 ms 41812 KB Output is correct
12 Correct 225 ms 41748 KB Output is correct
13 Correct 193 ms 41516 KB Output is correct
14 Correct 32 ms 25044 KB Output is correct
15 Correct 182 ms 35012 KB Output is correct
16 Correct 189 ms 35168 KB Output is correct
17 Correct 187 ms 35580 KB Output is correct
18 Correct 194 ms 35812 KB Output is correct
19 Correct 245 ms 38920 KB Output is correct
20 Correct 236 ms 37412 KB Output is correct
21 Correct 178 ms 35168 KB Output is correct
22 Correct 185 ms 35088 KB Output is correct
23 Correct 176 ms 35372 KB Output is correct
24 Correct 178 ms 35452 KB Output is correct
25 Correct 262 ms 38548 KB Output is correct
26 Correct 243 ms 34368 KB Output is correct
27 Correct 198 ms 34328 KB Output is correct
28 Correct 32 ms 25048 KB Output is correct
29 Correct 44 ms 25288 KB Output is correct
30 Correct 39 ms 25188 KB Output is correct
31 Correct 43 ms 25412 KB Output is correct
32 Correct 44 ms 25168 KB Output is correct
33 Correct 46 ms 25024 KB Output is correct
34 Correct 32 ms 25116 KB Output is correct
35 Correct 166 ms 34248 KB Output is correct
36 Correct 110 ms 31936 KB Output is correct
37 Correct 110 ms 32056 KB Output is correct
38 Correct 32 ms 25028 KB Output is correct
39 Correct 248 ms 41868 KB Output is correct
40 Correct 211 ms 41952 KB Output is correct
41 Correct 245 ms 41028 KB Output is correct
42 Correct 224 ms 41028 KB Output is correct
43 Correct 32 ms 25028 KB Output is correct
44 Correct 221 ms 35428 KB Output is correct
45 Correct 195 ms 35192 KB Output is correct
46 Correct 194 ms 35608 KB Output is correct
47 Correct 232 ms 36004 KB Output is correct
48 Correct 288 ms 37464 KB Output is correct
49 Correct 394 ms 38476 KB Output is correct
50 Correct 320 ms 38080 KB Output is correct
51 Correct 129 ms 33244 KB Output is correct
52 Correct 113 ms 32972 KB Output is correct
53 Correct 105 ms 32436 KB Output is correct
54 Correct 126 ms 33156 KB Output is correct
55 Correct 114 ms 32812 KB Output is correct
56 Correct 178 ms 34628 KB Output is correct
57 Correct 217 ms 36112 KB Output is correct
58 Correct 284 ms 34808 KB Output is correct
59 Correct 211 ms 34360 KB Output is correct