Submission #571011

# Submission time Handle Problem Language Result Execution time Memory
571011 2022-06-01T03:03:55 Z jjang36524 Inside information (BOI21_servers) C++14
100 / 100
557 ms 66952 KB
#include <iostream>
#include <algorithm>
#include <vector>
#include <string.h>
#pragma warning(disable:4996)
#define int long long
using namespace std;
int siz[500100];
int done[500100];
int ans[520100];
vector<pair<int, int>>chkq[520100];
vector<int>q[520100];
vector<pair<int, int>>t[500100];
int N, K;
bool cmp(pair<int, int>a, pair<int, int>b)
{
	if (a.second != b.second)
		return a.second < b.second;
	return a < b;
}
int sz(int n, int par)
{
	int i;
	siz[n] = 1;
	for (i = 0; i < t[n].size(); i++)
	{
		if (done[t[n][i].first] || t[n][i].first == par)
			continue;
		siz[n] += sz(t[n][i].first, n);
	}
	return siz[n];
}
int rt[500100];
int fw[500100];
void u(int n, int k)
{
	while (n <= N +K)
	{
		fw[n] += k;
		n += n & -n;
	}
}
int res(int n)
{
	int ans = 0;
	while (n)
	{
		ans += fw[n];
		n -= n & -n;
	}
	return ans;
}
void intcal(int n, int p, int lv)
{
	rt[n] = lv;
	u(lv, 1);
	int i;
	for (i = 0; i < t[n].size(); i++)
	{
		if (t[n][i].first != p && !done[t[n][i].first] && t[n][i].second >= lv)
		{
			intcal(t[n][i].first, n, t[n][i].second);
		}
	}
}
void leave(int n, int p, int lv)
{
	rt[n] = 998244353;
	u(lv, -1);
	int i;
	for (i = 0; i < t[n].size(); i++)
	{
		if (t[n][i].first != p && !done[t[n][i].first] && t[n][i].second >= lv)
		{
			leave(t[n][i].first, n, t[n][i].second);
		}
	}
}
void givans(int n)
{
	int i;
	for (i = 0; i < chkq[n].size(); i++)
	{
		if (rt[chkq[n][i].first] <= chkq[n][i].second)
			ans[chkq[n][i].second] = -1;
	}
	for (i = 0; i < q[n].size(); i++)
	{
		ans[q[n][i]] += res(q[n][i]);
	}
}
void soldfs(int n, int p, int lv)
{
	givans(n);
	int i;
	for (i = 0; i < t[n].size(); i++)
	{
		if (t[n][i].first != p && !done[t[n][i].first] && t[n][i].second <= lv)
		{
			soldfs(t[n][i].first, n, t[n][i].second);
		}
	}
}
int getsen(int n, int par, int lim)
{
	int i;
	for (i = 0; i < t[n].size(); i++)
	{
		if (done[t[n][i].first] || t[n][i].first == par)
			continue;
		if (lim < siz[t[n][i].first])
			return getsen(t[n][i].first, n, lim);
	}
	return n;
}

void cendec(int n,int p)
{
	sz(n, -1);
	int r = getsen(n, -1, siz[n] / 2);
	int i;
	sort(t[r].begin(), t[r].end(),cmp);
	intcal(r, 0, 1);
	givans(r);
	
	for (i = 0; i < t[r].size(); i++)
	{
		if (t[r][i].first != p && !done[t[r][i].first])
		{
			leave(t[r][i].first, r, t[r][i].second);
			u(rt[r], -1);
			rt[r] = t[r][i].second;
			u(rt[r], 1);
			soldfs(t[r][i].first, r, t[r][i].second);
		}
	}
	done[r] = 1;
	u(rt[r], -1);
	rt[r] = 998244353;
	for (i = 0; i < t[r].size(); i++)
	{
		if (t[r][i].first != p && !done[t[r][i].first])
		{
			cendec(t[r][i].first, r);
		}
	}
}
signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin >> N >> K;
	int i;
	for (i = 1; i < N+K; i++)
	{
		char a;
		cin >> a;
		if (a == 'S')
		{
			int b, c;
			cin >> b >> c;
			t[b].push_back({ c,i+1});
			t[c].push_back({ b,i+1 });
			ans[i+1] = -3;
		}
		else if (a == 'Q')
		{
			int b, c;
			cin >> b >> c;
			chkq[c].push_back({ b,i+1 });
			ans[i+1] = -2;
		}
		else
		{
			int b;
			cin >> b;
			q[b].push_back(i+1);
		}
	}
	memset(rt, 1, sizeof(rt));
	cendec(1,0);
	for (i = 2; i <= N + K; i++)
	{
		if (ans[i] >= -2)
		{
			if (ans[i] == -2)
				cout << "no" << '\n';
			else if (ans[i] == -1)
				cout << "yes" << '\n';
			else
				cout << ans[i] << '\n';
		}
	}
}

Compilation message

servers.cpp:5: warning: ignoring '#pragma warning ' [-Wunknown-pragmas]
    5 | #pragma warning(disable:4996)
      | 
servers.cpp: In function 'long long int sz(long long int, long long int)':
servers.cpp:25:16: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   25 |  for (i = 0; i < t[n].size(); i++)
      |              ~~^~~~~~~~~~~~~
servers.cpp: In function 'void intcal(long long int, long long int, long long int)':
servers.cpp:58:16: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   58 |  for (i = 0; i < t[n].size(); i++)
      |              ~~^~~~~~~~~~~~~
servers.cpp: In function 'void leave(long long int, long long int, long long int)':
servers.cpp:71:16: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   71 |  for (i = 0; i < t[n].size(); i++)
      |              ~~^~~~~~~~~~~~~
servers.cpp: In function 'void givans(long long int)':
servers.cpp:82:16: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   82 |  for (i = 0; i < chkq[n].size(); i++)
      |              ~~^~~~~~~~~~~~~~~~
servers.cpp:87:16: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   87 |  for (i = 0; i < q[n].size(); i++)
      |              ~~^~~~~~~~~~~~~
servers.cpp: In function 'void soldfs(long long int, long long int, long long int)':
servers.cpp:96:16: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   96 |  for (i = 0; i < t[n].size(); i++)
      |              ~~^~~~~~~~~~~~~
servers.cpp: In function 'long long int getsen(long long int, long long int, long long int)':
servers.cpp:107:16: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  107 |  for (i = 0; i < t[n].size(); i++)
      |              ~~^~~~~~~~~~~~~
servers.cpp: In function 'void cendec(long long int, long long int)':
servers.cpp:126:16: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  126 |  for (i = 0; i < t[r].size(); i++)
      |              ~~^~~~~~~~~~~~~
servers.cpp:140:16: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  140 |  for (i = 0; i < t[r].size(); i++)
      |              ~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 42 ms 45264 KB Output is correct
2 Correct 50 ms 46172 KB Output is correct
3 Correct 52 ms 47208 KB Output is correct
4 Correct 54 ms 47624 KB Output is correct
5 Correct 55 ms 47032 KB Output is correct
6 Correct 52 ms 46880 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 42 ms 45264 KB Output is correct
2 Correct 50 ms 46172 KB Output is correct
3 Correct 52 ms 47208 KB Output is correct
4 Correct 54 ms 47624 KB Output is correct
5 Correct 55 ms 47032 KB Output is correct
6 Correct 52 ms 46880 KB Output is correct
7 Correct 44 ms 45868 KB Output is correct
8 Correct 57 ms 46376 KB Output is correct
9 Correct 55 ms 46200 KB Output is correct
10 Correct 58 ms 46428 KB Output is correct
11 Correct 55 ms 45772 KB Output is correct
12 Correct 51 ms 45596 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 39 ms 45260 KB Output is correct
2 Correct 206 ms 55176 KB Output is correct
3 Correct 214 ms 58056 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 39 ms 45260 KB Output is correct
2 Correct 206 ms 55176 KB Output is correct
3 Correct 214 ms 58056 KB Output is correct
4 Correct 42 ms 45800 KB Output is correct
5 Correct 212 ms 57532 KB Output is correct
6 Correct 138 ms 54968 KB Output is correct
7 Correct 148 ms 55148 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 40 ms 45260 KB Output is correct
2 Correct 326 ms 63616 KB Output is correct
3 Correct 281 ms 66952 KB Output is correct
4 Correct 223 ms 66048 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 40 ms 45260 KB Output is correct
2 Correct 326 ms 63616 KB Output is correct
3 Correct 281 ms 66952 KB Output is correct
4 Correct 223 ms 66048 KB Output is correct
5 Correct 45 ms 45768 KB Output is correct
6 Correct 306 ms 66388 KB Output is correct
7 Correct 252 ms 65812 KB Output is correct
8 Correct 288 ms 65652 KB Output is correct
9 Correct 281 ms 65468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 40 ms 45236 KB Output is correct
2 Correct 225 ms 55808 KB Output is correct
3 Correct 251 ms 59840 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 40 ms 45236 KB Output is correct
2 Correct 225 ms 55808 KB Output is correct
3 Correct 251 ms 59840 KB Output is correct
4 Correct 43 ms 45916 KB Output is correct
5 Correct 254 ms 58968 KB Output is correct
6 Correct 266 ms 59340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 42 ms 45252 KB Output is correct
2 Correct 325 ms 63644 KB Output is correct
3 Correct 282 ms 66840 KB Output is correct
4 Correct 244 ms 65868 KB Output is correct
5 Correct 44 ms 46148 KB Output is correct
6 Correct 214 ms 59084 KB Output is correct
7 Correct 240 ms 59800 KB Output is correct
8 Correct 249 ms 59536 KB Output is correct
9 Correct 278 ms 60476 KB Output is correct
10 Correct 305 ms 63488 KB Output is correct
11 Correct 321 ms 62000 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 42 ms 45252 KB Output is correct
2 Correct 325 ms 63644 KB Output is correct
3 Correct 282 ms 66840 KB Output is correct
4 Correct 244 ms 65868 KB Output is correct
5 Correct 44 ms 46148 KB Output is correct
6 Correct 214 ms 59084 KB Output is correct
7 Correct 240 ms 59800 KB Output is correct
8 Correct 249 ms 59536 KB Output is correct
9 Correct 278 ms 60476 KB Output is correct
10 Correct 305 ms 63488 KB Output is correct
11 Correct 321 ms 62000 KB Output is correct
12 Correct 43 ms 45896 KB Output is correct
13 Correct 311 ms 66392 KB Output is correct
14 Correct 260 ms 65764 KB Output is correct
15 Correct 283 ms 65496 KB Output is correct
16 Correct 302 ms 65548 KB Output is correct
17 Correct 43 ms 45872 KB Output is correct
18 Correct 257 ms 58832 KB Output is correct
19 Correct 270 ms 59280 KB Output is correct
20 Correct 316 ms 59132 KB Output is correct
21 Correct 304 ms 60092 KB Output is correct
22 Correct 402 ms 61444 KB Output is correct
23 Correct 557 ms 62732 KB Output is correct
24 Correct 502 ms 62612 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 43 ms 45340 KB Output is correct
2 Correct 59 ms 46312 KB Output is correct
3 Correct 53 ms 47100 KB Output is correct
4 Correct 56 ms 47692 KB Output is correct
5 Correct 54 ms 46908 KB Output is correct
6 Correct 53 ms 46812 KB Output is correct
7 Correct 44 ms 46136 KB Output is correct
8 Correct 195 ms 58040 KB Output is correct
9 Correct 213 ms 58040 KB Output is correct
10 Correct 43 ms 46184 KB Output is correct
11 Correct 294 ms 66944 KB Output is correct
12 Correct 273 ms 66836 KB Output is correct
13 Correct 223 ms 65868 KB Output is correct
14 Correct 43 ms 46128 KB Output is correct
15 Correct 223 ms 59088 KB Output is correct
16 Correct 236 ms 59792 KB Output is correct
17 Correct 240 ms 59472 KB Output is correct
18 Correct 258 ms 60492 KB Output is correct
19 Correct 321 ms 63420 KB Output is correct
20 Correct 313 ms 62064 KB Output is correct
21 Correct 208 ms 58500 KB Output is correct
22 Correct 235 ms 58664 KB Output is correct
23 Correct 223 ms 59176 KB Output is correct
24 Correct 279 ms 59340 KB Output is correct
25 Correct 293 ms 62440 KB Output is correct
26 Correct 272 ms 58920 KB Output is correct
27 Correct 286 ms 59264 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 43 ms 45340 KB Output is correct
2 Correct 59 ms 46312 KB Output is correct
3 Correct 53 ms 47100 KB Output is correct
4 Correct 56 ms 47692 KB Output is correct
5 Correct 54 ms 46908 KB Output is correct
6 Correct 53 ms 46812 KB Output is correct
7 Correct 44 ms 46136 KB Output is correct
8 Correct 195 ms 58040 KB Output is correct
9 Correct 213 ms 58040 KB Output is correct
10 Correct 43 ms 46184 KB Output is correct
11 Correct 294 ms 66944 KB Output is correct
12 Correct 273 ms 66836 KB Output is correct
13 Correct 223 ms 65868 KB Output is correct
14 Correct 43 ms 46128 KB Output is correct
15 Correct 223 ms 59088 KB Output is correct
16 Correct 236 ms 59792 KB Output is correct
17 Correct 240 ms 59472 KB Output is correct
18 Correct 258 ms 60492 KB Output is correct
19 Correct 321 ms 63420 KB Output is correct
20 Correct 313 ms 62064 KB Output is correct
21 Correct 208 ms 58500 KB Output is correct
22 Correct 235 ms 58664 KB Output is correct
23 Correct 223 ms 59176 KB Output is correct
24 Correct 279 ms 59340 KB Output is correct
25 Correct 293 ms 62440 KB Output is correct
26 Correct 272 ms 58920 KB Output is correct
27 Correct 286 ms 59264 KB Output is correct
28 Correct 44 ms 45772 KB Output is correct
29 Correct 58 ms 46372 KB Output is correct
30 Correct 55 ms 46116 KB Output is correct
31 Correct 60 ms 46436 KB Output is correct
32 Correct 57 ms 45716 KB Output is correct
33 Correct 55 ms 45568 KB Output is correct
34 Correct 43 ms 45800 KB Output is correct
35 Correct 216 ms 57520 KB Output is correct
36 Correct 135 ms 55000 KB Output is correct
37 Correct 150 ms 55224 KB Output is correct
38 Correct 44 ms 45868 KB Output is correct
39 Correct 302 ms 66388 KB Output is correct
40 Correct 249 ms 65768 KB Output is correct
41 Correct 298 ms 65564 KB Output is correct
42 Correct 290 ms 65520 KB Output is correct
43 Correct 44 ms 45888 KB Output is correct
44 Correct 257 ms 58784 KB Output is correct
45 Correct 253 ms 59304 KB Output is correct
46 Correct 304 ms 59220 KB Output is correct
47 Correct 277 ms 60108 KB Output is correct
48 Correct 392 ms 61388 KB Output is correct
49 Correct 481 ms 62840 KB Output is correct
50 Correct 476 ms 62508 KB Output is correct
51 Correct 166 ms 56244 KB Output is correct
52 Correct 145 ms 56060 KB Output is correct
53 Correct 156 ms 55580 KB Output is correct
54 Correct 153 ms 56220 KB Output is correct
55 Correct 154 ms 55976 KB Output is correct
56 Correct 213 ms 58012 KB Output is correct
57 Correct 267 ms 59880 KB Output is correct
58 Correct 392 ms 58156 KB Output is correct
59 Correct 282 ms 59124 KB Output is correct