#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;
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:138: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]
138 | while(p < que[l].size() && que[l][p][0] == i){
| ~~^~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
604 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 |
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 |
2 ms |
348 KB |
Output is correct |
11 |
Correct |
2 ms |
348 KB |
Output is correct |
12 |
Correct |
3 ms |
348 KB |
Output is correct |
13 |
Correct |
2 ms |
496 KB |
Output is correct |
14 |
Correct |
3 ms |
344 KB |
Output is correct |
15 |
Correct |
3 ms |
344 KB |
Output is correct |
16 |
Correct |
2 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
2 ms |
344 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 |
348 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 |
600 KB |
Output is correct |
25 |
Correct |
2 ms |
540 KB |
Output is correct |
26 |
Correct |
1 ms |
348 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 |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
604 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 |
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 |
2 ms |
348 KB |
Output is correct |
11 |
Correct |
2 ms |
348 KB |
Output is correct |
12 |
Correct |
3 ms |
348 KB |
Output is correct |
13 |
Correct |
2 ms |
496 KB |
Output is correct |
14 |
Correct |
3 ms |
344 KB |
Output is correct |
15 |
Correct |
3 ms |
344 KB |
Output is correct |
16 |
Correct |
2 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
2 ms |
344 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 |
348 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 |
600 KB |
Output is correct |
25 |
Correct |
2 ms |
540 KB |
Output is correct |
26 |
Correct |
1 ms |
348 KB |
Output is correct |
27 |
Correct |
2 ms |
348 KB |
Output is correct |
28 |
Correct |
2 ms |
348 KB |
Output is correct |
29 |
Correct |
170 ms |
860 KB |
Output is correct |
30 |
Correct |
140 ms |
1252 KB |
Output is correct |
31 |
Correct |
124 ms |
880 KB |
Output is correct |
32 |
Correct |
107 ms |
808 KB |
Output is correct |
33 |
Correct |
44 ms |
604 KB |
Output is correct |
34 |
Correct |
108 ms |
1032 KB |
Output is correct |
35 |
Correct |
286 ms |
2364 KB |
Output is correct |
36 |
Correct |
175 ms |
860 KB |
Output is correct |
37 |
Correct |
372 ms |
1120 KB |
Output is correct |
38 |
Correct |
406 ms |
1148 KB |
Output is correct |
39 |
Correct |
232 ms |
1116 KB |
Output is correct |
40 |
Correct |
160 ms |
860 KB |
Output is correct |
41 |
Correct |
158 ms |
860 KB |
Output is correct |
42 |
Correct |
158 ms |
860 KB |
Output is correct |
43 |
Correct |
196 ms |
1080 KB |
Output is correct |
44 |
Correct |
184 ms |
856 KB |
Output is correct |
45 |
Correct |
150 ms |
948 KB |
Output is correct |
46 |
Correct |
270 ms |
1024 KB |
Output is correct |
47 |
Correct |
158 ms |
852 KB |
Output is correct |
48 |
Correct |
170 ms |
856 KB |
Output is correct |
49 |
Correct |
206 ms |
1024 KB |
Output is correct |
50 |
Correct |
168 ms |
1056 KB |
Output is correct |
51 |
Correct |
159 ms |
856 KB |
Output is correct |
52 |
Correct |
174 ms |
860 KB |
Output is correct |
53 |
Correct |
187 ms |
872 KB |
Output is correct |
54 |
Correct |
270 ms |
1032 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
77 ms |
30272 KB |
Output is correct |
4 |
Correct |
126 ms |
49356 KB |
Output is correct |
5 |
Correct |
75 ms |
22724 KB |
Output is correct |
6 |
Correct |
82 ms |
30412 KB |
Output is correct |
7 |
Correct |
84 ms |
30276 KB |
Output is correct |
8 |
Correct |
81 ms |
28476 KB |
Output is correct |
9 |
Correct |
79 ms |
29696 KB |
Output is correct |
10 |
Correct |
79 ms |
33044 KB |
Output is correct |
11 |
Correct |
87 ms |
30272 KB |
Output is correct |
12 |
Correct |
90 ms |
33028 KB |
Output is correct |
13 |
Correct |
78 ms |
27652 KB |
Output is correct |
14 |
Correct |
81 ms |
29060 KB |
Output is correct |
15 |
Correct |
83 ms |
31544 KB |
Output is correct |
16 |
Correct |
84 ms |
33596 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
604 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 |
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 |
2 ms |
348 KB |
Output is correct |
11 |
Correct |
2 ms |
348 KB |
Output is correct |
12 |
Correct |
3 ms |
348 KB |
Output is correct |
13 |
Correct |
2 ms |
496 KB |
Output is correct |
14 |
Correct |
3 ms |
344 KB |
Output is correct |
15 |
Correct |
3 ms |
344 KB |
Output is correct |
16 |
Correct |
2 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
2 ms |
344 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 |
348 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 |
600 KB |
Output is correct |
25 |
Correct |
2 ms |
540 KB |
Output is correct |
26 |
Correct |
1 ms |
348 KB |
Output is correct |
27 |
Correct |
2 ms |
348 KB |
Output is correct |
28 |
Correct |
2 ms |
348 KB |
Output is correct |
29 |
Correct |
77 ms |
30272 KB |
Output is correct |
30 |
Correct |
126 ms |
49356 KB |
Output is correct |
31 |
Correct |
75 ms |
22724 KB |
Output is correct |
32 |
Correct |
82 ms |
30412 KB |
Output is correct |
33 |
Correct |
84 ms |
30276 KB |
Output is correct |
34 |
Correct |
81 ms |
28476 KB |
Output is correct |
35 |
Correct |
79 ms |
29696 KB |
Output is correct |
36 |
Correct |
79 ms |
33044 KB |
Output is correct |
37 |
Correct |
87 ms |
30272 KB |
Output is correct |
38 |
Correct |
90 ms |
33028 KB |
Output is correct |
39 |
Correct |
78 ms |
27652 KB |
Output is correct |
40 |
Correct |
81 ms |
29060 KB |
Output is correct |
41 |
Correct |
83 ms |
31544 KB |
Output is correct |
42 |
Correct |
84 ms |
33596 KB |
Output is correct |
43 |
Execution timed out |
2070 ms |
44332 KB |
Time limit exceeded |
44 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
604 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 |
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 |
2 ms |
348 KB |
Output is correct |
11 |
Correct |
2 ms |
348 KB |
Output is correct |
12 |
Correct |
3 ms |
348 KB |
Output is correct |
13 |
Correct |
2 ms |
496 KB |
Output is correct |
14 |
Correct |
3 ms |
344 KB |
Output is correct |
15 |
Correct |
3 ms |
344 KB |
Output is correct |
16 |
Correct |
2 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
2 ms |
344 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 |
348 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 |
600 KB |
Output is correct |
25 |
Correct |
2 ms |
540 KB |
Output is correct |
26 |
Correct |
1 ms |
348 KB |
Output is correct |
27 |
Correct |
2 ms |
348 KB |
Output is correct |
28 |
Correct |
2 ms |
348 KB |
Output is correct |
29 |
Correct |
170 ms |
860 KB |
Output is correct |
30 |
Correct |
140 ms |
1252 KB |
Output is correct |
31 |
Correct |
124 ms |
880 KB |
Output is correct |
32 |
Correct |
107 ms |
808 KB |
Output is correct |
33 |
Correct |
44 ms |
604 KB |
Output is correct |
34 |
Correct |
108 ms |
1032 KB |
Output is correct |
35 |
Correct |
286 ms |
2364 KB |
Output is correct |
36 |
Correct |
175 ms |
860 KB |
Output is correct |
37 |
Correct |
372 ms |
1120 KB |
Output is correct |
38 |
Correct |
406 ms |
1148 KB |
Output is correct |
39 |
Correct |
232 ms |
1116 KB |
Output is correct |
40 |
Correct |
160 ms |
860 KB |
Output is correct |
41 |
Correct |
158 ms |
860 KB |
Output is correct |
42 |
Correct |
158 ms |
860 KB |
Output is correct |
43 |
Correct |
196 ms |
1080 KB |
Output is correct |
44 |
Correct |
184 ms |
856 KB |
Output is correct |
45 |
Correct |
150 ms |
948 KB |
Output is correct |
46 |
Correct |
270 ms |
1024 KB |
Output is correct |
47 |
Correct |
158 ms |
852 KB |
Output is correct |
48 |
Correct |
170 ms |
856 KB |
Output is correct |
49 |
Correct |
206 ms |
1024 KB |
Output is correct |
50 |
Correct |
168 ms |
1056 KB |
Output is correct |
51 |
Correct |
159 ms |
856 KB |
Output is correct |
52 |
Correct |
174 ms |
860 KB |
Output is correct |
53 |
Correct |
187 ms |
872 KB |
Output is correct |
54 |
Correct |
270 ms |
1032 KB |
Output is correct |
55 |
Runtime error |
23 ms |
9300 KB |
Execution killed with signal 11 |
56 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
604 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 |
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 |
2 ms |
348 KB |
Output is correct |
11 |
Correct |
2 ms |
348 KB |
Output is correct |
12 |
Correct |
3 ms |
348 KB |
Output is correct |
13 |
Correct |
2 ms |
496 KB |
Output is correct |
14 |
Correct |
3 ms |
344 KB |
Output is correct |
15 |
Correct |
3 ms |
344 KB |
Output is correct |
16 |
Correct |
2 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
2 ms |
344 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 |
348 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 |
600 KB |
Output is correct |
25 |
Correct |
2 ms |
540 KB |
Output is correct |
26 |
Correct |
1 ms |
348 KB |
Output is correct |
27 |
Correct |
2 ms |
348 KB |
Output is correct |
28 |
Correct |
2 ms |
348 KB |
Output is correct |
29 |
Correct |
170 ms |
860 KB |
Output is correct |
30 |
Correct |
140 ms |
1252 KB |
Output is correct |
31 |
Correct |
124 ms |
880 KB |
Output is correct |
32 |
Correct |
107 ms |
808 KB |
Output is correct |
33 |
Correct |
44 ms |
604 KB |
Output is correct |
34 |
Correct |
108 ms |
1032 KB |
Output is correct |
35 |
Correct |
286 ms |
2364 KB |
Output is correct |
36 |
Correct |
175 ms |
860 KB |
Output is correct |
37 |
Correct |
372 ms |
1120 KB |
Output is correct |
38 |
Correct |
406 ms |
1148 KB |
Output is correct |
39 |
Correct |
232 ms |
1116 KB |
Output is correct |
40 |
Correct |
160 ms |
860 KB |
Output is correct |
41 |
Correct |
158 ms |
860 KB |
Output is correct |
42 |
Correct |
158 ms |
860 KB |
Output is correct |
43 |
Correct |
196 ms |
1080 KB |
Output is correct |
44 |
Correct |
184 ms |
856 KB |
Output is correct |
45 |
Correct |
150 ms |
948 KB |
Output is correct |
46 |
Correct |
270 ms |
1024 KB |
Output is correct |
47 |
Correct |
158 ms |
852 KB |
Output is correct |
48 |
Correct |
170 ms |
856 KB |
Output is correct |
49 |
Correct |
206 ms |
1024 KB |
Output is correct |
50 |
Correct |
168 ms |
1056 KB |
Output is correct |
51 |
Correct |
159 ms |
856 KB |
Output is correct |
52 |
Correct |
174 ms |
860 KB |
Output is correct |
53 |
Correct |
187 ms |
872 KB |
Output is correct |
54 |
Correct |
270 ms |
1032 KB |
Output is correct |
55 |
Correct |
77 ms |
30272 KB |
Output is correct |
56 |
Correct |
126 ms |
49356 KB |
Output is correct |
57 |
Correct |
75 ms |
22724 KB |
Output is correct |
58 |
Correct |
82 ms |
30412 KB |
Output is correct |
59 |
Correct |
84 ms |
30276 KB |
Output is correct |
60 |
Correct |
81 ms |
28476 KB |
Output is correct |
61 |
Correct |
79 ms |
29696 KB |
Output is correct |
62 |
Correct |
79 ms |
33044 KB |
Output is correct |
63 |
Correct |
87 ms |
30272 KB |
Output is correct |
64 |
Correct |
90 ms |
33028 KB |
Output is correct |
65 |
Correct |
78 ms |
27652 KB |
Output is correct |
66 |
Correct |
81 ms |
29060 KB |
Output is correct |
67 |
Correct |
83 ms |
31544 KB |
Output is correct |
68 |
Correct |
84 ms |
33596 KB |
Output is correct |
69 |
Execution timed out |
2070 ms |
44332 KB |
Time limit exceeded |
70 |
Halted |
0 ms |
0 KB |
- |