Submission #1033125

# Submission time Handle Problem Language Result Execution time Memory
1033125 2024-07-24T13:05:30 Z vjudge1 Joker (BOI20_joker) C++17
14 / 100
427 ms 5876 KB
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define ll long long
#define ar array
#define ld long double

const int N = 3e5 + 20;
const int K = 200;
const int INF = 1e15;
const int LOG = 24;
const int MOD = 998244353;

struct DSU{
	vector<int> p;
	vector<int> c;
	vector<int> sz;
	vector<int> bi;
	
	DSU(int n){
		p.clear();
		sz.clear();
		bi.clear();
		c.clear();
		p.resize(n);
		sz.resize(n, 1);
		bi.resize(n, 1);
		c.resize(n, 0);
		for(int i = 0;i < n;i++)p[i] = i;
	}
	
	ar<int,2 > find(int x){
		if(x == p[x])return {x, c[x]};
		ar<int,2 > q = find(p[x]);
		return {q[0], q[1] ^ c[x]};
	}
	
	vector<pair<int&, int> > rb;
	
	bool join(int a,int b){
		ar<int, 2> pa = find(a);
		ar<int, 2> pb = find(b);
		a = pa[0];
		b = pb[0];
		int ca = pa[1];
		int cb = pb[1];
		
		rb.push_back({p[a], p[a]});
		rb.push_back({sz[a], sz[a]});
		rb.push_back({bi[a], bi[a]});
		rb.push_back({c[a], c[a]});
		
		rb.push_back({p[b], p[b]});
		rb.push_back({sz[b], sz[b]});
		rb.push_back({bi[b], bi[b]});
		rb.push_back({c[b], c[b]});
		
		if(a == b){
			if(ca == cb)bi[a] = 0;
			return 0;
		}
		
		if(sz[a] < sz[b])swap(a, b), swap(ca, cb);
		sz[a] += sz[b];
		p[b] = a;
		c[b] = cb ^ ca ^ 1;
		bi[a] &= bi[b];
		return 1;
	}
	inline bool bip(int x){
		return bi[find(x)[0]];
	}
	
	void roll(){
		for(int i = 0;i < 8;i++){
			rb.back().first = rb.back().second;
			rb.pop_back();
		}
	}
};

signed main(){ios_base::sync_with_stdio(false);cin.tie(0);
	int n, m, q;
	cin>>n>>m>>q;
	ar<int, 2> e[m];
	for(int i = 0;i < m;i++){
		int u, v;
		cin>>u>>v;
		--u, --v;
		e[i] = {u, v};
	}
	//assert(0);
	if(n <= 2000 && m <= 2000 && q <= 2000){
		while(q--){
			int l, r;
			cin>>l>>r;
			--l, --r;
			DSU d(n);
			bool ans = 1;
			for(int i = 0;i < m;i++){
				if(l <= i && i <= r)continue;
				d.join(e[i][0], e[i][1]);
				if(!d.bip(e[i][0])){
					ans = 0;
					break;
				}
			}
			cout<< (ans ? "NO\n" : "YES\n");
		}
		return 0;
	}
	
	
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 2 ms 348 KB Output is correct
9 Correct 2 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 2 ms 344 KB Output is correct
12 Correct 2 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 3 ms 348 KB Output is correct
15 Correct 3 ms 348 KB Output is correct
16 Correct 2 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 2 ms 344 KB Output is correct
20 Correct 2 ms 348 KB Output is correct
21 Correct 2 ms 348 KB Output is correct
22 Correct 2 ms 452 KB Output is correct
23 Correct 2 ms 348 KB Output is correct
24 Correct 2 ms 488 KB Output is correct
25 Correct 2 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 2 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 2 ms 348 KB Output is correct
9 Correct 2 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 2 ms 344 KB Output is correct
12 Correct 2 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 3 ms 348 KB Output is correct
15 Correct 3 ms 348 KB Output is correct
16 Correct 2 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 2 ms 344 KB Output is correct
20 Correct 2 ms 348 KB Output is correct
21 Correct 2 ms 348 KB Output is correct
22 Correct 2 ms 452 KB Output is correct
23 Correct 2 ms 348 KB Output is correct
24 Correct 2 ms 488 KB Output is correct
25 Correct 2 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 2 ms 344 KB Output is correct
29 Correct 217 ms 800 KB Output is correct
30 Correct 138 ms 988 KB Output is correct
31 Correct 135 ms 816 KB Output is correct
32 Correct 117 ms 760 KB Output is correct
33 Correct 51 ms 640 KB Output is correct
34 Correct 100 ms 996 KB Output is correct
35 Correct 236 ms 2192 KB Output is correct
36 Correct 165 ms 820 KB Output is correct
37 Correct 330 ms 1092 KB Output is correct
38 Correct 427 ms 1224 KB Output is correct
39 Correct 238 ms 1076 KB Output is correct
40 Correct 146 ms 804 KB Output is correct
41 Correct 157 ms 816 KB Output is correct
42 Correct 149 ms 812 KB Output is correct
43 Correct 190 ms 804 KB Output is correct
44 Correct 197 ms 812 KB Output is correct
45 Correct 151 ms 948 KB Output is correct
46 Correct 270 ms 988 KB Output is correct
47 Correct 178 ms 808 KB Output is correct
48 Correct 162 ms 856 KB Output is correct
49 Correct 182 ms 980 KB Output is correct
50 Correct 158 ms 1016 KB Output is correct
51 Correct 156 ms 804 KB Output is correct
52 Correct 171 ms 820 KB Output is correct
53 Correct 177 ms 824 KB Output is correct
54 Correct 277 ms 984 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 20 ms 3420 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 2 ms 348 KB Output is correct
9 Correct 2 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 2 ms 344 KB Output is correct
12 Correct 2 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 3 ms 348 KB Output is correct
15 Correct 3 ms 348 KB Output is correct
16 Correct 2 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 2 ms 344 KB Output is correct
20 Correct 2 ms 348 KB Output is correct
21 Correct 2 ms 348 KB Output is correct
22 Correct 2 ms 452 KB Output is correct
23 Correct 2 ms 348 KB Output is correct
24 Correct 2 ms 488 KB Output is correct
25 Correct 2 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 2 ms 344 KB Output is correct
29 Incorrect 20 ms 3420 KB Output isn't correct
30 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 2 ms 348 KB Output is correct
9 Correct 2 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 2 ms 344 KB Output is correct
12 Correct 2 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 3 ms 348 KB Output is correct
15 Correct 3 ms 348 KB Output is correct
16 Correct 2 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 2 ms 344 KB Output is correct
20 Correct 2 ms 348 KB Output is correct
21 Correct 2 ms 348 KB Output is correct
22 Correct 2 ms 452 KB Output is correct
23 Correct 2 ms 348 KB Output is correct
24 Correct 2 ms 488 KB Output is correct
25 Correct 2 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 2 ms 344 KB Output is correct
29 Correct 217 ms 800 KB Output is correct
30 Correct 138 ms 988 KB Output is correct
31 Correct 135 ms 816 KB Output is correct
32 Correct 117 ms 760 KB Output is correct
33 Correct 51 ms 640 KB Output is correct
34 Correct 100 ms 996 KB Output is correct
35 Correct 236 ms 2192 KB Output is correct
36 Correct 165 ms 820 KB Output is correct
37 Correct 330 ms 1092 KB Output is correct
38 Correct 427 ms 1224 KB Output is correct
39 Correct 238 ms 1076 KB Output is correct
40 Correct 146 ms 804 KB Output is correct
41 Correct 157 ms 816 KB Output is correct
42 Correct 149 ms 812 KB Output is correct
43 Correct 190 ms 804 KB Output is correct
44 Correct 197 ms 812 KB Output is correct
45 Correct 151 ms 948 KB Output is correct
46 Correct 270 ms 988 KB Output is correct
47 Correct 178 ms 808 KB Output is correct
48 Correct 162 ms 856 KB Output is correct
49 Correct 182 ms 980 KB Output is correct
50 Correct 158 ms 1016 KB Output is correct
51 Correct 156 ms 804 KB Output is correct
52 Correct 171 ms 820 KB Output is correct
53 Correct 177 ms 824 KB Output is correct
54 Correct 277 ms 984 KB Output is correct
55 Incorrect 22 ms 5876 KB Output isn't correct
56 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 2 ms 348 KB Output is correct
9 Correct 2 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 2 ms 344 KB Output is correct
12 Correct 2 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 3 ms 348 KB Output is correct
15 Correct 3 ms 348 KB Output is correct
16 Correct 2 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 2 ms 344 KB Output is correct
20 Correct 2 ms 348 KB Output is correct
21 Correct 2 ms 348 KB Output is correct
22 Correct 2 ms 452 KB Output is correct
23 Correct 2 ms 348 KB Output is correct
24 Correct 2 ms 488 KB Output is correct
25 Correct 2 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 2 ms 344 KB Output is correct
29 Correct 217 ms 800 KB Output is correct
30 Correct 138 ms 988 KB Output is correct
31 Correct 135 ms 816 KB Output is correct
32 Correct 117 ms 760 KB Output is correct
33 Correct 51 ms 640 KB Output is correct
34 Correct 100 ms 996 KB Output is correct
35 Correct 236 ms 2192 KB Output is correct
36 Correct 165 ms 820 KB Output is correct
37 Correct 330 ms 1092 KB Output is correct
38 Correct 427 ms 1224 KB Output is correct
39 Correct 238 ms 1076 KB Output is correct
40 Correct 146 ms 804 KB Output is correct
41 Correct 157 ms 816 KB Output is correct
42 Correct 149 ms 812 KB Output is correct
43 Correct 190 ms 804 KB Output is correct
44 Correct 197 ms 812 KB Output is correct
45 Correct 151 ms 948 KB Output is correct
46 Correct 270 ms 988 KB Output is correct
47 Correct 178 ms 808 KB Output is correct
48 Correct 162 ms 856 KB Output is correct
49 Correct 182 ms 980 KB Output is correct
50 Correct 158 ms 1016 KB Output is correct
51 Correct 156 ms 804 KB Output is correct
52 Correct 171 ms 820 KB Output is correct
53 Correct 177 ms 824 KB Output is correct
54 Correct 277 ms 984 KB Output is correct
55 Incorrect 20 ms 3420 KB Output isn't correct
56 Halted 0 ms 0 KB -