# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1114243 |
2024-11-18T12:17:20 Z |
raczek |
Joker (BOI20_joker) |
C++17 |
|
2000 ms |
27920 KB |
#include<bits/stdc++.h>
using namespace std;
#ifdef DEBUG
auto&operator<<(auto&o,pair<auto,auto>p){return o<<"("<<p.first<<", "<<p.second<<")";}
auto operator<<(auto&o,auto x)->decltype(x.end(),o){o<<"{";int i=0;for(auto e:x)o<<","+!i++<<e;return o<<"}";}
#define debug(X...)cerr<<"["#X"]: ",[](auto...$){((cerr<<$<<"; "),...)<<endl;}(X)
#else
#define debug(...){}
#endif
#define int long long
struct DSU{
int isOddCyc = 0;
vector<int> par;
vector<int> rnk;
vector<pair<int, int> > edg;
vector<pair<int&, int> > stck;
vector<int> operWght;
int Find(int a){
return (par[a] == a) ? a : Find(par[a]);
}
void Union(int a, int b){
a = Find(a), b = Find(b);
if(a == b) return;
if(rnk[a] < rnk[b]) swap(a, b);
stck.push_back({rnk[a], rnk[a]});
stck.push_back({par[b], par[b]});
rnk[a] += rnk[b];
par[b] = a;
}
int add(int x){
debug(x);
debug(edg[x]);
int t = stck.size();
Union(edg[x].first, edg[x].second^1);
Union(edg[x].first^1, edg[x].second);
if(Find(edg[x].first) == Find(edg[x].first^1)){
stck.push_back({isOddCyc, isOddCyc});
isOddCyc = true;
}
if(Find(edg[x].second) == Find(edg[x].second^1)){
stck.push_back({isOddCyc, isOddCyc});
isOddCyc = true;
}
operWght.push_back(stck.size() - t);
return +1;
}
int rollback(){
while(operWght.back() --> 0){
stck.back().first = stck.back().second;
stck.pop_back();
}
operWght.pop_back();
return -1;
}
void init(int n, vector<pair<int, int >> e){
edg = e;
for(auto& v : edg) v.first--, v.second--;
for(auto& v : edg) v.first*=2, v.second*=2;
par.resize(n*2);
rnk.resize(n*2);
for(int i=0;i<2*n;i++) par[i] = i, rnk[i] = 1;
}
};
struct solve{
vector<int> pos;
DSU dsu;
int n, m, q;
void rec(int l1, int l2, int r1, int r2){
debug(l1, l2, r1, r2);
if(l1 > l2) return;
if(r1 > r2) return;
int mid = (l1 + l2) >> 1;
for(int i=l1;i<=mid;i++)
dsu.add(i);
debug(mid);
debug(dsu.isOddCyc);
int opt = r2;
int cnt = 0;
if(!dsu.isOddCyc)
for(int i=r2-1;i>=r1;i--){
cnt += dsu.add(i);
if(dsu.isOddCyc == true){
opt = i;
break;
}
}
pos[mid] = opt;
int d = r2 - opt;
while(d --> 0) cnt += dsu.rollback();
for(int i=r1;i<max(mid+1, opt);i++) cnt += dsu.add(i);
rec(mid+1, l2, max(mid+1, opt), r2);
d = max(mid+1, opt) - r1 + mid - l1 + 1;
while(d --> 0) cnt += dsu.rollback();
for(int i=min(r2, m-1);i>opt;i--) cnt += dsu.add(i);
for(int i=l2;i>=mid;i--) cnt += dsu.add(i);
rec(l1, mid-1, r1, opt);
while(cnt --> 0) dsu.rollback();
}
solve()
{
cin>>n>>m>>q;
pos.resize(m+1);
vector<pair<int, int> > e(m);
for(auto& v : e) cin>>v.first>>v.second;
dsu.init(n, e);
//rec(0, m-1, 0, m);
for(int i=0;i<=m;i++)
{
if(i > 0)
dsu.add(i-1);
if(dsu.isOddCyc) {pos[i] = m+1; continue;}
int cnt = 0;
for(int j=m-1;j>i;j--){
cnt += dsu.add(j);
if(dsu.isOddCyc) {pos[i] = j+1; break;}
}
while(cnt --> 0) dsu.rollback();
}
debug(pos);
while(q --> 0)
{
int l, r;
cin>>l>>r;
if(pos[l-1] > r) cout<<"YES\n";
else cout<<"NO\n";
}
}
};
int32_t main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
solve a;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
2 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
1 ms |
336 KB |
Output is correct |
13 |
Correct |
1 ms |
336 KB |
Output is correct |
14 |
Correct |
2 ms |
512 KB |
Output is correct |
15 |
Correct |
2 ms |
592 KB |
Output is correct |
16 |
Correct |
1 ms |
336 KB |
Output is correct |
17 |
Correct |
1 ms |
336 KB |
Output is correct |
18 |
Correct |
1 ms |
336 KB |
Output is correct |
19 |
Correct |
1 ms |
504 KB |
Output is correct |
20 |
Correct |
1 ms |
336 KB |
Output is correct |
21 |
Correct |
1 ms |
336 KB |
Output is correct |
22 |
Correct |
1 ms |
460 KB |
Output is correct |
23 |
Correct |
1 ms |
336 KB |
Output is correct |
24 |
Correct |
1 ms |
336 KB |
Output is correct |
25 |
Correct |
1 ms |
504 KB |
Output is correct |
26 |
Correct |
1 ms |
336 KB |
Output is correct |
27 |
Correct |
1 ms |
508 KB |
Output is correct |
28 |
Correct |
1 ms |
336 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
2 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
1 ms |
336 KB |
Output is correct |
13 |
Correct |
1 ms |
336 KB |
Output is correct |
14 |
Correct |
2 ms |
512 KB |
Output is correct |
15 |
Correct |
2 ms |
592 KB |
Output is correct |
16 |
Correct |
1 ms |
336 KB |
Output is correct |
17 |
Correct |
1 ms |
336 KB |
Output is correct |
18 |
Correct |
1 ms |
336 KB |
Output is correct |
19 |
Correct |
1 ms |
504 KB |
Output is correct |
20 |
Correct |
1 ms |
336 KB |
Output is correct |
21 |
Correct |
1 ms |
336 KB |
Output is correct |
22 |
Correct |
1 ms |
460 KB |
Output is correct |
23 |
Correct |
1 ms |
336 KB |
Output is correct |
24 |
Correct |
1 ms |
336 KB |
Output is correct |
25 |
Correct |
1 ms |
504 KB |
Output is correct |
26 |
Correct |
1 ms |
336 KB |
Output is correct |
27 |
Correct |
1 ms |
508 KB |
Output is correct |
28 |
Correct |
1 ms |
336 KB |
Output is correct |
29 |
Correct |
22 ms |
764 KB |
Output is correct |
30 |
Correct |
21 ms |
848 KB |
Output is correct |
31 |
Correct |
17 ms |
772 KB |
Output is correct |
32 |
Correct |
9 ms |
720 KB |
Output is correct |
33 |
Correct |
4 ms |
592 KB |
Output is correct |
34 |
Correct |
17 ms |
800 KB |
Output is correct |
35 |
Correct |
25 ms |
796 KB |
Output is correct |
36 |
Correct |
21 ms |
664 KB |
Output is correct |
37 |
Correct |
53 ms |
848 KB |
Output is correct |
38 |
Correct |
83 ms |
848 KB |
Output is correct |
39 |
Correct |
5 ms |
908 KB |
Output is correct |
40 |
Correct |
4 ms |
672 KB |
Output is correct |
41 |
Correct |
3 ms |
748 KB |
Output is correct |
42 |
Correct |
4 ms |
848 KB |
Output is correct |
43 |
Correct |
6 ms |
592 KB |
Output is correct |
44 |
Correct |
8 ms |
676 KB |
Output is correct |
45 |
Correct |
10 ms |
768 KB |
Output is correct |
46 |
Correct |
24 ms |
852 KB |
Output is correct |
47 |
Correct |
9 ms |
592 KB |
Output is correct |
48 |
Correct |
13 ms |
740 KB |
Output is correct |
49 |
Correct |
18 ms |
1104 KB |
Output is correct |
50 |
Correct |
23 ms |
856 KB |
Output is correct |
51 |
Correct |
5 ms |
756 KB |
Output is correct |
52 |
Correct |
8 ms |
848 KB |
Output is correct |
53 |
Correct |
13 ms |
848 KB |
Output is correct |
54 |
Correct |
26 ms |
856 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Execution timed out |
2058 ms |
25616 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
2 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
1 ms |
336 KB |
Output is correct |
13 |
Correct |
1 ms |
336 KB |
Output is correct |
14 |
Correct |
2 ms |
512 KB |
Output is correct |
15 |
Correct |
2 ms |
592 KB |
Output is correct |
16 |
Correct |
1 ms |
336 KB |
Output is correct |
17 |
Correct |
1 ms |
336 KB |
Output is correct |
18 |
Correct |
1 ms |
336 KB |
Output is correct |
19 |
Correct |
1 ms |
504 KB |
Output is correct |
20 |
Correct |
1 ms |
336 KB |
Output is correct |
21 |
Correct |
1 ms |
336 KB |
Output is correct |
22 |
Correct |
1 ms |
460 KB |
Output is correct |
23 |
Correct |
1 ms |
336 KB |
Output is correct |
24 |
Correct |
1 ms |
336 KB |
Output is correct |
25 |
Correct |
1 ms |
504 KB |
Output is correct |
26 |
Correct |
1 ms |
336 KB |
Output is correct |
27 |
Correct |
1 ms |
508 KB |
Output is correct |
28 |
Correct |
1 ms |
336 KB |
Output is correct |
29 |
Execution timed out |
2058 ms |
25616 KB |
Time limit exceeded |
30 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
2 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
1 ms |
336 KB |
Output is correct |
13 |
Correct |
1 ms |
336 KB |
Output is correct |
14 |
Correct |
2 ms |
512 KB |
Output is correct |
15 |
Correct |
2 ms |
592 KB |
Output is correct |
16 |
Correct |
1 ms |
336 KB |
Output is correct |
17 |
Correct |
1 ms |
336 KB |
Output is correct |
18 |
Correct |
1 ms |
336 KB |
Output is correct |
19 |
Correct |
1 ms |
504 KB |
Output is correct |
20 |
Correct |
1 ms |
336 KB |
Output is correct |
21 |
Correct |
1 ms |
336 KB |
Output is correct |
22 |
Correct |
1 ms |
460 KB |
Output is correct |
23 |
Correct |
1 ms |
336 KB |
Output is correct |
24 |
Correct |
1 ms |
336 KB |
Output is correct |
25 |
Correct |
1 ms |
504 KB |
Output is correct |
26 |
Correct |
1 ms |
336 KB |
Output is correct |
27 |
Correct |
1 ms |
508 KB |
Output is correct |
28 |
Correct |
1 ms |
336 KB |
Output is correct |
29 |
Correct |
22 ms |
764 KB |
Output is correct |
30 |
Correct |
21 ms |
848 KB |
Output is correct |
31 |
Correct |
17 ms |
772 KB |
Output is correct |
32 |
Correct |
9 ms |
720 KB |
Output is correct |
33 |
Correct |
4 ms |
592 KB |
Output is correct |
34 |
Correct |
17 ms |
800 KB |
Output is correct |
35 |
Correct |
25 ms |
796 KB |
Output is correct |
36 |
Correct |
21 ms |
664 KB |
Output is correct |
37 |
Correct |
53 ms |
848 KB |
Output is correct |
38 |
Correct |
83 ms |
848 KB |
Output is correct |
39 |
Correct |
5 ms |
908 KB |
Output is correct |
40 |
Correct |
4 ms |
672 KB |
Output is correct |
41 |
Correct |
3 ms |
748 KB |
Output is correct |
42 |
Correct |
4 ms |
848 KB |
Output is correct |
43 |
Correct |
6 ms |
592 KB |
Output is correct |
44 |
Correct |
8 ms |
676 KB |
Output is correct |
45 |
Correct |
10 ms |
768 KB |
Output is correct |
46 |
Correct |
24 ms |
852 KB |
Output is correct |
47 |
Correct |
9 ms |
592 KB |
Output is correct |
48 |
Correct |
13 ms |
740 KB |
Output is correct |
49 |
Correct |
18 ms |
1104 KB |
Output is correct |
50 |
Correct |
23 ms |
856 KB |
Output is correct |
51 |
Correct |
5 ms |
756 KB |
Output is correct |
52 |
Correct |
8 ms |
848 KB |
Output is correct |
53 |
Correct |
13 ms |
848 KB |
Output is correct |
54 |
Correct |
26 ms |
856 KB |
Output is correct |
55 |
Execution timed out |
2033 ms |
27920 KB |
Time limit exceeded |
56 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
2 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
1 ms |
336 KB |
Output is correct |
13 |
Correct |
1 ms |
336 KB |
Output is correct |
14 |
Correct |
2 ms |
512 KB |
Output is correct |
15 |
Correct |
2 ms |
592 KB |
Output is correct |
16 |
Correct |
1 ms |
336 KB |
Output is correct |
17 |
Correct |
1 ms |
336 KB |
Output is correct |
18 |
Correct |
1 ms |
336 KB |
Output is correct |
19 |
Correct |
1 ms |
504 KB |
Output is correct |
20 |
Correct |
1 ms |
336 KB |
Output is correct |
21 |
Correct |
1 ms |
336 KB |
Output is correct |
22 |
Correct |
1 ms |
460 KB |
Output is correct |
23 |
Correct |
1 ms |
336 KB |
Output is correct |
24 |
Correct |
1 ms |
336 KB |
Output is correct |
25 |
Correct |
1 ms |
504 KB |
Output is correct |
26 |
Correct |
1 ms |
336 KB |
Output is correct |
27 |
Correct |
1 ms |
508 KB |
Output is correct |
28 |
Correct |
1 ms |
336 KB |
Output is correct |
29 |
Correct |
22 ms |
764 KB |
Output is correct |
30 |
Correct |
21 ms |
848 KB |
Output is correct |
31 |
Correct |
17 ms |
772 KB |
Output is correct |
32 |
Correct |
9 ms |
720 KB |
Output is correct |
33 |
Correct |
4 ms |
592 KB |
Output is correct |
34 |
Correct |
17 ms |
800 KB |
Output is correct |
35 |
Correct |
25 ms |
796 KB |
Output is correct |
36 |
Correct |
21 ms |
664 KB |
Output is correct |
37 |
Correct |
53 ms |
848 KB |
Output is correct |
38 |
Correct |
83 ms |
848 KB |
Output is correct |
39 |
Correct |
5 ms |
908 KB |
Output is correct |
40 |
Correct |
4 ms |
672 KB |
Output is correct |
41 |
Correct |
3 ms |
748 KB |
Output is correct |
42 |
Correct |
4 ms |
848 KB |
Output is correct |
43 |
Correct |
6 ms |
592 KB |
Output is correct |
44 |
Correct |
8 ms |
676 KB |
Output is correct |
45 |
Correct |
10 ms |
768 KB |
Output is correct |
46 |
Correct |
24 ms |
852 KB |
Output is correct |
47 |
Correct |
9 ms |
592 KB |
Output is correct |
48 |
Correct |
13 ms |
740 KB |
Output is correct |
49 |
Correct |
18 ms |
1104 KB |
Output is correct |
50 |
Correct |
23 ms |
856 KB |
Output is correct |
51 |
Correct |
5 ms |
756 KB |
Output is correct |
52 |
Correct |
8 ms |
848 KB |
Output is correct |
53 |
Correct |
13 ms |
848 KB |
Output is correct |
54 |
Correct |
26 ms |
856 KB |
Output is correct |
55 |
Execution timed out |
2058 ms |
25616 KB |
Time limit exceeded |
56 |
Halted |
0 ms |
0 KB |
- |