Submission #1033165

# Submission time Handle Problem Language Result Execution time Memory
1033165 2024-07-24T13:31:10 Z vjudge1 Joker (BOI20_joker) C++17
49 / 100
1144 ms 18608 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 B = 400;
const int M = 200;
const int INF = 1e15;
const int LOG = 24;
const int MOD = 998244353;

#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx,bmi,bmi2,lzcnt,popcnt")

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]];
	}
	/*
	bool roll(){
		if(rb.empty())return 0;
		for(int i = 0;i < 8;i++){
			rb.back().first = rb.back().second;
			rb.pop_back();
		}
		return 1;
	}
	*/
};

vector<ar<int, 2> > que[M];

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};
	}
	
	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;
	}
	for(int i = 0;i < q;i++){
		int l, r;
		cin>>l>>r;
		--l, --r;
		que[l].push_back({r, i});
	}
	bitset<N> res;
	for(int l = 0;l < M;l++){
		if(que[l].empty())continue;
		sort(que[l].rbegin(), que[l].rend());
		
		DSU d(n);
		bool ans = 1;
		for(int i = 0;i < l;i++){
			d.join(e[i][0], e[i][1]);
			if(!d.bip(e[i][0]))ans = 0;
		}
		int p = 0;
		for(int i = m - 1;i >= 0 && ans;i--){
			while(p < que[l].size() && que[l][p][0] == i){
				res[que[l][p][1]] = ans;
				++p;
			}
			d.join(e[i][0], e[i][1]);
			if(!d.bip(e[i][0]))ans = 0;
		}
		
	}
	for(int i = 0;i < q;i++)cout<<(res[i] ? "NO\n" : "YES\n");
}

Compilation message

Joker.cpp: In function 'int main()':
Joker.cpp:142:12: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::array<long long int, 2> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  142 |    while(p < que[l].size() && que[l][p][0] == i){
      |          ~~^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 504 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 600 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 344 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 1 ms 504 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 1 ms 492 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 504 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 600 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 344 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 1 ms 504 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 1 ms 492 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 22 ms 604 KB Output is correct
30 Correct 24 ms 604 KB Output is correct
31 Correct 23 ms 604 KB Output is correct
32 Correct 13 ms 596 KB Output is correct
33 Correct 8 ms 344 KB Output is correct
34 Correct 20 ms 604 KB Output is correct
35 Correct 28 ms 600 KB Output is correct
36 Correct 17 ms 600 KB Output is correct
37 Correct 35 ms 600 KB Output is correct
38 Correct 38 ms 604 KB Output is correct
39 Correct 25 ms 604 KB Output is correct
40 Correct 16 ms 348 KB Output is correct
41 Correct 15 ms 604 KB Output is correct
42 Correct 15 ms 348 KB Output is correct
43 Correct 18 ms 344 KB Output is correct
44 Correct 21 ms 348 KB Output is correct
45 Correct 22 ms 616 KB Output is correct
46 Correct 24 ms 628 KB Output is correct
47 Correct 17 ms 588 KB Output is correct
48 Correct 19 ms 344 KB Output is correct
49 Correct 21 ms 600 KB Output is correct
50 Correct 29 ms 604 KB Output is correct
51 Correct 17 ms 348 KB Output is correct
52 Correct 19 ms 348 KB Output is correct
53 Correct 22 ms 604 KB Output is correct
54 Correct 36 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 61 ms 14528 KB Output is correct
4 Correct 71 ms 16376 KB Output is correct
5 Correct 70 ms 16372 KB Output is correct
6 Correct 72 ms 14456 KB Output is correct
7 Correct 69 ms 14420 KB Output is correct
8 Correct 65 ms 12488 KB Output is correct
9 Correct 65 ms 13756 KB Output is correct
10 Correct 70 ms 16332 KB Output is correct
11 Correct 70 ms 14236 KB Output is correct
12 Correct 79 ms 16316 KB Output is correct
13 Correct 67 ms 11712 KB Output is correct
14 Correct 70 ms 13248 KB Output is correct
15 Correct 69 ms 15156 KB Output is correct
16 Correct 71 ms 17088 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 504 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 600 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 344 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 1 ms 504 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 1 ms 492 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 61 ms 14528 KB Output is correct
30 Correct 71 ms 16376 KB Output is correct
31 Correct 70 ms 16372 KB Output is correct
32 Correct 72 ms 14456 KB Output is correct
33 Correct 69 ms 14420 KB Output is correct
34 Correct 65 ms 12488 KB Output is correct
35 Correct 65 ms 13756 KB Output is correct
36 Correct 70 ms 16332 KB Output is correct
37 Correct 70 ms 14236 KB Output is correct
38 Correct 79 ms 16316 KB Output is correct
39 Correct 67 ms 11712 KB Output is correct
40 Correct 70 ms 13248 KB Output is correct
41 Correct 69 ms 15156 KB Output is correct
42 Correct 71 ms 17088 KB Output is correct
43 Correct 527 ms 15420 KB Output is correct
44 Correct 1144 ms 18252 KB Output is correct
45 Correct 1103 ms 18592 KB Output is correct
46 Correct 233 ms 15716 KB Output is correct
47 Correct 243 ms 15468 KB Output is correct
48 Correct 473 ms 14780 KB Output is correct
49 Correct 822 ms 18268 KB Output is correct
50 Correct 699 ms 14596 KB Output is correct
51 Correct 681 ms 16624 KB Output is correct
52 Correct 731 ms 18608 KB Output is correct
53 Correct 393 ms 12920 KB Output is correct
54 Correct 449 ms 14896 KB Output is correct
55 Correct 640 ms 16840 KB Output is correct
56 Correct 843 ms 18540 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 504 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 600 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 344 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 1 ms 504 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 1 ms 492 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 22 ms 604 KB Output is correct
30 Correct 24 ms 604 KB Output is correct
31 Correct 23 ms 604 KB Output is correct
32 Correct 13 ms 596 KB Output is correct
33 Correct 8 ms 344 KB Output is correct
34 Correct 20 ms 604 KB Output is correct
35 Correct 28 ms 600 KB Output is correct
36 Correct 17 ms 600 KB Output is correct
37 Correct 35 ms 600 KB Output is correct
38 Correct 38 ms 604 KB Output is correct
39 Correct 25 ms 604 KB Output is correct
40 Correct 16 ms 348 KB Output is correct
41 Correct 15 ms 604 KB Output is correct
42 Correct 15 ms 348 KB Output is correct
43 Correct 18 ms 344 KB Output is correct
44 Correct 21 ms 348 KB Output is correct
45 Correct 22 ms 616 KB Output is correct
46 Correct 24 ms 628 KB Output is correct
47 Correct 17 ms 588 KB Output is correct
48 Correct 19 ms 344 KB Output is correct
49 Correct 21 ms 600 KB Output is correct
50 Correct 29 ms 604 KB Output is correct
51 Correct 17 ms 348 KB Output is correct
52 Correct 19 ms 348 KB Output is correct
53 Correct 22 ms 604 KB Output is correct
54 Correct 36 ms 604 KB Output is correct
55 Runtime error 23 ms 9304 KB Execution killed with signal 11
56 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 504 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 600 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 344 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 1 ms 504 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 1 ms 492 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 22 ms 604 KB Output is correct
30 Correct 24 ms 604 KB Output is correct
31 Correct 23 ms 604 KB Output is correct
32 Correct 13 ms 596 KB Output is correct
33 Correct 8 ms 344 KB Output is correct
34 Correct 20 ms 604 KB Output is correct
35 Correct 28 ms 600 KB Output is correct
36 Correct 17 ms 600 KB Output is correct
37 Correct 35 ms 600 KB Output is correct
38 Correct 38 ms 604 KB Output is correct
39 Correct 25 ms 604 KB Output is correct
40 Correct 16 ms 348 KB Output is correct
41 Correct 15 ms 604 KB Output is correct
42 Correct 15 ms 348 KB Output is correct
43 Correct 18 ms 344 KB Output is correct
44 Correct 21 ms 348 KB Output is correct
45 Correct 22 ms 616 KB Output is correct
46 Correct 24 ms 628 KB Output is correct
47 Correct 17 ms 588 KB Output is correct
48 Correct 19 ms 344 KB Output is correct
49 Correct 21 ms 600 KB Output is correct
50 Correct 29 ms 604 KB Output is correct
51 Correct 17 ms 348 KB Output is correct
52 Correct 19 ms 348 KB Output is correct
53 Correct 22 ms 604 KB Output is correct
54 Correct 36 ms 604 KB Output is correct
55 Correct 61 ms 14528 KB Output is correct
56 Correct 71 ms 16376 KB Output is correct
57 Correct 70 ms 16372 KB Output is correct
58 Correct 72 ms 14456 KB Output is correct
59 Correct 69 ms 14420 KB Output is correct
60 Correct 65 ms 12488 KB Output is correct
61 Correct 65 ms 13756 KB Output is correct
62 Correct 70 ms 16332 KB Output is correct
63 Correct 70 ms 14236 KB Output is correct
64 Correct 79 ms 16316 KB Output is correct
65 Correct 67 ms 11712 KB Output is correct
66 Correct 70 ms 13248 KB Output is correct
67 Correct 69 ms 15156 KB Output is correct
68 Correct 71 ms 17088 KB Output is correct
69 Correct 527 ms 15420 KB Output is correct
70 Correct 1144 ms 18252 KB Output is correct
71 Correct 1103 ms 18592 KB Output is correct
72 Correct 233 ms 15716 KB Output is correct
73 Correct 243 ms 15468 KB Output is correct
74 Correct 473 ms 14780 KB Output is correct
75 Correct 822 ms 18268 KB Output is correct
76 Correct 699 ms 14596 KB Output is correct
77 Correct 681 ms 16624 KB Output is correct
78 Correct 731 ms 18608 KB Output is correct
79 Correct 393 ms 12920 KB Output is correct
80 Correct 449 ms 14896 KB Output is correct
81 Correct 640 ms 16840 KB Output is correct
82 Correct 843 ms 18540 KB Output is correct
83 Runtime error 23 ms 9304 KB Execution killed with signal 11
84 Halted 0 ms 0 KB -