#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
#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;
int find(int x) {
if (x == dsu[x]) return x;
return find(dsu[x]);
}
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;
}
int main() {
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 = 500;
vector<vector<Q>> qu(K);
rep(i, q) {
int l, r;
cin >> l >> r;
l--; r--;
qu[l / K].pb({ l, r, i });
}
rep(bl, K) {
if (qu[bl].empty()) continue;
init();
sort(all(qu[bl]));
int bl_l = bl * K;
int bl_r = min((bl + 1) * K - 1, m - 1);
int pr = m - 1;
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();
}
}
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:160: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]
160 | while (ba.size() != was) {
| ~~~~~~~~~~^~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
3436 KB |
Output is correct |
2 |
Correct |
3 ms |
3436 KB |
Output is correct |
3 |
Correct |
3 ms |
3436 KB |
Output is correct |
4 |
Correct |
3 ms |
3436 KB |
Output is correct |
5 |
Correct |
3 ms |
3436 KB |
Output is correct |
6 |
Correct |
3 ms |
3436 KB |
Output is correct |
7 |
Correct |
3 ms |
3436 KB |
Output is correct |
8 |
Correct |
4 ms |
3564 KB |
Output is correct |
9 |
Correct |
5 ms |
3564 KB |
Output is correct |
10 |
Correct |
4 ms |
3564 KB |
Output is correct |
11 |
Correct |
4 ms |
3564 KB |
Output is correct |
12 |
Correct |
4 ms |
3564 KB |
Output is correct |
13 |
Correct |
4 ms |
3564 KB |
Output is correct |
14 |
Correct |
4 ms |
3584 KB |
Output is correct |
15 |
Correct |
4 ms |
3564 KB |
Output is correct |
16 |
Correct |
4 ms |
3564 KB |
Output is correct |
17 |
Correct |
4 ms |
3564 KB |
Output is correct |
18 |
Correct |
4 ms |
3564 KB |
Output is correct |
19 |
Correct |
4 ms |
3564 KB |
Output is correct |
20 |
Correct |
4 ms |
3436 KB |
Output is correct |
21 |
Correct |
4 ms |
3564 KB |
Output is correct |
22 |
Correct |
4 ms |
3564 KB |
Output is correct |
23 |
Correct |
4 ms |
3564 KB |
Output is correct |
24 |
Correct |
4 ms |
3564 KB |
Output is correct |
25 |
Correct |
4 ms |
3564 KB |
Output is correct |
26 |
Correct |
4 ms |
3564 KB |
Output is correct |
27 |
Correct |
4 ms |
3564 KB |
Output is correct |
28 |
Correct |
4 ms |
3564 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
3436 KB |
Output is correct |
2 |
Correct |
3 ms |
3436 KB |
Output is correct |
3 |
Correct |
3 ms |
3436 KB |
Output is correct |
4 |
Correct |
3 ms |
3436 KB |
Output is correct |
5 |
Correct |
3 ms |
3436 KB |
Output is correct |
6 |
Correct |
3 ms |
3436 KB |
Output is correct |
7 |
Correct |
3 ms |
3436 KB |
Output is correct |
8 |
Correct |
4 ms |
3564 KB |
Output is correct |
9 |
Correct |
5 ms |
3564 KB |
Output is correct |
10 |
Correct |
4 ms |
3564 KB |
Output is correct |
11 |
Correct |
4 ms |
3564 KB |
Output is correct |
12 |
Correct |
4 ms |
3564 KB |
Output is correct |
13 |
Correct |
4 ms |
3564 KB |
Output is correct |
14 |
Correct |
4 ms |
3584 KB |
Output is correct |
15 |
Correct |
4 ms |
3564 KB |
Output is correct |
16 |
Correct |
4 ms |
3564 KB |
Output is correct |
17 |
Correct |
4 ms |
3564 KB |
Output is correct |
18 |
Correct |
4 ms |
3564 KB |
Output is correct |
19 |
Correct |
4 ms |
3564 KB |
Output is correct |
20 |
Correct |
4 ms |
3436 KB |
Output is correct |
21 |
Correct |
4 ms |
3564 KB |
Output is correct |
22 |
Correct |
4 ms |
3564 KB |
Output is correct |
23 |
Correct |
4 ms |
3564 KB |
Output is correct |
24 |
Correct |
4 ms |
3564 KB |
Output is correct |
25 |
Correct |
4 ms |
3564 KB |
Output is correct |
26 |
Correct |
4 ms |
3564 KB |
Output is correct |
27 |
Correct |
4 ms |
3564 KB |
Output is correct |
28 |
Correct |
4 ms |
3564 KB |
Output is correct |
29 |
Correct |
27 ms |
3692 KB |
Output is correct |
30 |
Incorrect |
27 ms |
3820 KB |
Output isn't correct |
31 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
3436 KB |
Output is correct |
2 |
Correct |
3 ms |
3436 KB |
Output is correct |
3 |
Correct |
111 ms |
17848 KB |
Output is correct |
4 |
Correct |
121 ms |
21432 KB |
Output is correct |
5 |
Correct |
130 ms |
22108 KB |
Output is correct |
6 |
Correct |
114 ms |
17780 KB |
Output is correct |
7 |
Correct |
121 ms |
17888 KB |
Output is correct |
8 |
Correct |
110 ms |
15584 KB |
Output is correct |
9 |
Correct |
114 ms |
17120 KB |
Output is correct |
10 |
Correct |
129 ms |
21468 KB |
Output is correct |
11 |
Correct |
119 ms |
17760 KB |
Output is correct |
12 |
Correct |
144 ms |
21980 KB |
Output is correct |
13 |
Correct |
126 ms |
13928 KB |
Output is correct |
14 |
Correct |
118 ms |
16352 KB |
Output is correct |
15 |
Correct |
130 ms |
21932 KB |
Output is correct |
16 |
Correct |
131 ms |
21980 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
3436 KB |
Output is correct |
2 |
Correct |
3 ms |
3436 KB |
Output is correct |
3 |
Correct |
3 ms |
3436 KB |
Output is correct |
4 |
Correct |
3 ms |
3436 KB |
Output is correct |
5 |
Correct |
3 ms |
3436 KB |
Output is correct |
6 |
Correct |
3 ms |
3436 KB |
Output is correct |
7 |
Correct |
3 ms |
3436 KB |
Output is correct |
8 |
Correct |
4 ms |
3564 KB |
Output is correct |
9 |
Correct |
5 ms |
3564 KB |
Output is correct |
10 |
Correct |
4 ms |
3564 KB |
Output is correct |
11 |
Correct |
4 ms |
3564 KB |
Output is correct |
12 |
Correct |
4 ms |
3564 KB |
Output is correct |
13 |
Correct |
4 ms |
3564 KB |
Output is correct |
14 |
Correct |
4 ms |
3584 KB |
Output is correct |
15 |
Correct |
4 ms |
3564 KB |
Output is correct |
16 |
Correct |
4 ms |
3564 KB |
Output is correct |
17 |
Correct |
4 ms |
3564 KB |
Output is correct |
18 |
Correct |
4 ms |
3564 KB |
Output is correct |
19 |
Correct |
4 ms |
3564 KB |
Output is correct |
20 |
Correct |
4 ms |
3436 KB |
Output is correct |
21 |
Correct |
4 ms |
3564 KB |
Output is correct |
22 |
Correct |
4 ms |
3564 KB |
Output is correct |
23 |
Correct |
4 ms |
3564 KB |
Output is correct |
24 |
Correct |
4 ms |
3564 KB |
Output is correct |
25 |
Correct |
4 ms |
3564 KB |
Output is correct |
26 |
Correct |
4 ms |
3564 KB |
Output is correct |
27 |
Correct |
4 ms |
3564 KB |
Output is correct |
28 |
Correct |
4 ms |
3564 KB |
Output is correct |
29 |
Correct |
111 ms |
17848 KB |
Output is correct |
30 |
Correct |
121 ms |
21432 KB |
Output is correct |
31 |
Correct |
130 ms |
22108 KB |
Output is correct |
32 |
Correct |
114 ms |
17780 KB |
Output is correct |
33 |
Correct |
121 ms |
17888 KB |
Output is correct |
34 |
Correct |
110 ms |
15584 KB |
Output is correct |
35 |
Correct |
114 ms |
17120 KB |
Output is correct |
36 |
Correct |
129 ms |
21468 KB |
Output is correct |
37 |
Correct |
119 ms |
17760 KB |
Output is correct |
38 |
Correct |
144 ms |
21980 KB |
Output is correct |
39 |
Correct |
126 ms |
13928 KB |
Output is correct |
40 |
Correct |
118 ms |
16352 KB |
Output is correct |
41 |
Correct |
130 ms |
21932 KB |
Output is correct |
42 |
Correct |
131 ms |
21980 KB |
Output is correct |
43 |
Correct |
1113 ms |
18276 KB |
Output is correct |
44 |
Correct |
1157 ms |
22060 KB |
Output is correct |
45 |
Correct |
1179 ms |
22376 KB |
Output is correct |
46 |
Correct |
1096 ms |
18132 KB |
Output is correct |
47 |
Correct |
1396 ms |
18184 KB |
Output is correct |
48 |
Correct |
1197 ms |
17632 KB |
Output is correct |
49 |
Correct |
1288 ms |
21980 KB |
Output is correct |
50 |
Correct |
979 ms |
18284 KB |
Output is correct |
51 |
Correct |
1124 ms |
22364 KB |
Output is correct |
52 |
Correct |
1169 ms |
22352 KB |
Output is correct |
53 |
Correct |
965 ms |
14108 KB |
Output is correct |
54 |
Correct |
1434 ms |
18276 KB |
Output is correct |
55 |
Correct |
1464 ms |
22432 KB |
Output is correct |
56 |
Correct |
1516 ms |
22364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
3436 KB |
Output is correct |
2 |
Correct |
3 ms |
3436 KB |
Output is correct |
3 |
Correct |
3 ms |
3436 KB |
Output is correct |
4 |
Correct |
3 ms |
3436 KB |
Output is correct |
5 |
Correct |
3 ms |
3436 KB |
Output is correct |
6 |
Correct |
3 ms |
3436 KB |
Output is correct |
7 |
Correct |
3 ms |
3436 KB |
Output is correct |
8 |
Correct |
4 ms |
3564 KB |
Output is correct |
9 |
Correct |
5 ms |
3564 KB |
Output is correct |
10 |
Correct |
4 ms |
3564 KB |
Output is correct |
11 |
Correct |
4 ms |
3564 KB |
Output is correct |
12 |
Correct |
4 ms |
3564 KB |
Output is correct |
13 |
Correct |
4 ms |
3564 KB |
Output is correct |
14 |
Correct |
4 ms |
3584 KB |
Output is correct |
15 |
Correct |
4 ms |
3564 KB |
Output is correct |
16 |
Correct |
4 ms |
3564 KB |
Output is correct |
17 |
Correct |
4 ms |
3564 KB |
Output is correct |
18 |
Correct |
4 ms |
3564 KB |
Output is correct |
19 |
Correct |
4 ms |
3564 KB |
Output is correct |
20 |
Correct |
4 ms |
3436 KB |
Output is correct |
21 |
Correct |
4 ms |
3564 KB |
Output is correct |
22 |
Correct |
4 ms |
3564 KB |
Output is correct |
23 |
Correct |
4 ms |
3564 KB |
Output is correct |
24 |
Correct |
4 ms |
3564 KB |
Output is correct |
25 |
Correct |
4 ms |
3564 KB |
Output is correct |
26 |
Correct |
4 ms |
3564 KB |
Output is correct |
27 |
Correct |
4 ms |
3564 KB |
Output is correct |
28 |
Correct |
4 ms |
3564 KB |
Output is correct |
29 |
Correct |
27 ms |
3692 KB |
Output is correct |
30 |
Incorrect |
27 ms |
3820 KB |
Output isn't correct |
31 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
3436 KB |
Output is correct |
2 |
Correct |
3 ms |
3436 KB |
Output is correct |
3 |
Correct |
3 ms |
3436 KB |
Output is correct |
4 |
Correct |
3 ms |
3436 KB |
Output is correct |
5 |
Correct |
3 ms |
3436 KB |
Output is correct |
6 |
Correct |
3 ms |
3436 KB |
Output is correct |
7 |
Correct |
3 ms |
3436 KB |
Output is correct |
8 |
Correct |
4 ms |
3564 KB |
Output is correct |
9 |
Correct |
5 ms |
3564 KB |
Output is correct |
10 |
Correct |
4 ms |
3564 KB |
Output is correct |
11 |
Correct |
4 ms |
3564 KB |
Output is correct |
12 |
Correct |
4 ms |
3564 KB |
Output is correct |
13 |
Correct |
4 ms |
3564 KB |
Output is correct |
14 |
Correct |
4 ms |
3584 KB |
Output is correct |
15 |
Correct |
4 ms |
3564 KB |
Output is correct |
16 |
Correct |
4 ms |
3564 KB |
Output is correct |
17 |
Correct |
4 ms |
3564 KB |
Output is correct |
18 |
Correct |
4 ms |
3564 KB |
Output is correct |
19 |
Correct |
4 ms |
3564 KB |
Output is correct |
20 |
Correct |
4 ms |
3436 KB |
Output is correct |
21 |
Correct |
4 ms |
3564 KB |
Output is correct |
22 |
Correct |
4 ms |
3564 KB |
Output is correct |
23 |
Correct |
4 ms |
3564 KB |
Output is correct |
24 |
Correct |
4 ms |
3564 KB |
Output is correct |
25 |
Correct |
4 ms |
3564 KB |
Output is correct |
26 |
Correct |
4 ms |
3564 KB |
Output is correct |
27 |
Correct |
4 ms |
3564 KB |
Output is correct |
28 |
Correct |
4 ms |
3564 KB |
Output is correct |
29 |
Correct |
27 ms |
3692 KB |
Output is correct |
30 |
Incorrect |
27 ms |
3820 KB |
Output isn't correct |
31 |
Halted |
0 ms |
0 KB |
- |