Submission #642333

# Submission time Handle Problem Language Result Execution time Memory
642333 2022-09-19T08:52:54 Z dozer Joker (BOI20_joker) C++14
39 / 100
1148 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;
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;
	if (node == -b[node]) return 0;
	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 (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 (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 18 ms 37844 KB Output is correct
2 Correct 21 ms 37844 KB Output is correct
3 Correct 18 ms 37912 KB Output is correct
4 Correct 17 ms 37888 KB Output is correct
5 Correct 18 ms 37860 KB Output is correct
6 Correct 18 ms 37900 KB Output is correct
7 Correct 18 ms 38100 KB Output is correct
8 Correct 20 ms 38604 KB Output is correct
9 Correct 22 ms 38796 KB Output is correct
10 Correct 21 ms 38868 KB Output is correct
11 Correct 20 ms 38868 KB Output is correct
12 Correct 19 ms 38868 KB Output is correct
13 Correct 21 ms 38760 KB Output is correct
14 Correct 23 ms 38780 KB Output is correct
15 Correct 21 ms 38812 KB Output is correct
16 Correct 20 ms 38888 KB Output is correct
17 Correct 24 ms 38788 KB Output is correct
18 Correct 20 ms 38780 KB Output is correct
19 Correct 19 ms 38868 KB Output is correct
20 Correct 22 ms 38792 KB Output is correct
21 Correct 22 ms 38812 KB Output is correct
22 Correct 21 ms 38868 KB Output is correct
23 Correct 22 ms 38860 KB Output is correct
24 Correct 20 ms 38804 KB Output is correct
25 Correct 21 ms 38788 KB Output is correct
26 Correct 26 ms 38776 KB Output is correct
27 Correct 25 ms 38868 KB Output is correct
28 Correct 27 ms 38808 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 18 ms 37844 KB Output is correct
2 Correct 21 ms 37844 KB Output is correct
3 Correct 18 ms 37912 KB Output is correct
4 Correct 17 ms 37888 KB Output is correct
5 Correct 18 ms 37860 KB Output is correct
6 Correct 18 ms 37900 KB Output is correct
7 Correct 18 ms 38100 KB Output is correct
8 Correct 20 ms 38604 KB Output is correct
9 Correct 22 ms 38796 KB Output is correct
10 Correct 21 ms 38868 KB Output is correct
11 Correct 20 ms 38868 KB Output is correct
12 Correct 19 ms 38868 KB Output is correct
13 Correct 21 ms 38760 KB Output is correct
14 Correct 23 ms 38780 KB Output is correct
15 Correct 21 ms 38812 KB Output is correct
16 Correct 20 ms 38888 KB Output is correct
17 Correct 24 ms 38788 KB Output is correct
18 Correct 20 ms 38780 KB Output is correct
19 Correct 19 ms 38868 KB Output is correct
20 Correct 22 ms 38792 KB Output is correct
21 Correct 22 ms 38812 KB Output is correct
22 Correct 21 ms 38868 KB Output is correct
23 Correct 22 ms 38860 KB Output is correct
24 Correct 20 ms 38804 KB Output is correct
25 Correct 21 ms 38788 KB Output is correct
26 Correct 26 ms 38776 KB Output is correct
27 Correct 25 ms 38868 KB Output is correct
28 Correct 27 ms 38808 KB Output is correct
29 Correct 96 ms 61420 KB Output is correct
30 Correct 247 ms 114216 KB Output is correct
31 Correct 308 ms 132076 KB Output is correct
32 Correct 296 ms 132064 KB Output is correct
33 Correct 272 ms 132036 KB Output is correct
34 Correct 287 ms 131828 KB Output is correct
35 Correct 319 ms 132084 KB Output is correct
36 Correct 336 ms 131776 KB Output is correct
37 Correct 374 ms 132076 KB Output is correct
38 Correct 389 ms 131920 KB Output is correct
39 Correct 352 ms 132040 KB Output is correct
40 Correct 327 ms 131912 KB Output is correct
41 Correct 344 ms 131900 KB Output is correct
42 Correct 338 ms 131916 KB Output is correct
43 Correct 352 ms 131980 KB Output is correct
44 Correct 334 ms 132004 KB Output is correct
45 Correct 319 ms 132012 KB Output is correct
46 Correct 370 ms 132084 KB Output is correct
47 Correct 331 ms 132032 KB Output is correct
48 Correct 358 ms 132100 KB Output is correct
49 Correct 320 ms 132052 KB Output is correct
50 Correct 333 ms 132032 KB Output is correct
51 Correct 329 ms 132104 KB Output is correct
52 Correct 339 ms 132004 KB Output is correct
53 Correct 381 ms 131992 KB Output is correct
54 Correct 322 ms 132052 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 18 ms 37844 KB Output is correct
2 Correct 21 ms 37844 KB Output is correct
3 Correct 184 ms 53664 KB Output is correct
4 Correct 172 ms 53668 KB Output is correct
5 Correct 173 ms 53212 KB Output is correct
6 Correct 169 ms 53260 KB Output is correct
7 Correct 160 ms 52936 KB Output is correct
8 Correct 202 ms 52984 KB Output is correct
9 Correct 168 ms 53052 KB Output is correct
10 Correct 170 ms 53448 KB Output is correct
11 Correct 178 ms 53192 KB Output is correct
12 Correct 164 ms 53820 KB Output is correct
13 Correct 170 ms 52592 KB Output is correct
14 Correct 170 ms 52764 KB Output is correct
15 Correct 164 ms 53100 KB Output is correct
16 Correct 171 ms 53360 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 18 ms 37844 KB Output is correct
2 Correct 21 ms 37844 KB Output is correct
3 Correct 18 ms 37912 KB Output is correct
4 Correct 17 ms 37888 KB Output is correct
5 Correct 18 ms 37860 KB Output is correct
6 Correct 18 ms 37900 KB Output is correct
7 Correct 18 ms 38100 KB Output is correct
8 Correct 20 ms 38604 KB Output is correct
9 Correct 22 ms 38796 KB Output is correct
10 Correct 21 ms 38868 KB Output is correct
11 Correct 20 ms 38868 KB Output is correct
12 Correct 19 ms 38868 KB Output is correct
13 Correct 21 ms 38760 KB Output is correct
14 Correct 23 ms 38780 KB Output is correct
15 Correct 21 ms 38812 KB Output is correct
16 Correct 20 ms 38888 KB Output is correct
17 Correct 24 ms 38788 KB Output is correct
18 Correct 20 ms 38780 KB Output is correct
19 Correct 19 ms 38868 KB Output is correct
20 Correct 22 ms 38792 KB Output is correct
21 Correct 22 ms 38812 KB Output is correct
22 Correct 21 ms 38868 KB Output is correct
23 Correct 22 ms 38860 KB Output is correct
24 Correct 20 ms 38804 KB Output is correct
25 Correct 21 ms 38788 KB Output is correct
26 Correct 26 ms 38776 KB Output is correct
27 Correct 25 ms 38868 KB Output is correct
28 Correct 27 ms 38808 KB Output is correct
29 Correct 184 ms 53664 KB Output is correct
30 Correct 172 ms 53668 KB Output is correct
31 Correct 173 ms 53212 KB Output is correct
32 Correct 169 ms 53260 KB Output is correct
33 Correct 160 ms 52936 KB Output is correct
34 Correct 202 ms 52984 KB Output is correct
35 Correct 168 ms 53052 KB Output is correct
36 Correct 170 ms 53448 KB Output is correct
37 Correct 178 ms 53192 KB Output is correct
38 Correct 164 ms 53820 KB Output is correct
39 Correct 170 ms 52592 KB Output is correct
40 Correct 170 ms 52764 KB Output is correct
41 Correct 164 ms 53100 KB Output is correct
42 Correct 171 ms 53360 KB Output is correct
43 Runtime error 1148 ms 262144 KB Execution killed with signal 9
44 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 18 ms 37844 KB Output is correct
2 Correct 21 ms 37844 KB Output is correct
3 Correct 18 ms 37912 KB Output is correct
4 Correct 17 ms 37888 KB Output is correct
5 Correct 18 ms 37860 KB Output is correct
6 Correct 18 ms 37900 KB Output is correct
7 Correct 18 ms 38100 KB Output is correct
8 Correct 20 ms 38604 KB Output is correct
9 Correct 22 ms 38796 KB Output is correct
10 Correct 21 ms 38868 KB Output is correct
11 Correct 20 ms 38868 KB Output is correct
12 Correct 19 ms 38868 KB Output is correct
13 Correct 21 ms 38760 KB Output is correct
14 Correct 23 ms 38780 KB Output is correct
15 Correct 21 ms 38812 KB Output is correct
16 Correct 20 ms 38888 KB Output is correct
17 Correct 24 ms 38788 KB Output is correct
18 Correct 20 ms 38780 KB Output is correct
19 Correct 19 ms 38868 KB Output is correct
20 Correct 22 ms 38792 KB Output is correct
21 Correct 22 ms 38812 KB Output is correct
22 Correct 21 ms 38868 KB Output is correct
23 Correct 22 ms 38860 KB Output is correct
24 Correct 20 ms 38804 KB Output is correct
25 Correct 21 ms 38788 KB Output is correct
26 Correct 26 ms 38776 KB Output is correct
27 Correct 25 ms 38868 KB Output is correct
28 Correct 27 ms 38808 KB Output is correct
29 Correct 96 ms 61420 KB Output is correct
30 Correct 247 ms 114216 KB Output is correct
31 Correct 308 ms 132076 KB Output is correct
32 Correct 296 ms 132064 KB Output is correct
33 Correct 272 ms 132036 KB Output is correct
34 Correct 287 ms 131828 KB Output is correct
35 Correct 319 ms 132084 KB Output is correct
36 Correct 336 ms 131776 KB Output is correct
37 Correct 374 ms 132076 KB Output is correct
38 Correct 389 ms 131920 KB Output is correct
39 Correct 352 ms 132040 KB Output is correct
40 Correct 327 ms 131912 KB Output is correct
41 Correct 344 ms 131900 KB Output is correct
42 Correct 338 ms 131916 KB Output is correct
43 Correct 352 ms 131980 KB Output is correct
44 Correct 334 ms 132004 KB Output is correct
45 Correct 319 ms 132012 KB Output is correct
46 Correct 370 ms 132084 KB Output is correct
47 Correct 331 ms 132032 KB Output is correct
48 Correct 358 ms 132100 KB Output is correct
49 Correct 320 ms 132052 KB Output is correct
50 Correct 333 ms 132032 KB Output is correct
51 Correct 329 ms 132104 KB Output is correct
52 Correct 339 ms 132004 KB Output is correct
53 Correct 381 ms 131992 KB Output is correct
54 Correct 322 ms 132052 KB Output is correct
55 Runtime error 1122 ms 262144 KB Execution killed with signal 9
56 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 18 ms 37844 KB Output is correct
2 Correct 21 ms 37844 KB Output is correct
3 Correct 18 ms 37912 KB Output is correct
4 Correct 17 ms 37888 KB Output is correct
5 Correct 18 ms 37860 KB Output is correct
6 Correct 18 ms 37900 KB Output is correct
7 Correct 18 ms 38100 KB Output is correct
8 Correct 20 ms 38604 KB Output is correct
9 Correct 22 ms 38796 KB Output is correct
10 Correct 21 ms 38868 KB Output is correct
11 Correct 20 ms 38868 KB Output is correct
12 Correct 19 ms 38868 KB Output is correct
13 Correct 21 ms 38760 KB Output is correct
14 Correct 23 ms 38780 KB Output is correct
15 Correct 21 ms 38812 KB Output is correct
16 Correct 20 ms 38888 KB Output is correct
17 Correct 24 ms 38788 KB Output is correct
18 Correct 20 ms 38780 KB Output is correct
19 Correct 19 ms 38868 KB Output is correct
20 Correct 22 ms 38792 KB Output is correct
21 Correct 22 ms 38812 KB Output is correct
22 Correct 21 ms 38868 KB Output is correct
23 Correct 22 ms 38860 KB Output is correct
24 Correct 20 ms 38804 KB Output is correct
25 Correct 21 ms 38788 KB Output is correct
26 Correct 26 ms 38776 KB Output is correct
27 Correct 25 ms 38868 KB Output is correct
28 Correct 27 ms 38808 KB Output is correct
29 Correct 96 ms 61420 KB Output is correct
30 Correct 247 ms 114216 KB Output is correct
31 Correct 308 ms 132076 KB Output is correct
32 Correct 296 ms 132064 KB Output is correct
33 Correct 272 ms 132036 KB Output is correct
34 Correct 287 ms 131828 KB Output is correct
35 Correct 319 ms 132084 KB Output is correct
36 Correct 336 ms 131776 KB Output is correct
37 Correct 374 ms 132076 KB Output is correct
38 Correct 389 ms 131920 KB Output is correct
39 Correct 352 ms 132040 KB Output is correct
40 Correct 327 ms 131912 KB Output is correct
41 Correct 344 ms 131900 KB Output is correct
42 Correct 338 ms 131916 KB Output is correct
43 Correct 352 ms 131980 KB Output is correct
44 Correct 334 ms 132004 KB Output is correct
45 Correct 319 ms 132012 KB Output is correct
46 Correct 370 ms 132084 KB Output is correct
47 Correct 331 ms 132032 KB Output is correct
48 Correct 358 ms 132100 KB Output is correct
49 Correct 320 ms 132052 KB Output is correct
50 Correct 333 ms 132032 KB Output is correct
51 Correct 329 ms 132104 KB Output is correct
52 Correct 339 ms 132004 KB Output is correct
53 Correct 381 ms 131992 KB Output is correct
54 Correct 322 ms 132052 KB Output is correct
55 Correct 184 ms 53664 KB Output is correct
56 Correct 172 ms 53668 KB Output is correct
57 Correct 173 ms 53212 KB Output is correct
58 Correct 169 ms 53260 KB Output is correct
59 Correct 160 ms 52936 KB Output is correct
60 Correct 202 ms 52984 KB Output is correct
61 Correct 168 ms 53052 KB Output is correct
62 Correct 170 ms 53448 KB Output is correct
63 Correct 178 ms 53192 KB Output is correct
64 Correct 164 ms 53820 KB Output is correct
65 Correct 170 ms 52592 KB Output is correct
66 Correct 170 ms 52764 KB Output is correct
67 Correct 164 ms 53100 KB Output is correct
68 Correct 171 ms 53360 KB Output is correct
69 Runtime error 1148 ms 262144 KB Execution killed with signal 9
70 Halted 0 ms 0 KB -