Submission #642335

# Submission time Handle Problem Language Result Execution time Memory
642335 2022-09-19T08:55:13 Z dozer Joker (BOI20_joker) C++14
39 / 100
1111 ms 262144 KB
#include <bits/stdc++.h>
using namespace std;
#define fileio() freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout)
#define fastio() cin.tie(0), ios_base::sync_with_stdio(0)
#define sp " "
#define endl "\n"
#define pb push_back
#define pii pair<int, int>
#define st first
#define nd second
#define N 400005

const int modulo = 1e9 + 7;
int ans[N], u[N], v[N], l[N], r[N], n, sz[N];
vector<int> ind[N], root, gh[N];
map<int, int> res[N];

int find(vector<int> &b, int node)
{
	if (node < 0) return -(find(b, -node));
	if (node == b[node]) return node;
	return b[node] = find(b, b[node]);
}


int32_t main()
{
	fastio();


	int m, q;
	cin>>n>>m>>q;
	root.resize(n + 5, 0);
	for (int i = 1; i <= n; i++)
		root[i] = i;

	for (int i = 1; i <= m; i++)
	{
		cin>>u[i]>>v[i];
	}

	int maks = 0;
	for (int i = 1; i <= q; i++)
	{
		cin>>l[i]>>r[i];
		maks = max(maks, l[i]);
		ind[l[i]].pb(r[i]);
	}


	for (int t = 1; t <= maks; t++)
	{
		for (int i = 1; i <= n; i++) root[i] = i;
		for (int i = 1; i < t; i++)
		{
			if (ans[i] == 1) 
			{
				ans[i + 1] = 1;
				continue;
			}
			int a = find(root, u[i]), b = find(root, v[i]);
			if (a == b) 
			{
				ans[i + 1] = 1;
			}
			else
			{
				if (sz[abs(a)] > sz[abs(b)]) swap(a, b);
				if (a < 0) a *= -1, b *= -1;
				root[a] = -b;
			}		
		}
		if (ans[t] == 1) res[t][m] = 1;
		for (int i = m; i >= t; i--)
		{
			if (res[t][i] == 1) 
			{
				res[t][i - 1] = 1;
				continue;
			}
			int a = find(root, u[i]), b = find(root, v[i]);
			if (a == b) 
			{
				res[t][i - 1] = 1;
			}
			else
			{
				if (sz[abs(a)] > sz[abs(b)]) swap(a, b);
				if (a < 0) a *= -1, b *= -1;
				root[a] = -b;
			}
			//cout<<i<<sp<<ans[i]<<endl;
		}
	}

	for (int i = 1; i <= q; i++)
	{
		if (res[l[i]][r[i]]) cout<<"YES\n";
		else cout<<"NO\n";
	}
		
	cerr<<"time taken : "<<(float)clock() / CLOCKS_PER_SEC<<" seconds\n";
}
# Verdict Execution time Memory Grader output
1 Correct 19 ms 37844 KB Output is correct
2 Correct 18 ms 37844 KB Output is correct
3 Correct 18 ms 37836 KB Output is correct
4 Correct 21 ms 37824 KB Output is correct
5 Correct 18 ms 37856 KB Output is correct
6 Correct 18 ms 37904 KB Output is correct
7 Correct 19 ms 38076 KB Output is correct
8 Correct 23 ms 38652 KB Output is correct
9 Correct 22 ms 38792 KB Output is correct
10 Correct 22 ms 38796 KB Output is correct
11 Correct 21 ms 38772 KB Output is correct
12 Correct 23 ms 38856 KB Output is correct
13 Correct 24 ms 38800 KB Output is correct
14 Correct 24 ms 38824 KB Output is correct
15 Correct 23 ms 38792 KB Output is correct
16 Correct 23 ms 38868 KB Output is correct
17 Correct 27 ms 38800 KB Output is correct
18 Correct 22 ms 38732 KB Output is correct
19 Correct 23 ms 38868 KB Output is correct
20 Correct 24 ms 38784 KB Output is correct
21 Correct 24 ms 38892 KB Output is correct
22 Correct 24 ms 38928 KB Output is correct
23 Correct 24 ms 38868 KB Output is correct
24 Correct 23 ms 38820 KB Output is correct
25 Correct 23 ms 38868 KB Output is correct
26 Correct 24 ms 38888 KB Output is correct
27 Correct 22 ms 38868 KB Output is correct
28 Correct 24 ms 38788 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 19 ms 37844 KB Output is correct
2 Correct 18 ms 37844 KB Output is correct
3 Correct 18 ms 37836 KB Output is correct
4 Correct 21 ms 37824 KB Output is correct
5 Correct 18 ms 37856 KB Output is correct
6 Correct 18 ms 37904 KB Output is correct
7 Correct 19 ms 38076 KB Output is correct
8 Correct 23 ms 38652 KB Output is correct
9 Correct 22 ms 38792 KB Output is correct
10 Correct 22 ms 38796 KB Output is correct
11 Correct 21 ms 38772 KB Output is correct
12 Correct 23 ms 38856 KB Output is correct
13 Correct 24 ms 38800 KB Output is correct
14 Correct 24 ms 38824 KB Output is correct
15 Correct 23 ms 38792 KB Output is correct
16 Correct 23 ms 38868 KB Output is correct
17 Correct 27 ms 38800 KB Output is correct
18 Correct 22 ms 38732 KB Output is correct
19 Correct 23 ms 38868 KB Output is correct
20 Correct 24 ms 38784 KB Output is correct
21 Correct 24 ms 38892 KB Output is correct
22 Correct 24 ms 38928 KB Output is correct
23 Correct 24 ms 38868 KB Output is correct
24 Correct 23 ms 38820 KB Output is correct
25 Correct 23 ms 38868 KB Output is correct
26 Correct 24 ms 38888 KB Output is correct
27 Correct 22 ms 38868 KB Output is correct
28 Correct 24 ms 38788 KB Output is correct
29 Correct 96 ms 61408 KB Output is correct
30 Correct 232 ms 114244 KB Output is correct
31 Correct 282 ms 132060 KB Output is correct
32 Correct 287 ms 132152 KB Output is correct
33 Correct 265 ms 132004 KB Output is correct
34 Correct 271 ms 131792 KB Output is correct
35 Correct 292 ms 132108 KB Output is correct
36 Correct 283 ms 131704 KB Output is correct
37 Correct 308 ms 131972 KB Output is correct
38 Correct 298 ms 131956 KB Output is correct
39 Correct 300 ms 132044 KB Output is correct
40 Correct 271 ms 131900 KB Output is correct
41 Correct 278 ms 131788 KB Output is correct
42 Correct 278 ms 131944 KB Output is correct
43 Correct 283 ms 131972 KB Output is correct
44 Correct 286 ms 132016 KB Output is correct
45 Correct 285 ms 131980 KB Output is correct
46 Correct 287 ms 132064 KB Output is correct
47 Correct 288 ms 132044 KB Output is correct
48 Correct 278 ms 131984 KB Output is correct
49 Correct 281 ms 132004 KB Output is correct
50 Correct 283 ms 132064 KB Output is correct
51 Correct 294 ms 132000 KB Output is correct
52 Correct 296 ms 131972 KB Output is correct
53 Correct 288 ms 132044 KB Output is correct
54 Correct 289 ms 132040 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 19 ms 37844 KB Output is correct
2 Correct 18 ms 37844 KB Output is correct
3 Correct 161 ms 52624 KB Output is correct
4 Correct 160 ms 52796 KB Output is correct
5 Correct 167 ms 52552 KB Output is correct
6 Correct 158 ms 52552 KB Output is correct
7 Correct 159 ms 52168 KB Output is correct
8 Correct 164 ms 52216 KB Output is correct
9 Correct 169 ms 52372 KB Output is correct
10 Correct 162 ms 52752 KB Output is correct
11 Correct 157 ms 52260 KB Output is correct
12 Correct 156 ms 52788 KB Output is correct
13 Correct 159 ms 51936 KB Output is correct
14 Correct 161 ms 52000 KB Output is correct
15 Correct 161 ms 52408 KB Output is correct
16 Correct 163 ms 52556 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 19 ms 37844 KB Output is correct
2 Correct 18 ms 37844 KB Output is correct
3 Correct 18 ms 37836 KB Output is correct
4 Correct 21 ms 37824 KB Output is correct
5 Correct 18 ms 37856 KB Output is correct
6 Correct 18 ms 37904 KB Output is correct
7 Correct 19 ms 38076 KB Output is correct
8 Correct 23 ms 38652 KB Output is correct
9 Correct 22 ms 38792 KB Output is correct
10 Correct 22 ms 38796 KB Output is correct
11 Correct 21 ms 38772 KB Output is correct
12 Correct 23 ms 38856 KB Output is correct
13 Correct 24 ms 38800 KB Output is correct
14 Correct 24 ms 38824 KB Output is correct
15 Correct 23 ms 38792 KB Output is correct
16 Correct 23 ms 38868 KB Output is correct
17 Correct 27 ms 38800 KB Output is correct
18 Correct 22 ms 38732 KB Output is correct
19 Correct 23 ms 38868 KB Output is correct
20 Correct 24 ms 38784 KB Output is correct
21 Correct 24 ms 38892 KB Output is correct
22 Correct 24 ms 38928 KB Output is correct
23 Correct 24 ms 38868 KB Output is correct
24 Correct 23 ms 38820 KB Output is correct
25 Correct 23 ms 38868 KB Output is correct
26 Correct 24 ms 38888 KB Output is correct
27 Correct 22 ms 38868 KB Output is correct
28 Correct 24 ms 38788 KB Output is correct
29 Correct 161 ms 52624 KB Output is correct
30 Correct 160 ms 52796 KB Output is correct
31 Correct 167 ms 52552 KB Output is correct
32 Correct 158 ms 52552 KB Output is correct
33 Correct 159 ms 52168 KB Output is correct
34 Correct 164 ms 52216 KB Output is correct
35 Correct 169 ms 52372 KB Output is correct
36 Correct 162 ms 52752 KB Output is correct
37 Correct 157 ms 52260 KB Output is correct
38 Correct 156 ms 52788 KB Output is correct
39 Correct 159 ms 51936 KB Output is correct
40 Correct 161 ms 52000 KB Output is correct
41 Correct 161 ms 52408 KB Output is correct
42 Correct 163 ms 52556 KB Output is correct
43 Runtime error 1111 ms 262144 KB Execution killed with signal 9
44 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 19 ms 37844 KB Output is correct
2 Correct 18 ms 37844 KB Output is correct
3 Correct 18 ms 37836 KB Output is correct
4 Correct 21 ms 37824 KB Output is correct
5 Correct 18 ms 37856 KB Output is correct
6 Correct 18 ms 37904 KB Output is correct
7 Correct 19 ms 38076 KB Output is correct
8 Correct 23 ms 38652 KB Output is correct
9 Correct 22 ms 38792 KB Output is correct
10 Correct 22 ms 38796 KB Output is correct
11 Correct 21 ms 38772 KB Output is correct
12 Correct 23 ms 38856 KB Output is correct
13 Correct 24 ms 38800 KB Output is correct
14 Correct 24 ms 38824 KB Output is correct
15 Correct 23 ms 38792 KB Output is correct
16 Correct 23 ms 38868 KB Output is correct
17 Correct 27 ms 38800 KB Output is correct
18 Correct 22 ms 38732 KB Output is correct
19 Correct 23 ms 38868 KB Output is correct
20 Correct 24 ms 38784 KB Output is correct
21 Correct 24 ms 38892 KB Output is correct
22 Correct 24 ms 38928 KB Output is correct
23 Correct 24 ms 38868 KB Output is correct
24 Correct 23 ms 38820 KB Output is correct
25 Correct 23 ms 38868 KB Output is correct
26 Correct 24 ms 38888 KB Output is correct
27 Correct 22 ms 38868 KB Output is correct
28 Correct 24 ms 38788 KB Output is correct
29 Correct 96 ms 61408 KB Output is correct
30 Correct 232 ms 114244 KB Output is correct
31 Correct 282 ms 132060 KB Output is correct
32 Correct 287 ms 132152 KB Output is correct
33 Correct 265 ms 132004 KB Output is correct
34 Correct 271 ms 131792 KB Output is correct
35 Correct 292 ms 132108 KB Output is correct
36 Correct 283 ms 131704 KB Output is correct
37 Correct 308 ms 131972 KB Output is correct
38 Correct 298 ms 131956 KB Output is correct
39 Correct 300 ms 132044 KB Output is correct
40 Correct 271 ms 131900 KB Output is correct
41 Correct 278 ms 131788 KB Output is correct
42 Correct 278 ms 131944 KB Output is correct
43 Correct 283 ms 131972 KB Output is correct
44 Correct 286 ms 132016 KB Output is correct
45 Correct 285 ms 131980 KB Output is correct
46 Correct 287 ms 132064 KB Output is correct
47 Correct 288 ms 132044 KB Output is correct
48 Correct 278 ms 131984 KB Output is correct
49 Correct 281 ms 132004 KB Output is correct
50 Correct 283 ms 132064 KB Output is correct
51 Correct 294 ms 132000 KB Output is correct
52 Correct 296 ms 131972 KB Output is correct
53 Correct 288 ms 132044 KB Output is correct
54 Correct 289 ms 132040 KB Output is correct
55 Runtime error 1086 ms 262144 KB Execution killed with signal 9
56 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 19 ms 37844 KB Output is correct
2 Correct 18 ms 37844 KB Output is correct
3 Correct 18 ms 37836 KB Output is correct
4 Correct 21 ms 37824 KB Output is correct
5 Correct 18 ms 37856 KB Output is correct
6 Correct 18 ms 37904 KB Output is correct
7 Correct 19 ms 38076 KB Output is correct
8 Correct 23 ms 38652 KB Output is correct
9 Correct 22 ms 38792 KB Output is correct
10 Correct 22 ms 38796 KB Output is correct
11 Correct 21 ms 38772 KB Output is correct
12 Correct 23 ms 38856 KB Output is correct
13 Correct 24 ms 38800 KB Output is correct
14 Correct 24 ms 38824 KB Output is correct
15 Correct 23 ms 38792 KB Output is correct
16 Correct 23 ms 38868 KB Output is correct
17 Correct 27 ms 38800 KB Output is correct
18 Correct 22 ms 38732 KB Output is correct
19 Correct 23 ms 38868 KB Output is correct
20 Correct 24 ms 38784 KB Output is correct
21 Correct 24 ms 38892 KB Output is correct
22 Correct 24 ms 38928 KB Output is correct
23 Correct 24 ms 38868 KB Output is correct
24 Correct 23 ms 38820 KB Output is correct
25 Correct 23 ms 38868 KB Output is correct
26 Correct 24 ms 38888 KB Output is correct
27 Correct 22 ms 38868 KB Output is correct
28 Correct 24 ms 38788 KB Output is correct
29 Correct 96 ms 61408 KB Output is correct
30 Correct 232 ms 114244 KB Output is correct
31 Correct 282 ms 132060 KB Output is correct
32 Correct 287 ms 132152 KB Output is correct
33 Correct 265 ms 132004 KB Output is correct
34 Correct 271 ms 131792 KB Output is correct
35 Correct 292 ms 132108 KB Output is correct
36 Correct 283 ms 131704 KB Output is correct
37 Correct 308 ms 131972 KB Output is correct
38 Correct 298 ms 131956 KB Output is correct
39 Correct 300 ms 132044 KB Output is correct
40 Correct 271 ms 131900 KB Output is correct
41 Correct 278 ms 131788 KB Output is correct
42 Correct 278 ms 131944 KB Output is correct
43 Correct 283 ms 131972 KB Output is correct
44 Correct 286 ms 132016 KB Output is correct
45 Correct 285 ms 131980 KB Output is correct
46 Correct 287 ms 132064 KB Output is correct
47 Correct 288 ms 132044 KB Output is correct
48 Correct 278 ms 131984 KB Output is correct
49 Correct 281 ms 132004 KB Output is correct
50 Correct 283 ms 132064 KB Output is correct
51 Correct 294 ms 132000 KB Output is correct
52 Correct 296 ms 131972 KB Output is correct
53 Correct 288 ms 132044 KB Output is correct
54 Correct 289 ms 132040 KB Output is correct
55 Correct 161 ms 52624 KB Output is correct
56 Correct 160 ms 52796 KB Output is correct
57 Correct 167 ms 52552 KB Output is correct
58 Correct 158 ms 52552 KB Output is correct
59 Correct 159 ms 52168 KB Output is correct
60 Correct 164 ms 52216 KB Output is correct
61 Correct 169 ms 52372 KB Output is correct
62 Correct 162 ms 52752 KB Output is correct
63 Correct 157 ms 52260 KB Output is correct
64 Correct 156 ms 52788 KB Output is correct
65 Correct 159 ms 51936 KB Output is correct
66 Correct 161 ms 52000 KB Output is correct
67 Correct 161 ms 52408 KB Output is correct
68 Correct 163 ms 52556 KB Output is correct
69 Runtime error 1111 ms 262144 KB Execution killed with signal 9
70 Halted 0 ms 0 KB -