# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
877218 |
2023-11-23T03:57:58 Z |
hotboy2703 |
Joker (BOI20_joker) |
C++14 |
|
2000 ms |
14812 KB |
#include<bits/stdc++.h>
using namespace std;
#define pll pair <ll,ll>
#define fi first
#define se second
using ll = int;
ll n,m,q;
namespace DSU{
ll dsu[200100];
ll rev[200100];
void init(){
memset(dsu,-1,sizeof dsu);
memset(rev,-1,sizeof rev);
}
ll f(ll x){
if (dsu[x] < 0)return x;
return (dsu[x] = f(dsu[x]));
}
void m(ll x,ll y){
if (x == -1 || y == -1)return;
if (dsu[x] > dsu[y])swap(x,y);
dsu[x] += dsu[y];
dsu[y] = x;
}
bool join(ll x,ll y){
x = f(x),y = f(y);
if (x==y)return 0;
if (rev[x] == y)return 1;
else{
m(x,rev[y]);
m(rev[x],y);
x = f(x);
y = f(y);
rev[x] = y;
rev[y] = x;
return 1;
}
}
}
pll a[200100];
ll color[200100];
ll pre[200100];
vector <ll> g[200100];
int main(){
ios_base::sync_with_stdio(0);cin.tie(nullptr);cout.tie(nullptr);
cin>>n>>m>>q;
for (ll i = 1;i <= m;i ++)cin>>a[i].fi>>a[i].se;
if (q <= 2000){
while (q--){
ll l,r;
cin>>l>>r;
for (ll i = 1;i <= n;i ++){
color[i] = -1;
g[i].clear();
}
for (ll i = 1;i < l;i ++){
g[a[i].fi].push_back(a[i].se);
g[a[i].se].push_back(a[i].fi);
}
for (ll i = r + 1;i <= m;i ++){
g[a[i].fi].push_back(a[i].se);
g[a[i].se].push_back(a[i].fi);
}
bool ok = 0;
for (ll i = 1;i <= n;i ++){
if (color[i] == -1){
color[i] = 0;
queue <ll> q;
q.push(i);
while (!q.empty()){
ll u = q.front();
q.pop();
for (auto v:g[u]){
if (color[v] == -1){
color[v] = 1-color[u];
q.push(v);
}
else{
if (color[v] == color[u]){
ok = 1;
break;
}
}
}
}
if (ok)break;
}
}
cout<<(ok?"YES":"NO")<<'\n';
}
}
else{
for (ll i = 0;i < m;i ++){
pre[i] = m+1;
}
for (ll i = 0;i < min(m,201);i ++){
DSU::init();
bool ok = 1;
for (ll j = 1;j <= i;j ++){
ok &= DSU::join(a[j].fi,a[j].se);
}
if (ok == 0)break;
while (pre[i] > i + 1 && DSU::join(a[pre[i]-1].fi,a[pre[i] - 1].se)){
pre[i]--;
}
}
for (ll i = 1;i <= q;i ++){
ll l,r;
cin>>l>>r;
if (r < pre[l-1] - 1){
cout<<"YES";
}
else{
cout<<"NO";
}
cout<<'\n';
}
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
6744 KB |
Output is correct |
2 |
Correct |
1 ms |
6748 KB |
Output is correct |
3 |
Correct |
1 ms |
6748 KB |
Output is correct |
4 |
Correct |
1 ms |
6748 KB |
Output is correct |
5 |
Correct |
1 ms |
6748 KB |
Output is correct |
6 |
Correct |
1 ms |
6748 KB |
Output is correct |
7 |
Correct |
2 ms |
6796 KB |
Output is correct |
8 |
Correct |
2 ms |
6748 KB |
Output is correct |
9 |
Correct |
2 ms |
6748 KB |
Output is correct |
10 |
Correct |
2 ms |
6748 KB |
Output is correct |
11 |
Correct |
2 ms |
6748 KB |
Output is correct |
12 |
Correct |
2 ms |
6800 KB |
Output is correct |
13 |
Correct |
2 ms |
6744 KB |
Output is correct |
14 |
Correct |
2 ms |
6748 KB |
Output is correct |
15 |
Correct |
2 ms |
6748 KB |
Output is correct |
16 |
Correct |
2 ms |
6748 KB |
Output is correct |
17 |
Correct |
2 ms |
6748 KB |
Output is correct |
18 |
Correct |
2 ms |
6588 KB |
Output is correct |
19 |
Correct |
2 ms |
6748 KB |
Output is correct |
20 |
Correct |
2 ms |
6748 KB |
Output is correct |
21 |
Correct |
2 ms |
6748 KB |
Output is correct |
22 |
Correct |
2 ms |
6748 KB |
Output is correct |
23 |
Correct |
2 ms |
6748 KB |
Output is correct |
24 |
Correct |
2 ms |
6792 KB |
Output is correct |
25 |
Correct |
2 ms |
6748 KB |
Output is correct |
26 |
Correct |
2 ms |
6748 KB |
Output is correct |
27 |
Correct |
2 ms |
6748 KB |
Output is correct |
28 |
Correct |
2 ms |
6748 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
6744 KB |
Output is correct |
2 |
Correct |
1 ms |
6748 KB |
Output is correct |
3 |
Correct |
1 ms |
6748 KB |
Output is correct |
4 |
Correct |
1 ms |
6748 KB |
Output is correct |
5 |
Correct |
1 ms |
6748 KB |
Output is correct |
6 |
Correct |
1 ms |
6748 KB |
Output is correct |
7 |
Correct |
2 ms |
6796 KB |
Output is correct |
8 |
Correct |
2 ms |
6748 KB |
Output is correct |
9 |
Correct |
2 ms |
6748 KB |
Output is correct |
10 |
Correct |
2 ms |
6748 KB |
Output is correct |
11 |
Correct |
2 ms |
6748 KB |
Output is correct |
12 |
Correct |
2 ms |
6800 KB |
Output is correct |
13 |
Correct |
2 ms |
6744 KB |
Output is correct |
14 |
Correct |
2 ms |
6748 KB |
Output is correct |
15 |
Correct |
2 ms |
6748 KB |
Output is correct |
16 |
Correct |
2 ms |
6748 KB |
Output is correct |
17 |
Correct |
2 ms |
6748 KB |
Output is correct |
18 |
Correct |
2 ms |
6588 KB |
Output is correct |
19 |
Correct |
2 ms |
6748 KB |
Output is correct |
20 |
Correct |
2 ms |
6748 KB |
Output is correct |
21 |
Correct |
2 ms |
6748 KB |
Output is correct |
22 |
Correct |
2 ms |
6748 KB |
Output is correct |
23 |
Correct |
2 ms |
6748 KB |
Output is correct |
24 |
Correct |
2 ms |
6792 KB |
Output is correct |
25 |
Correct |
2 ms |
6748 KB |
Output is correct |
26 |
Correct |
2 ms |
6748 KB |
Output is correct |
27 |
Correct |
2 ms |
6748 KB |
Output is correct |
28 |
Correct |
2 ms |
6748 KB |
Output is correct |
29 |
Correct |
114 ms |
6836 KB |
Output is correct |
30 |
Correct |
88 ms |
6748 KB |
Output is correct |
31 |
Correct |
78 ms |
6748 KB |
Output is correct |
32 |
Correct |
54 ms |
6744 KB |
Output is correct |
33 |
Correct |
35 ms |
6748 KB |
Output is correct |
34 |
Correct |
76 ms |
6868 KB |
Output is correct |
35 |
Correct |
101 ms |
6876 KB |
Output is correct |
36 |
Correct |
30 ms |
6744 KB |
Output is correct |
37 |
Correct |
80 ms |
6996 KB |
Output is correct |
38 |
Correct |
56 ms |
6748 KB |
Output is correct |
39 |
Correct |
84 ms |
6744 KB |
Output is correct |
40 |
Correct |
57 ms |
6748 KB |
Output is correct |
41 |
Correct |
57 ms |
6748 KB |
Output is correct |
42 |
Correct |
57 ms |
7000 KB |
Output is correct |
43 |
Correct |
28 ms |
6744 KB |
Output is correct |
44 |
Correct |
39 ms |
6744 KB |
Output is correct |
45 |
Correct |
50 ms |
6744 KB |
Output is correct |
46 |
Correct |
54 ms |
6744 KB |
Output is correct |
47 |
Correct |
51 ms |
7004 KB |
Output is correct |
48 |
Correct |
54 ms |
6748 KB |
Output is correct |
49 |
Correct |
68 ms |
6744 KB |
Output is correct |
50 |
Correct |
92 ms |
6744 KB |
Output is correct |
51 |
Correct |
43 ms |
6872 KB |
Output is correct |
52 |
Correct |
57 ms |
6748 KB |
Output is correct |
53 |
Correct |
75 ms |
6748 KB |
Output is correct |
54 |
Correct |
91 ms |
6748 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
6744 KB |
Output is correct |
2 |
Correct |
1 ms |
6748 KB |
Output is correct |
3 |
Correct |
412 ms |
10344 KB |
Output is correct |
4 |
Correct |
985 ms |
10580 KB |
Output is correct |
5 |
Correct |
116 ms |
10376 KB |
Output is correct |
6 |
Correct |
114 ms |
14440 KB |
Output is correct |
7 |
Correct |
120 ms |
14416 KB |
Output is correct |
8 |
Correct |
262 ms |
13844 KB |
Output is correct |
9 |
Correct |
293 ms |
13920 KB |
Output is correct |
10 |
Correct |
559 ms |
14040 KB |
Output is correct |
11 |
Correct |
519 ms |
14368 KB |
Output is correct |
12 |
Correct |
487 ms |
14420 KB |
Output is correct |
13 |
Correct |
251 ms |
14364 KB |
Output is correct |
14 |
Correct |
276 ms |
14328 KB |
Output is correct |
15 |
Correct |
483 ms |
14304 KB |
Output is correct |
16 |
Correct |
548 ms |
14420 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
6744 KB |
Output is correct |
2 |
Correct |
1 ms |
6748 KB |
Output is correct |
3 |
Correct |
1 ms |
6748 KB |
Output is correct |
4 |
Correct |
1 ms |
6748 KB |
Output is correct |
5 |
Correct |
1 ms |
6748 KB |
Output is correct |
6 |
Correct |
1 ms |
6748 KB |
Output is correct |
7 |
Correct |
2 ms |
6796 KB |
Output is correct |
8 |
Correct |
2 ms |
6748 KB |
Output is correct |
9 |
Correct |
2 ms |
6748 KB |
Output is correct |
10 |
Correct |
2 ms |
6748 KB |
Output is correct |
11 |
Correct |
2 ms |
6748 KB |
Output is correct |
12 |
Correct |
2 ms |
6800 KB |
Output is correct |
13 |
Correct |
2 ms |
6744 KB |
Output is correct |
14 |
Correct |
2 ms |
6748 KB |
Output is correct |
15 |
Correct |
2 ms |
6748 KB |
Output is correct |
16 |
Correct |
2 ms |
6748 KB |
Output is correct |
17 |
Correct |
2 ms |
6748 KB |
Output is correct |
18 |
Correct |
2 ms |
6588 KB |
Output is correct |
19 |
Correct |
2 ms |
6748 KB |
Output is correct |
20 |
Correct |
2 ms |
6748 KB |
Output is correct |
21 |
Correct |
2 ms |
6748 KB |
Output is correct |
22 |
Correct |
2 ms |
6748 KB |
Output is correct |
23 |
Correct |
2 ms |
6748 KB |
Output is correct |
24 |
Correct |
2 ms |
6792 KB |
Output is correct |
25 |
Correct |
2 ms |
6748 KB |
Output is correct |
26 |
Correct |
2 ms |
6748 KB |
Output is correct |
27 |
Correct |
2 ms |
6748 KB |
Output is correct |
28 |
Correct |
2 ms |
6748 KB |
Output is correct |
29 |
Correct |
412 ms |
10344 KB |
Output is correct |
30 |
Correct |
985 ms |
10580 KB |
Output is correct |
31 |
Correct |
116 ms |
10376 KB |
Output is correct |
32 |
Correct |
114 ms |
14440 KB |
Output is correct |
33 |
Correct |
120 ms |
14416 KB |
Output is correct |
34 |
Correct |
262 ms |
13844 KB |
Output is correct |
35 |
Correct |
293 ms |
13920 KB |
Output is correct |
36 |
Correct |
559 ms |
14040 KB |
Output is correct |
37 |
Correct |
519 ms |
14368 KB |
Output is correct |
38 |
Correct |
487 ms |
14420 KB |
Output is correct |
39 |
Correct |
251 ms |
14364 KB |
Output is correct |
40 |
Correct |
276 ms |
14328 KB |
Output is correct |
41 |
Correct |
483 ms |
14304 KB |
Output is correct |
42 |
Correct |
548 ms |
14420 KB |
Output is correct |
43 |
Correct |
420 ms |
14724 KB |
Output is correct |
44 |
Correct |
983 ms |
14292 KB |
Output is correct |
45 |
Correct |
890 ms |
14808 KB |
Output is correct |
46 |
Correct |
91 ms |
14760 KB |
Output is correct |
47 |
Correct |
100 ms |
14576 KB |
Output is correct |
48 |
Correct |
341 ms |
14424 KB |
Output is correct |
49 |
Correct |
603 ms |
14552 KB |
Output is correct |
50 |
Correct |
548 ms |
14552 KB |
Output is correct |
51 |
Correct |
550 ms |
14812 KB |
Output is correct |
52 |
Correct |
508 ms |
14804 KB |
Output is correct |
53 |
Correct |
229 ms |
14428 KB |
Output is correct |
54 |
Correct |
327 ms |
14784 KB |
Output is correct |
55 |
Correct |
485 ms |
14808 KB |
Output is correct |
56 |
Correct |
582 ms |
14804 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
6744 KB |
Output is correct |
2 |
Correct |
1 ms |
6748 KB |
Output is correct |
3 |
Correct |
1 ms |
6748 KB |
Output is correct |
4 |
Correct |
1 ms |
6748 KB |
Output is correct |
5 |
Correct |
1 ms |
6748 KB |
Output is correct |
6 |
Correct |
1 ms |
6748 KB |
Output is correct |
7 |
Correct |
2 ms |
6796 KB |
Output is correct |
8 |
Correct |
2 ms |
6748 KB |
Output is correct |
9 |
Correct |
2 ms |
6748 KB |
Output is correct |
10 |
Correct |
2 ms |
6748 KB |
Output is correct |
11 |
Correct |
2 ms |
6748 KB |
Output is correct |
12 |
Correct |
2 ms |
6800 KB |
Output is correct |
13 |
Correct |
2 ms |
6744 KB |
Output is correct |
14 |
Correct |
2 ms |
6748 KB |
Output is correct |
15 |
Correct |
2 ms |
6748 KB |
Output is correct |
16 |
Correct |
2 ms |
6748 KB |
Output is correct |
17 |
Correct |
2 ms |
6748 KB |
Output is correct |
18 |
Correct |
2 ms |
6588 KB |
Output is correct |
19 |
Correct |
2 ms |
6748 KB |
Output is correct |
20 |
Correct |
2 ms |
6748 KB |
Output is correct |
21 |
Correct |
2 ms |
6748 KB |
Output is correct |
22 |
Correct |
2 ms |
6748 KB |
Output is correct |
23 |
Correct |
2 ms |
6748 KB |
Output is correct |
24 |
Correct |
2 ms |
6792 KB |
Output is correct |
25 |
Correct |
2 ms |
6748 KB |
Output is correct |
26 |
Correct |
2 ms |
6748 KB |
Output is correct |
27 |
Correct |
2 ms |
6748 KB |
Output is correct |
28 |
Correct |
2 ms |
6748 KB |
Output is correct |
29 |
Correct |
114 ms |
6836 KB |
Output is correct |
30 |
Correct |
88 ms |
6748 KB |
Output is correct |
31 |
Correct |
78 ms |
6748 KB |
Output is correct |
32 |
Correct |
54 ms |
6744 KB |
Output is correct |
33 |
Correct |
35 ms |
6748 KB |
Output is correct |
34 |
Correct |
76 ms |
6868 KB |
Output is correct |
35 |
Correct |
101 ms |
6876 KB |
Output is correct |
36 |
Correct |
30 ms |
6744 KB |
Output is correct |
37 |
Correct |
80 ms |
6996 KB |
Output is correct |
38 |
Correct |
56 ms |
6748 KB |
Output is correct |
39 |
Correct |
84 ms |
6744 KB |
Output is correct |
40 |
Correct |
57 ms |
6748 KB |
Output is correct |
41 |
Correct |
57 ms |
6748 KB |
Output is correct |
42 |
Correct |
57 ms |
7000 KB |
Output is correct |
43 |
Correct |
28 ms |
6744 KB |
Output is correct |
44 |
Correct |
39 ms |
6744 KB |
Output is correct |
45 |
Correct |
50 ms |
6744 KB |
Output is correct |
46 |
Correct |
54 ms |
6744 KB |
Output is correct |
47 |
Correct |
51 ms |
7004 KB |
Output is correct |
48 |
Correct |
54 ms |
6748 KB |
Output is correct |
49 |
Correct |
68 ms |
6744 KB |
Output is correct |
50 |
Correct |
92 ms |
6744 KB |
Output is correct |
51 |
Correct |
43 ms |
6872 KB |
Output is correct |
52 |
Correct |
57 ms |
6748 KB |
Output is correct |
53 |
Correct |
75 ms |
6748 KB |
Output is correct |
54 |
Correct |
91 ms |
6748 KB |
Output is correct |
55 |
Execution timed out |
2004 ms |
14288 KB |
Time limit exceeded |
56 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
6744 KB |
Output is correct |
2 |
Correct |
1 ms |
6748 KB |
Output is correct |
3 |
Correct |
1 ms |
6748 KB |
Output is correct |
4 |
Correct |
1 ms |
6748 KB |
Output is correct |
5 |
Correct |
1 ms |
6748 KB |
Output is correct |
6 |
Correct |
1 ms |
6748 KB |
Output is correct |
7 |
Correct |
2 ms |
6796 KB |
Output is correct |
8 |
Correct |
2 ms |
6748 KB |
Output is correct |
9 |
Correct |
2 ms |
6748 KB |
Output is correct |
10 |
Correct |
2 ms |
6748 KB |
Output is correct |
11 |
Correct |
2 ms |
6748 KB |
Output is correct |
12 |
Correct |
2 ms |
6800 KB |
Output is correct |
13 |
Correct |
2 ms |
6744 KB |
Output is correct |
14 |
Correct |
2 ms |
6748 KB |
Output is correct |
15 |
Correct |
2 ms |
6748 KB |
Output is correct |
16 |
Correct |
2 ms |
6748 KB |
Output is correct |
17 |
Correct |
2 ms |
6748 KB |
Output is correct |
18 |
Correct |
2 ms |
6588 KB |
Output is correct |
19 |
Correct |
2 ms |
6748 KB |
Output is correct |
20 |
Correct |
2 ms |
6748 KB |
Output is correct |
21 |
Correct |
2 ms |
6748 KB |
Output is correct |
22 |
Correct |
2 ms |
6748 KB |
Output is correct |
23 |
Correct |
2 ms |
6748 KB |
Output is correct |
24 |
Correct |
2 ms |
6792 KB |
Output is correct |
25 |
Correct |
2 ms |
6748 KB |
Output is correct |
26 |
Correct |
2 ms |
6748 KB |
Output is correct |
27 |
Correct |
2 ms |
6748 KB |
Output is correct |
28 |
Correct |
2 ms |
6748 KB |
Output is correct |
29 |
Correct |
114 ms |
6836 KB |
Output is correct |
30 |
Correct |
88 ms |
6748 KB |
Output is correct |
31 |
Correct |
78 ms |
6748 KB |
Output is correct |
32 |
Correct |
54 ms |
6744 KB |
Output is correct |
33 |
Correct |
35 ms |
6748 KB |
Output is correct |
34 |
Correct |
76 ms |
6868 KB |
Output is correct |
35 |
Correct |
101 ms |
6876 KB |
Output is correct |
36 |
Correct |
30 ms |
6744 KB |
Output is correct |
37 |
Correct |
80 ms |
6996 KB |
Output is correct |
38 |
Correct |
56 ms |
6748 KB |
Output is correct |
39 |
Correct |
84 ms |
6744 KB |
Output is correct |
40 |
Correct |
57 ms |
6748 KB |
Output is correct |
41 |
Correct |
57 ms |
6748 KB |
Output is correct |
42 |
Correct |
57 ms |
7000 KB |
Output is correct |
43 |
Correct |
28 ms |
6744 KB |
Output is correct |
44 |
Correct |
39 ms |
6744 KB |
Output is correct |
45 |
Correct |
50 ms |
6744 KB |
Output is correct |
46 |
Correct |
54 ms |
6744 KB |
Output is correct |
47 |
Correct |
51 ms |
7004 KB |
Output is correct |
48 |
Correct |
54 ms |
6748 KB |
Output is correct |
49 |
Correct |
68 ms |
6744 KB |
Output is correct |
50 |
Correct |
92 ms |
6744 KB |
Output is correct |
51 |
Correct |
43 ms |
6872 KB |
Output is correct |
52 |
Correct |
57 ms |
6748 KB |
Output is correct |
53 |
Correct |
75 ms |
6748 KB |
Output is correct |
54 |
Correct |
91 ms |
6748 KB |
Output is correct |
55 |
Correct |
412 ms |
10344 KB |
Output is correct |
56 |
Correct |
985 ms |
10580 KB |
Output is correct |
57 |
Correct |
116 ms |
10376 KB |
Output is correct |
58 |
Correct |
114 ms |
14440 KB |
Output is correct |
59 |
Correct |
120 ms |
14416 KB |
Output is correct |
60 |
Correct |
262 ms |
13844 KB |
Output is correct |
61 |
Correct |
293 ms |
13920 KB |
Output is correct |
62 |
Correct |
559 ms |
14040 KB |
Output is correct |
63 |
Correct |
519 ms |
14368 KB |
Output is correct |
64 |
Correct |
487 ms |
14420 KB |
Output is correct |
65 |
Correct |
251 ms |
14364 KB |
Output is correct |
66 |
Correct |
276 ms |
14328 KB |
Output is correct |
67 |
Correct |
483 ms |
14304 KB |
Output is correct |
68 |
Correct |
548 ms |
14420 KB |
Output is correct |
69 |
Correct |
420 ms |
14724 KB |
Output is correct |
70 |
Correct |
983 ms |
14292 KB |
Output is correct |
71 |
Correct |
890 ms |
14808 KB |
Output is correct |
72 |
Correct |
91 ms |
14760 KB |
Output is correct |
73 |
Correct |
100 ms |
14576 KB |
Output is correct |
74 |
Correct |
341 ms |
14424 KB |
Output is correct |
75 |
Correct |
603 ms |
14552 KB |
Output is correct |
76 |
Correct |
548 ms |
14552 KB |
Output is correct |
77 |
Correct |
550 ms |
14812 KB |
Output is correct |
78 |
Correct |
508 ms |
14804 KB |
Output is correct |
79 |
Correct |
229 ms |
14428 KB |
Output is correct |
80 |
Correct |
327 ms |
14784 KB |
Output is correct |
81 |
Correct |
485 ms |
14808 KB |
Output is correct |
82 |
Correct |
582 ms |
14804 KB |
Output is correct |
83 |
Execution timed out |
2004 ms |
14288 KB |
Time limit exceeded |
84 |
Halted |
0 ms |
0 KB |
- |