답안 #1033156

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1033156 2024-07-24T13:27:37 Z vjudge1 Joker (BOI20_joker) C++17
39 / 100
2000 ms 48996 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 = 300;
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:141: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]
  141 |    while(p < que[l].size() && que[l][p][0] == i){
      |          ~~^~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 2 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 344 KB Output is correct
11 Correct 2 ms 348 KB Output is correct
12 Correct 2 ms 348 KB Output is correct
13 Correct 2 ms 344 KB Output is correct
14 Correct 3 ms 568 KB Output is correct
15 Correct 3 ms 348 KB Output is correct
16 Correct 2 ms 344 KB Output is correct
17 Correct 2 ms 348 KB Output is correct
18 Correct 2 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 2 ms 348 KB Output is correct
21 Correct 2 ms 344 KB Output is correct
22 Correct 2 ms 348 KB Output is correct
23 Correct 2 ms 348 KB Output is correct
24 Correct 2 ms 348 KB Output is correct
25 Correct 2 ms 348 KB Output is correct
26 Correct 2 ms 540 KB Output is correct
27 Correct 2 ms 348 KB Output is correct
28 Correct 2 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 2 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 344 KB Output is correct
11 Correct 2 ms 348 KB Output is correct
12 Correct 2 ms 348 KB Output is correct
13 Correct 2 ms 344 KB Output is correct
14 Correct 3 ms 568 KB Output is correct
15 Correct 3 ms 348 KB Output is correct
16 Correct 2 ms 344 KB Output is correct
17 Correct 2 ms 348 KB Output is correct
18 Correct 2 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 2 ms 348 KB Output is correct
21 Correct 2 ms 344 KB Output is correct
22 Correct 2 ms 348 KB Output is correct
23 Correct 2 ms 348 KB Output is correct
24 Correct 2 ms 348 KB Output is correct
25 Correct 2 ms 348 KB Output is correct
26 Correct 2 ms 540 KB Output is correct
27 Correct 2 ms 348 KB Output is correct
28 Correct 2 ms 348 KB Output is correct
29 Correct 171 ms 860 KB Output is correct
30 Correct 137 ms 1040 KB Output is correct
31 Correct 135 ms 960 KB Output is correct
32 Correct 130 ms 808 KB Output is correct
33 Correct 45 ms 692 KB Output is correct
34 Correct 98 ms 1040 KB Output is correct
35 Correct 278 ms 2192 KB Output is correct
36 Correct 165 ms 860 KB Output is correct
37 Correct 383 ms 1212 KB Output is correct
38 Correct 404 ms 1148 KB Output is correct
39 Correct 273 ms 1700 KB Output is correct
40 Correct 154 ms 856 KB Output is correct
41 Correct 148 ms 864 KB Output is correct
42 Correct 157 ms 856 KB Output is correct
43 Correct 185 ms 844 KB Output is correct
44 Correct 192 ms 860 KB Output is correct
45 Correct 154 ms 880 KB Output is correct
46 Correct 261 ms 1028 KB Output is correct
47 Correct 157 ms 856 KB Output is correct
48 Correct 165 ms 864 KB Output is correct
49 Correct 197 ms 1020 KB Output is correct
50 Correct 161 ms 1048 KB Output is correct
51 Correct 165 ms 856 KB Output is correct
52 Correct 164 ms 860 KB Output is correct
53 Correct 171 ms 876 KB Output is correct
54 Correct 264 ms 1040 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 78 ms 29788 KB Output is correct
4 Correct 105 ms 48996 KB Output is correct
5 Correct 72 ms 22052 KB Output is correct
6 Correct 81 ms 29764 KB Output is correct
7 Correct 89 ms 29544 KB Output is correct
8 Correct 79 ms 27960 KB Output is correct
9 Correct 84 ms 29500 KB Output is correct
10 Correct 82 ms 32572 KB Output is correct
11 Correct 82 ms 29756 KB Output is correct
12 Correct 82 ms 32316 KB Output is correct
13 Correct 82 ms 27096 KB Output is correct
14 Correct 82 ms 28472 KB Output is correct
15 Correct 87 ms 30928 KB Output is correct
16 Correct 85 ms 33084 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 2 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 344 KB Output is correct
11 Correct 2 ms 348 KB Output is correct
12 Correct 2 ms 348 KB Output is correct
13 Correct 2 ms 344 KB Output is correct
14 Correct 3 ms 568 KB Output is correct
15 Correct 3 ms 348 KB Output is correct
16 Correct 2 ms 344 KB Output is correct
17 Correct 2 ms 348 KB Output is correct
18 Correct 2 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 2 ms 348 KB Output is correct
21 Correct 2 ms 344 KB Output is correct
22 Correct 2 ms 348 KB Output is correct
23 Correct 2 ms 348 KB Output is correct
24 Correct 2 ms 348 KB Output is correct
25 Correct 2 ms 348 KB Output is correct
26 Correct 2 ms 540 KB Output is correct
27 Correct 2 ms 348 KB Output is correct
28 Correct 2 ms 348 KB Output is correct
29 Correct 78 ms 29788 KB Output is correct
30 Correct 105 ms 48996 KB Output is correct
31 Correct 72 ms 22052 KB Output is correct
32 Correct 81 ms 29764 KB Output is correct
33 Correct 89 ms 29544 KB Output is correct
34 Correct 79 ms 27960 KB Output is correct
35 Correct 84 ms 29500 KB Output is correct
36 Correct 82 ms 32572 KB Output is correct
37 Correct 82 ms 29756 KB Output is correct
38 Correct 82 ms 32316 KB Output is correct
39 Correct 82 ms 27096 KB Output is correct
40 Correct 82 ms 28472 KB Output is correct
41 Correct 87 ms 30928 KB Output is correct
42 Correct 85 ms 33084 KB Output is correct
43 Execution timed out 2033 ms 43536 KB Time limit exceeded
44 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 2 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 344 KB Output is correct
11 Correct 2 ms 348 KB Output is correct
12 Correct 2 ms 348 KB Output is correct
13 Correct 2 ms 344 KB Output is correct
14 Correct 3 ms 568 KB Output is correct
15 Correct 3 ms 348 KB Output is correct
16 Correct 2 ms 344 KB Output is correct
17 Correct 2 ms 348 KB Output is correct
18 Correct 2 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 2 ms 348 KB Output is correct
21 Correct 2 ms 344 KB Output is correct
22 Correct 2 ms 348 KB Output is correct
23 Correct 2 ms 348 KB Output is correct
24 Correct 2 ms 348 KB Output is correct
25 Correct 2 ms 348 KB Output is correct
26 Correct 2 ms 540 KB Output is correct
27 Correct 2 ms 348 KB Output is correct
28 Correct 2 ms 348 KB Output is correct
29 Correct 171 ms 860 KB Output is correct
30 Correct 137 ms 1040 KB Output is correct
31 Correct 135 ms 960 KB Output is correct
32 Correct 130 ms 808 KB Output is correct
33 Correct 45 ms 692 KB Output is correct
34 Correct 98 ms 1040 KB Output is correct
35 Correct 278 ms 2192 KB Output is correct
36 Correct 165 ms 860 KB Output is correct
37 Correct 383 ms 1212 KB Output is correct
38 Correct 404 ms 1148 KB Output is correct
39 Correct 273 ms 1700 KB Output is correct
40 Correct 154 ms 856 KB Output is correct
41 Correct 148 ms 864 KB Output is correct
42 Correct 157 ms 856 KB Output is correct
43 Correct 185 ms 844 KB Output is correct
44 Correct 192 ms 860 KB Output is correct
45 Correct 154 ms 880 KB Output is correct
46 Correct 261 ms 1028 KB Output is correct
47 Correct 157 ms 856 KB Output is correct
48 Correct 165 ms 864 KB Output is correct
49 Correct 197 ms 1020 KB Output is correct
50 Correct 161 ms 1048 KB Output is correct
51 Correct 165 ms 856 KB Output is correct
52 Correct 164 ms 860 KB Output is correct
53 Correct 171 ms 876 KB Output is correct
54 Correct 264 ms 1040 KB Output is correct
55 Runtime error 23 ms 9296 KB Execution killed with signal 11
56 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 2 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 344 KB Output is correct
11 Correct 2 ms 348 KB Output is correct
12 Correct 2 ms 348 KB Output is correct
13 Correct 2 ms 344 KB Output is correct
14 Correct 3 ms 568 KB Output is correct
15 Correct 3 ms 348 KB Output is correct
16 Correct 2 ms 344 KB Output is correct
17 Correct 2 ms 348 KB Output is correct
18 Correct 2 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 2 ms 348 KB Output is correct
21 Correct 2 ms 344 KB Output is correct
22 Correct 2 ms 348 KB Output is correct
23 Correct 2 ms 348 KB Output is correct
24 Correct 2 ms 348 KB Output is correct
25 Correct 2 ms 348 KB Output is correct
26 Correct 2 ms 540 KB Output is correct
27 Correct 2 ms 348 KB Output is correct
28 Correct 2 ms 348 KB Output is correct
29 Correct 171 ms 860 KB Output is correct
30 Correct 137 ms 1040 KB Output is correct
31 Correct 135 ms 960 KB Output is correct
32 Correct 130 ms 808 KB Output is correct
33 Correct 45 ms 692 KB Output is correct
34 Correct 98 ms 1040 KB Output is correct
35 Correct 278 ms 2192 KB Output is correct
36 Correct 165 ms 860 KB Output is correct
37 Correct 383 ms 1212 KB Output is correct
38 Correct 404 ms 1148 KB Output is correct
39 Correct 273 ms 1700 KB Output is correct
40 Correct 154 ms 856 KB Output is correct
41 Correct 148 ms 864 KB Output is correct
42 Correct 157 ms 856 KB Output is correct
43 Correct 185 ms 844 KB Output is correct
44 Correct 192 ms 860 KB Output is correct
45 Correct 154 ms 880 KB Output is correct
46 Correct 261 ms 1028 KB Output is correct
47 Correct 157 ms 856 KB Output is correct
48 Correct 165 ms 864 KB Output is correct
49 Correct 197 ms 1020 KB Output is correct
50 Correct 161 ms 1048 KB Output is correct
51 Correct 165 ms 856 KB Output is correct
52 Correct 164 ms 860 KB Output is correct
53 Correct 171 ms 876 KB Output is correct
54 Correct 264 ms 1040 KB Output is correct
55 Correct 78 ms 29788 KB Output is correct
56 Correct 105 ms 48996 KB Output is correct
57 Correct 72 ms 22052 KB Output is correct
58 Correct 81 ms 29764 KB Output is correct
59 Correct 89 ms 29544 KB Output is correct
60 Correct 79 ms 27960 KB Output is correct
61 Correct 84 ms 29500 KB Output is correct
62 Correct 82 ms 32572 KB Output is correct
63 Correct 82 ms 29756 KB Output is correct
64 Correct 82 ms 32316 KB Output is correct
65 Correct 82 ms 27096 KB Output is correct
66 Correct 82 ms 28472 KB Output is correct
67 Correct 87 ms 30928 KB Output is correct
68 Correct 85 ms 33084 KB Output is correct
69 Execution timed out 2033 ms 43536 KB Time limit exceeded
70 Halted 0 ms 0 KB -