Submission #384364

# Submission time Handle Problem Language Result Execution time Memory
384364 2021-04-01T13:07:19 Z LinusTorvaldsFan Joker (BOI20_joker) C++14
71 / 100
2000 ms 20872 KB
#pragma GCC optimize("Ofast")


#include <iostream>
#include <string.h>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <assert.h>
#include <cmath>
#include <memory.h>
#include <queue>
#include <bitset>
#include <set>

using namespace std;

#define rep(i, n) for(int i =0;i<(n);i++)
#define per(i, n) for (int i=((int)n-1);i>=0;i--)
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define ff first
#define ss second
#define make_unique(x) { sort(all(x)); x.resize(unique(x.begin(), x.end()) - x.begin()); }
#define sz(x) ((int)x.size())
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define add insert
#define debug(x) { cerr << #x << "= " << x << "\n"; }
typedef long long ll;
typedef vector<int>vi;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
typedef pair<ll, ll> pll;
typedef vector<string> vs;
const int N = 200100;
int dsu[2 * N];
int sz[2 * N];

bool is_bipar = true;

vector<tuple<int, int, int, int>> ba;
vector<bool> bipar;


inline int find(int x) {
	while (x != dsu[x]) x = dsu[x];
	return x;
}

inline void unite(int a, int b) {
	
	a = find(a);
	b = find(b);

	if (sz[a] < sz[b]) swap(a, b);
	
	if (a == b) return;

	
	bipar.pb(is_bipar);
	ba.eb(a, sz[a], b, dsu[b]);

	dsu[b] = a;
	sz[a] += sz[b];

}

bool same(int a, int b) {
	return find(a) == find(b);
}

void merge(int a, int b) {

	unite(a, b + N);
	unite(b, a + N);

	if (same(a, a + N) || same(b, b + N)) {
		is_bipar = false;
	}
}

void back() {
	int a, b, c, d;
	tie(a, b, c, d) = ba.back();
	sz[a] = b;
	dsu[c] = d;
	is_bipar = bipar.back();
	ba.pop_back();
	bipar.pop_back();
}

void init() {
	rep(i, 2 * N) {
		dsu[i] = i;
		sz[i] = 1;
	}
}

bool ans[N];

struct Q {
	int l, r, i;
};

bool operator<(Q a, Q b) {
	return a.r > b.r;
}

vector<Q> qu[N];

int main() {
	bipar.reserve(2 * N);
	ba.reserve(2 * N);
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n, m, q;
	cin >> n >> m >> q;
	vpii edges;
	rep(i, m) {
		int u, v;
		cin >> u >> v;
		edges.eb(u, v);
	}
	const int K = 1800;

	rep(i, q) {
		int l, r;
		cin >> l >> r;
		l--; r--;
		qu[l / K].pb({ l, r, i });
	}
	init();
	rep(bl, N) {
		int bl_l = bl * K;
		int bl_r = min((bl + 1) * K - 1, m - 1);
		if (qu[bl].size()) {
			sort(all(qu[bl]));
			int pr = m - 1;
			int was_on_start = ba.size();
			rep(j, sz(qu[bl])) {
				while (pr > qu[bl][j].r) {
					int v1 = edges[pr].ff;
					int v2 = edges[pr].ss;
					pr--;
					merge(v1, v2);
				}
				int was = ba.size();
				for (int i = qu[bl][j].l - 1; i >= bl_l; i--) {
					int v1 = edges[i].ff;
					int v2 = edges[i].ss;
					merge(v1, v2);
				}
				ans[qu[bl][j].i] = is_bipar;
				while (ba.size() != was) {
					back();
				}
			}

			while (ba.size() != was_on_start) {
				back();
			}
		}
		for (int i = bl_l; i <= bl_r; i++) {
			int v1 = edges[i].ff;
			int v2 = edges[i].ss;
			merge(v1, v2);
		}
	}

	rep(i, q) {
		if (ans[i]) cout << "NO\n";
		else cout << "YES\n";
	}

	return 0;
}

Compilation message

Joker.cpp: In function 'int main()':
Joker.cpp:158:22: warning: comparison of integer expressions of different signedness: 'std::vector<std::tuple<int, int, int, int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
  158 |     while (ba.size() != was) {
      |            ~~~~~~~~~~^~~~~~
Joker.cpp:163:21: warning: comparison of integer expressions of different signedness: 'std::vector<std::tuple<int, int, int, int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
  163 |    while (ba.size() != was_on_start) {
      |           ~~~~~~~~~~^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 7 ms 8176 KB Output is correct
2 Correct 7 ms 8320 KB Output is correct
3 Correct 7 ms 8172 KB Output is correct
4 Correct 9 ms 8172 KB Output is correct
5 Correct 7 ms 8172 KB Output is correct
6 Correct 7 ms 8172 KB Output is correct
7 Correct 7 ms 8172 KB Output is correct
8 Correct 10 ms 8172 KB Output is correct
9 Correct 8 ms 8172 KB Output is correct
10 Correct 9 ms 8172 KB Output is correct
11 Correct 8 ms 8172 KB Output is correct
12 Correct 8 ms 8172 KB Output is correct
13 Correct 8 ms 8172 KB Output is correct
14 Correct 8 ms 8172 KB Output is correct
15 Correct 8 ms 8172 KB Output is correct
16 Correct 8 ms 8172 KB Output is correct
17 Correct 8 ms 8172 KB Output is correct
18 Correct 8 ms 8172 KB Output is correct
19 Correct 8 ms 8172 KB Output is correct
20 Correct 8 ms 8172 KB Output is correct
21 Correct 8 ms 8172 KB Output is correct
22 Correct 8 ms 8172 KB Output is correct
23 Correct 8 ms 8172 KB Output is correct
24 Correct 8 ms 8172 KB Output is correct
25 Correct 10 ms 8172 KB Output is correct
26 Correct 9 ms 8172 KB Output is correct
27 Correct 10 ms 8172 KB Output is correct
28 Correct 9 ms 8172 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 8176 KB Output is correct
2 Correct 7 ms 8320 KB Output is correct
3 Correct 7 ms 8172 KB Output is correct
4 Correct 9 ms 8172 KB Output is correct
5 Correct 7 ms 8172 KB Output is correct
6 Correct 7 ms 8172 KB Output is correct
7 Correct 7 ms 8172 KB Output is correct
8 Correct 10 ms 8172 KB Output is correct
9 Correct 8 ms 8172 KB Output is correct
10 Correct 9 ms 8172 KB Output is correct
11 Correct 8 ms 8172 KB Output is correct
12 Correct 8 ms 8172 KB Output is correct
13 Correct 8 ms 8172 KB Output is correct
14 Correct 8 ms 8172 KB Output is correct
15 Correct 8 ms 8172 KB Output is correct
16 Correct 8 ms 8172 KB Output is correct
17 Correct 8 ms 8172 KB Output is correct
18 Correct 8 ms 8172 KB Output is correct
19 Correct 8 ms 8172 KB Output is correct
20 Correct 8 ms 8172 KB Output is correct
21 Correct 8 ms 8172 KB Output is correct
22 Correct 8 ms 8172 KB Output is correct
23 Correct 8 ms 8172 KB Output is correct
24 Correct 8 ms 8172 KB Output is correct
25 Correct 10 ms 8172 KB Output is correct
26 Correct 9 ms 8172 KB Output is correct
27 Correct 10 ms 8172 KB Output is correct
28 Correct 9 ms 8172 KB Output is correct
29 Correct 63 ms 8428 KB Output is correct
30 Correct 131 ms 8300 KB Output is correct
31 Correct 124 ms 8300 KB Output is correct
32 Correct 120 ms 8300 KB Output is correct
33 Correct 115 ms 8300 KB Output is correct
34 Correct 117 ms 8300 KB Output is correct
35 Correct 123 ms 8428 KB Output is correct
36 Correct 83 ms 8300 KB Output is correct
37 Correct 118 ms 8496 KB Output is correct
38 Correct 125 ms 8300 KB Output is correct
39 Correct 105 ms 8300 KB Output is correct
40 Correct 108 ms 8428 KB Output is correct
41 Correct 109 ms 8300 KB Output is correct
42 Correct 116 ms 8300 KB Output is correct
43 Correct 106 ms 8300 KB Output is correct
44 Correct 113 ms 8300 KB Output is correct
45 Correct 126 ms 8300 KB Output is correct
46 Correct 122 ms 8300 KB Output is correct
47 Correct 96 ms 8300 KB Output is correct
48 Correct 109 ms 8428 KB Output is correct
49 Correct 105 ms 8300 KB Output is correct
50 Correct 112 ms 8364 KB Output is correct
51 Correct 123 ms 8428 KB Output is correct
52 Correct 129 ms 8340 KB Output is correct
53 Correct 125 ms 8300 KB Output is correct
54 Correct 125 ms 8360 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 8176 KB Output is correct
2 Correct 7 ms 8320 KB Output is correct
3 Correct 122 ms 17624 KB Output is correct
4 Correct 149 ms 20872 KB Output is correct
5 Correct 146 ms 20184 KB Output is correct
6 Correct 136 ms 17624 KB Output is correct
7 Correct 141 ms 17860 KB Output is correct
8 Correct 137 ms 16472 KB Output is correct
9 Correct 143 ms 17752 KB Output is correct
10 Correct 159 ms 20184 KB Output is correct
11 Correct 130 ms 17624 KB Output is correct
12 Correct 140 ms 19416 KB Output is correct
13 Correct 135 ms 15192 KB Output is correct
14 Correct 140 ms 16344 KB Output is correct
15 Correct 149 ms 18648 KB Output is correct
16 Correct 163 ms 19928 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 8176 KB Output is correct
2 Correct 7 ms 8320 KB Output is correct
3 Correct 7 ms 8172 KB Output is correct
4 Correct 9 ms 8172 KB Output is correct
5 Correct 7 ms 8172 KB Output is correct
6 Correct 7 ms 8172 KB Output is correct
7 Correct 7 ms 8172 KB Output is correct
8 Correct 10 ms 8172 KB Output is correct
9 Correct 8 ms 8172 KB Output is correct
10 Correct 9 ms 8172 KB Output is correct
11 Correct 8 ms 8172 KB Output is correct
12 Correct 8 ms 8172 KB Output is correct
13 Correct 8 ms 8172 KB Output is correct
14 Correct 8 ms 8172 KB Output is correct
15 Correct 8 ms 8172 KB Output is correct
16 Correct 8 ms 8172 KB Output is correct
17 Correct 8 ms 8172 KB Output is correct
18 Correct 8 ms 8172 KB Output is correct
19 Correct 8 ms 8172 KB Output is correct
20 Correct 8 ms 8172 KB Output is correct
21 Correct 8 ms 8172 KB Output is correct
22 Correct 8 ms 8172 KB Output is correct
23 Correct 8 ms 8172 KB Output is correct
24 Correct 8 ms 8172 KB Output is correct
25 Correct 10 ms 8172 KB Output is correct
26 Correct 9 ms 8172 KB Output is correct
27 Correct 10 ms 8172 KB Output is correct
28 Correct 9 ms 8172 KB Output is correct
29 Correct 122 ms 17624 KB Output is correct
30 Correct 149 ms 20872 KB Output is correct
31 Correct 146 ms 20184 KB Output is correct
32 Correct 136 ms 17624 KB Output is correct
33 Correct 141 ms 17860 KB Output is correct
34 Correct 137 ms 16472 KB Output is correct
35 Correct 143 ms 17752 KB Output is correct
36 Correct 159 ms 20184 KB Output is correct
37 Correct 130 ms 17624 KB Output is correct
38 Correct 140 ms 19416 KB Output is correct
39 Correct 135 ms 15192 KB Output is correct
40 Correct 140 ms 16344 KB Output is correct
41 Correct 149 ms 18648 KB Output is correct
42 Correct 163 ms 19928 KB Output is correct
43 Correct 1292 ms 17692 KB Output is correct
44 Correct 1344 ms 20824 KB Output is correct
45 Correct 1424 ms 20824 KB Output is correct
46 Correct 1240 ms 17624 KB Output is correct
47 Correct 1588 ms 18008 KB Output is correct
48 Correct 1196 ms 17880 KB Output is correct
49 Correct 1377 ms 20020 KB Output is correct
50 Correct 1106 ms 17372 KB Output is correct
51 Correct 1295 ms 18904 KB Output is correct
52 Correct 1380 ms 19836 KB Output is correct
53 Correct 936 ms 15192 KB Output is correct
54 Correct 1683 ms 16984 KB Output is correct
55 Correct 1692 ms 18812 KB Output is correct
56 Correct 1761 ms 19884 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 8176 KB Output is correct
2 Correct 7 ms 8320 KB Output is correct
3 Correct 7 ms 8172 KB Output is correct
4 Correct 9 ms 8172 KB Output is correct
5 Correct 7 ms 8172 KB Output is correct
6 Correct 7 ms 8172 KB Output is correct
7 Correct 7 ms 8172 KB Output is correct
8 Correct 10 ms 8172 KB Output is correct
9 Correct 8 ms 8172 KB Output is correct
10 Correct 9 ms 8172 KB Output is correct
11 Correct 8 ms 8172 KB Output is correct
12 Correct 8 ms 8172 KB Output is correct
13 Correct 8 ms 8172 KB Output is correct
14 Correct 8 ms 8172 KB Output is correct
15 Correct 8 ms 8172 KB Output is correct
16 Correct 8 ms 8172 KB Output is correct
17 Correct 8 ms 8172 KB Output is correct
18 Correct 8 ms 8172 KB Output is correct
19 Correct 8 ms 8172 KB Output is correct
20 Correct 8 ms 8172 KB Output is correct
21 Correct 8 ms 8172 KB Output is correct
22 Correct 8 ms 8172 KB Output is correct
23 Correct 8 ms 8172 KB Output is correct
24 Correct 8 ms 8172 KB Output is correct
25 Correct 10 ms 8172 KB Output is correct
26 Correct 9 ms 8172 KB Output is correct
27 Correct 10 ms 8172 KB Output is correct
28 Correct 9 ms 8172 KB Output is correct
29 Correct 63 ms 8428 KB Output is correct
30 Correct 131 ms 8300 KB Output is correct
31 Correct 124 ms 8300 KB Output is correct
32 Correct 120 ms 8300 KB Output is correct
33 Correct 115 ms 8300 KB Output is correct
34 Correct 117 ms 8300 KB Output is correct
35 Correct 123 ms 8428 KB Output is correct
36 Correct 83 ms 8300 KB Output is correct
37 Correct 118 ms 8496 KB Output is correct
38 Correct 125 ms 8300 KB Output is correct
39 Correct 105 ms 8300 KB Output is correct
40 Correct 108 ms 8428 KB Output is correct
41 Correct 109 ms 8300 KB Output is correct
42 Correct 116 ms 8300 KB Output is correct
43 Correct 106 ms 8300 KB Output is correct
44 Correct 113 ms 8300 KB Output is correct
45 Correct 126 ms 8300 KB Output is correct
46 Correct 122 ms 8300 KB Output is correct
47 Correct 96 ms 8300 KB Output is correct
48 Correct 109 ms 8428 KB Output is correct
49 Correct 105 ms 8300 KB Output is correct
50 Correct 112 ms 8364 KB Output is correct
51 Correct 123 ms 8428 KB Output is correct
52 Correct 129 ms 8340 KB Output is correct
53 Correct 125 ms 8300 KB Output is correct
54 Correct 125 ms 8360 KB Output is correct
55 Correct 583 ms 13148 KB Output is correct
56 Correct 1301 ms 16348 KB Output is correct
57 Correct 1028 ms 15580 KB Output is correct
58 Correct 946 ms 13148 KB Output is correct
59 Correct 1423 ms 13148 KB Output is correct
60 Correct 1680 ms 14556 KB Output is correct
61 Correct 895 ms 13172 KB Output is correct
62 Correct 1222 ms 15036 KB Output is correct
63 Correct 991 ms 11228 KB Output is correct
64 Correct 1352 ms 13532 KB Output is correct
65 Correct 1546 ms 14812 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 8176 KB Output is correct
2 Correct 7 ms 8320 KB Output is correct
3 Correct 7 ms 8172 KB Output is correct
4 Correct 9 ms 8172 KB Output is correct
5 Correct 7 ms 8172 KB Output is correct
6 Correct 7 ms 8172 KB Output is correct
7 Correct 7 ms 8172 KB Output is correct
8 Correct 10 ms 8172 KB Output is correct
9 Correct 8 ms 8172 KB Output is correct
10 Correct 9 ms 8172 KB Output is correct
11 Correct 8 ms 8172 KB Output is correct
12 Correct 8 ms 8172 KB Output is correct
13 Correct 8 ms 8172 KB Output is correct
14 Correct 8 ms 8172 KB Output is correct
15 Correct 8 ms 8172 KB Output is correct
16 Correct 8 ms 8172 KB Output is correct
17 Correct 8 ms 8172 KB Output is correct
18 Correct 8 ms 8172 KB Output is correct
19 Correct 8 ms 8172 KB Output is correct
20 Correct 8 ms 8172 KB Output is correct
21 Correct 8 ms 8172 KB Output is correct
22 Correct 8 ms 8172 KB Output is correct
23 Correct 8 ms 8172 KB Output is correct
24 Correct 8 ms 8172 KB Output is correct
25 Correct 10 ms 8172 KB Output is correct
26 Correct 9 ms 8172 KB Output is correct
27 Correct 10 ms 8172 KB Output is correct
28 Correct 9 ms 8172 KB Output is correct
29 Correct 63 ms 8428 KB Output is correct
30 Correct 131 ms 8300 KB Output is correct
31 Correct 124 ms 8300 KB Output is correct
32 Correct 120 ms 8300 KB Output is correct
33 Correct 115 ms 8300 KB Output is correct
34 Correct 117 ms 8300 KB Output is correct
35 Correct 123 ms 8428 KB Output is correct
36 Correct 83 ms 8300 KB Output is correct
37 Correct 118 ms 8496 KB Output is correct
38 Correct 125 ms 8300 KB Output is correct
39 Correct 105 ms 8300 KB Output is correct
40 Correct 108 ms 8428 KB Output is correct
41 Correct 109 ms 8300 KB Output is correct
42 Correct 116 ms 8300 KB Output is correct
43 Correct 106 ms 8300 KB Output is correct
44 Correct 113 ms 8300 KB Output is correct
45 Correct 126 ms 8300 KB Output is correct
46 Correct 122 ms 8300 KB Output is correct
47 Correct 96 ms 8300 KB Output is correct
48 Correct 109 ms 8428 KB Output is correct
49 Correct 105 ms 8300 KB Output is correct
50 Correct 112 ms 8364 KB Output is correct
51 Correct 123 ms 8428 KB Output is correct
52 Correct 129 ms 8340 KB Output is correct
53 Correct 125 ms 8300 KB Output is correct
54 Correct 125 ms 8360 KB Output is correct
55 Correct 122 ms 17624 KB Output is correct
56 Correct 149 ms 20872 KB Output is correct
57 Correct 146 ms 20184 KB Output is correct
58 Correct 136 ms 17624 KB Output is correct
59 Correct 141 ms 17860 KB Output is correct
60 Correct 137 ms 16472 KB Output is correct
61 Correct 143 ms 17752 KB Output is correct
62 Correct 159 ms 20184 KB Output is correct
63 Correct 130 ms 17624 KB Output is correct
64 Correct 140 ms 19416 KB Output is correct
65 Correct 135 ms 15192 KB Output is correct
66 Correct 140 ms 16344 KB Output is correct
67 Correct 149 ms 18648 KB Output is correct
68 Correct 163 ms 19928 KB Output is correct
69 Correct 1292 ms 17692 KB Output is correct
70 Correct 1344 ms 20824 KB Output is correct
71 Correct 1424 ms 20824 KB Output is correct
72 Correct 1240 ms 17624 KB Output is correct
73 Correct 1588 ms 18008 KB Output is correct
74 Correct 1196 ms 17880 KB Output is correct
75 Correct 1377 ms 20020 KB Output is correct
76 Correct 1106 ms 17372 KB Output is correct
77 Correct 1295 ms 18904 KB Output is correct
78 Correct 1380 ms 19836 KB Output is correct
79 Correct 936 ms 15192 KB Output is correct
80 Correct 1683 ms 16984 KB Output is correct
81 Correct 1692 ms 18812 KB Output is correct
82 Correct 1761 ms 19884 KB Output is correct
83 Correct 583 ms 13148 KB Output is correct
84 Correct 1301 ms 16348 KB Output is correct
85 Correct 1028 ms 15580 KB Output is correct
86 Correct 946 ms 13148 KB Output is correct
87 Correct 1423 ms 13148 KB Output is correct
88 Correct 1680 ms 14556 KB Output is correct
89 Correct 895 ms 13172 KB Output is correct
90 Correct 1222 ms 15036 KB Output is correct
91 Correct 991 ms 11228 KB Output is correct
92 Correct 1352 ms 13532 KB Output is correct
93 Correct 1546 ms 14812 KB Output is correct
94 Execution timed out 2074 ms 16192 KB Time limit exceeded
95 Halted 0 ms 0 KB -