# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
871024 |
2023-11-09T17:48:12 Z |
NaimSS |
Joker (BOI20_joker) |
C++14 |
|
2000 ms |
27264 KB |
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define pb push_back
#define ld long double
#define ff first
#define ss second
#define endl '\n'
#define sz(v) ((int)v.size())
#define all(v) begin(v),end(v)
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
void dbg_out() { cerr << endl ;}
template<typename Head, typename... Tail> void dbg_out(Head H,Tail... T){
cerr<<' '<<H ;
dbg_out(T...);
}
#ifdef LOCAL
#define dbg(...) cerr<<"("<< #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__), cerr << endl;
#else
#define dbg(...) 42
#endif
struct event{
int a,b,psb,pa,corA,is_good;
event(int a,int b,int psb,int pa,int corA,int is_good):
a(a),b(b),psb(psb),pa(pa),corA(corA), is_good(is_good){}
};
struct DSU{
vector<event> st;
int is_good;
int n;
vi p,ps,ar;
DSU(int n):n(n){
p = ps = vi(n+1,1);
ar = vi(n+1,0);
rep(i,0,n+1)p[i] = i;
is_good = 1;
}
pii find(int x){
int val=0;
while(x!=p[x]){
val^=ar[x];
x = p[x];
}
return pii(x,val);
}
int f(int x){return find(x).ff;}
int cor(int x){return find(x).ss;}
bool join(int a,int b){
if(ps[f(a)] > ps[f(b)])swap(a,b);
int ca = cor(a),cb = cor(b);
a = f(a),b = f(b);
st.pb(event(a,b,ps[b],p[a],ar[a],is_good));
if(a == b){
if(ca == cb)is_good = 0;
return 0;
}
ps[b] += ps[a], p[a] = b;
ar[a] = (ca^cb^1);
return 1;
}
void undo(){
auto [a,b,psb,pa,corA,Isgood] = st.back();
p[a] = pa,ps[b] = psb,is_good = Isgood;
ar[a] = corA;
st.pop_back();
}
void clear(){
while(sz(st))undo();
}
int ok(){return is_good;}
};
const int N = 2 * (200100);
const int SQ = 400;
int a[N], b[N];
struct query{
int l,r,id;
query(int l,int r,int id):l(l),r(r),id(id){}
};
vector<query> Q[N];
int res[N];
int32_t main(){
ios_base::sync_with_stdio(0);cin.tie(0);
int n,m,q;
cin >> n >> m >> q;
rep(i,1,m+1){
cin >> a[i] >> b[i];
a[i + m] = a[i], b[i+m] = b[i];
}
rep(i,1,q+1){
int l,r;
cin >> l >> r;
if( l == 1 && r == m){
res[i] = 1;
continue;
}
Q[(r+1)/SQ].pb(query(r+1,l+m-1,i));
}
DSU d(n);
for(int bk=0;bk<N;bk++){
if(sz(Q[bk])==0)continue;
d.clear();
sort(all(Q[bk]),[&](query a,query b){
return a.r < b.r;
});
int ptr = (bk + 1) * SQ;
int lB = ptr - 1;
for(auto q : Q[bk]){
int l = q.l,r = q.r;
assert(l <= r);
while(ptr <= r){
d.join(a[ptr], b[ptr]);
ptr++;
}
int qtd=0;
for(int i=min(r,lB);i >= l; i--){
d.join(a[i], b[i]);
qtd++;
}
res[q.id] = d.ok();
while(qtd--)d.undo();
}
}
rep(i,1,q+1){
cout << (res[i] == 1 ? "NO" : "YES") << endl;
}
}
Compilation message
Joker.cpp: In member function 'void DSU::undo()':
Joker.cpp:69:8: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
69 | auto [a,b,psb,pa,corA,Isgood] = st.back();
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
12632 KB |
Output is correct |
2 |
Correct |
4 ms |
12632 KB |
Output is correct |
3 |
Correct |
3 ms |
12636 KB |
Output is correct |
4 |
Correct |
5 ms |
12708 KB |
Output is correct |
5 |
Correct |
3 ms |
12636 KB |
Output is correct |
6 |
Correct |
3 ms |
12636 KB |
Output is correct |
7 |
Correct |
3 ms |
12636 KB |
Output is correct |
8 |
Correct |
5 ms |
12816 KB |
Output is correct |
9 |
Correct |
4 ms |
12636 KB |
Output is correct |
10 |
Correct |
4 ms |
12636 KB |
Output is correct |
11 |
Correct |
5 ms |
12776 KB |
Output is correct |
12 |
Correct |
4 ms |
12636 KB |
Output is correct |
13 |
Correct |
4 ms |
12636 KB |
Output is correct |
14 |
Correct |
4 ms |
12636 KB |
Output is correct |
15 |
Correct |
3 ms |
12636 KB |
Output is correct |
16 |
Correct |
4 ms |
12636 KB |
Output is correct |
17 |
Correct |
4 ms |
12636 KB |
Output is correct |
18 |
Correct |
3 ms |
12804 KB |
Output is correct |
19 |
Correct |
4 ms |
12636 KB |
Output is correct |
20 |
Correct |
4 ms |
12636 KB |
Output is correct |
21 |
Correct |
4 ms |
12632 KB |
Output is correct |
22 |
Correct |
4 ms |
12632 KB |
Output is correct |
23 |
Correct |
4 ms |
12632 KB |
Output is correct |
24 |
Correct |
4 ms |
12636 KB |
Output is correct |
25 |
Correct |
4 ms |
12636 KB |
Output is correct |
26 |
Correct |
4 ms |
12636 KB |
Output is correct |
27 |
Correct |
4 ms |
12632 KB |
Output is correct |
28 |
Correct |
4 ms |
12636 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
12632 KB |
Output is correct |
2 |
Correct |
4 ms |
12632 KB |
Output is correct |
3 |
Correct |
3 ms |
12636 KB |
Output is correct |
4 |
Correct |
5 ms |
12708 KB |
Output is correct |
5 |
Correct |
3 ms |
12636 KB |
Output is correct |
6 |
Correct |
3 ms |
12636 KB |
Output is correct |
7 |
Correct |
3 ms |
12636 KB |
Output is correct |
8 |
Correct |
5 ms |
12816 KB |
Output is correct |
9 |
Correct |
4 ms |
12636 KB |
Output is correct |
10 |
Correct |
4 ms |
12636 KB |
Output is correct |
11 |
Correct |
5 ms |
12776 KB |
Output is correct |
12 |
Correct |
4 ms |
12636 KB |
Output is correct |
13 |
Correct |
4 ms |
12636 KB |
Output is correct |
14 |
Correct |
4 ms |
12636 KB |
Output is correct |
15 |
Correct |
3 ms |
12636 KB |
Output is correct |
16 |
Correct |
4 ms |
12636 KB |
Output is correct |
17 |
Correct |
4 ms |
12636 KB |
Output is correct |
18 |
Correct |
3 ms |
12804 KB |
Output is correct |
19 |
Correct |
4 ms |
12636 KB |
Output is correct |
20 |
Correct |
4 ms |
12636 KB |
Output is correct |
21 |
Correct |
4 ms |
12632 KB |
Output is correct |
22 |
Correct |
4 ms |
12632 KB |
Output is correct |
23 |
Correct |
4 ms |
12632 KB |
Output is correct |
24 |
Correct |
4 ms |
12636 KB |
Output is correct |
25 |
Correct |
4 ms |
12636 KB |
Output is correct |
26 |
Correct |
4 ms |
12636 KB |
Output is correct |
27 |
Correct |
4 ms |
12632 KB |
Output is correct |
28 |
Correct |
4 ms |
12636 KB |
Output is correct |
29 |
Correct |
11 ms |
12932 KB |
Output is correct |
30 |
Correct |
11 ms |
12892 KB |
Output is correct |
31 |
Correct |
13 ms |
12888 KB |
Output is correct |
32 |
Correct |
14 ms |
12892 KB |
Output is correct |
33 |
Correct |
15 ms |
12988 KB |
Output is correct |
34 |
Correct |
7 ms |
12892 KB |
Output is correct |
35 |
Correct |
13 ms |
12892 KB |
Output is correct |
36 |
Correct |
6 ms |
12888 KB |
Output is correct |
37 |
Correct |
13 ms |
12792 KB |
Output is correct |
38 |
Correct |
9 ms |
12892 KB |
Output is correct |
39 |
Correct |
9 ms |
12892 KB |
Output is correct |
40 |
Correct |
7 ms |
12884 KB |
Output is correct |
41 |
Correct |
6 ms |
12892 KB |
Output is correct |
42 |
Correct |
7 ms |
12980 KB |
Output is correct |
43 |
Correct |
11 ms |
12992 KB |
Output is correct |
44 |
Correct |
11 ms |
12892 KB |
Output is correct |
45 |
Correct |
12 ms |
12888 KB |
Output is correct |
46 |
Correct |
11 ms |
12892 KB |
Output is correct |
47 |
Correct |
12 ms |
12984 KB |
Output is correct |
48 |
Correct |
12 ms |
12892 KB |
Output is correct |
49 |
Correct |
11 ms |
12992 KB |
Output is correct |
50 |
Correct |
12 ms |
12892 KB |
Output is correct |
51 |
Correct |
14 ms |
12892 KB |
Output is correct |
52 |
Correct |
15 ms |
12892 KB |
Output is correct |
53 |
Correct |
13 ms |
12892 KB |
Output is correct |
54 |
Correct |
13 ms |
12892 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
12632 KB |
Output is correct |
2 |
Correct |
4 ms |
12632 KB |
Output is correct |
3 |
Correct |
1563 ms |
24816 KB |
Output is correct |
4 |
Execution timed out |
2044 ms |
27264 KB |
Time limit exceeded |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
12632 KB |
Output is correct |
2 |
Correct |
4 ms |
12632 KB |
Output is correct |
3 |
Correct |
3 ms |
12636 KB |
Output is correct |
4 |
Correct |
5 ms |
12708 KB |
Output is correct |
5 |
Correct |
3 ms |
12636 KB |
Output is correct |
6 |
Correct |
3 ms |
12636 KB |
Output is correct |
7 |
Correct |
3 ms |
12636 KB |
Output is correct |
8 |
Correct |
5 ms |
12816 KB |
Output is correct |
9 |
Correct |
4 ms |
12636 KB |
Output is correct |
10 |
Correct |
4 ms |
12636 KB |
Output is correct |
11 |
Correct |
5 ms |
12776 KB |
Output is correct |
12 |
Correct |
4 ms |
12636 KB |
Output is correct |
13 |
Correct |
4 ms |
12636 KB |
Output is correct |
14 |
Correct |
4 ms |
12636 KB |
Output is correct |
15 |
Correct |
3 ms |
12636 KB |
Output is correct |
16 |
Correct |
4 ms |
12636 KB |
Output is correct |
17 |
Correct |
4 ms |
12636 KB |
Output is correct |
18 |
Correct |
3 ms |
12804 KB |
Output is correct |
19 |
Correct |
4 ms |
12636 KB |
Output is correct |
20 |
Correct |
4 ms |
12636 KB |
Output is correct |
21 |
Correct |
4 ms |
12632 KB |
Output is correct |
22 |
Correct |
4 ms |
12632 KB |
Output is correct |
23 |
Correct |
4 ms |
12632 KB |
Output is correct |
24 |
Correct |
4 ms |
12636 KB |
Output is correct |
25 |
Correct |
4 ms |
12636 KB |
Output is correct |
26 |
Correct |
4 ms |
12636 KB |
Output is correct |
27 |
Correct |
4 ms |
12632 KB |
Output is correct |
28 |
Correct |
4 ms |
12636 KB |
Output is correct |
29 |
Correct |
1563 ms |
24816 KB |
Output is correct |
30 |
Execution timed out |
2044 ms |
27264 KB |
Time limit exceeded |
31 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
12632 KB |
Output is correct |
2 |
Correct |
4 ms |
12632 KB |
Output is correct |
3 |
Correct |
3 ms |
12636 KB |
Output is correct |
4 |
Correct |
5 ms |
12708 KB |
Output is correct |
5 |
Correct |
3 ms |
12636 KB |
Output is correct |
6 |
Correct |
3 ms |
12636 KB |
Output is correct |
7 |
Correct |
3 ms |
12636 KB |
Output is correct |
8 |
Correct |
5 ms |
12816 KB |
Output is correct |
9 |
Correct |
4 ms |
12636 KB |
Output is correct |
10 |
Correct |
4 ms |
12636 KB |
Output is correct |
11 |
Correct |
5 ms |
12776 KB |
Output is correct |
12 |
Correct |
4 ms |
12636 KB |
Output is correct |
13 |
Correct |
4 ms |
12636 KB |
Output is correct |
14 |
Correct |
4 ms |
12636 KB |
Output is correct |
15 |
Correct |
3 ms |
12636 KB |
Output is correct |
16 |
Correct |
4 ms |
12636 KB |
Output is correct |
17 |
Correct |
4 ms |
12636 KB |
Output is correct |
18 |
Correct |
3 ms |
12804 KB |
Output is correct |
19 |
Correct |
4 ms |
12636 KB |
Output is correct |
20 |
Correct |
4 ms |
12636 KB |
Output is correct |
21 |
Correct |
4 ms |
12632 KB |
Output is correct |
22 |
Correct |
4 ms |
12632 KB |
Output is correct |
23 |
Correct |
4 ms |
12632 KB |
Output is correct |
24 |
Correct |
4 ms |
12636 KB |
Output is correct |
25 |
Correct |
4 ms |
12636 KB |
Output is correct |
26 |
Correct |
4 ms |
12636 KB |
Output is correct |
27 |
Correct |
4 ms |
12632 KB |
Output is correct |
28 |
Correct |
4 ms |
12636 KB |
Output is correct |
29 |
Correct |
11 ms |
12932 KB |
Output is correct |
30 |
Correct |
11 ms |
12892 KB |
Output is correct |
31 |
Correct |
13 ms |
12888 KB |
Output is correct |
32 |
Correct |
14 ms |
12892 KB |
Output is correct |
33 |
Correct |
15 ms |
12988 KB |
Output is correct |
34 |
Correct |
7 ms |
12892 KB |
Output is correct |
35 |
Correct |
13 ms |
12892 KB |
Output is correct |
36 |
Correct |
6 ms |
12888 KB |
Output is correct |
37 |
Correct |
13 ms |
12792 KB |
Output is correct |
38 |
Correct |
9 ms |
12892 KB |
Output is correct |
39 |
Correct |
9 ms |
12892 KB |
Output is correct |
40 |
Correct |
7 ms |
12884 KB |
Output is correct |
41 |
Correct |
6 ms |
12892 KB |
Output is correct |
42 |
Correct |
7 ms |
12980 KB |
Output is correct |
43 |
Correct |
11 ms |
12992 KB |
Output is correct |
44 |
Correct |
11 ms |
12892 KB |
Output is correct |
45 |
Correct |
12 ms |
12888 KB |
Output is correct |
46 |
Correct |
11 ms |
12892 KB |
Output is correct |
47 |
Correct |
12 ms |
12984 KB |
Output is correct |
48 |
Correct |
12 ms |
12892 KB |
Output is correct |
49 |
Correct |
11 ms |
12992 KB |
Output is correct |
50 |
Correct |
12 ms |
12892 KB |
Output is correct |
51 |
Correct |
14 ms |
12892 KB |
Output is correct |
52 |
Correct |
15 ms |
12892 KB |
Output is correct |
53 |
Correct |
13 ms |
12892 KB |
Output is correct |
54 |
Correct |
13 ms |
12892 KB |
Output is correct |
55 |
Correct |
1130 ms |
24088 KB |
Output is correct |
56 |
Execution timed out |
2075 ms |
25636 KB |
Time limit exceeded |
57 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
12632 KB |
Output is correct |
2 |
Correct |
4 ms |
12632 KB |
Output is correct |
3 |
Correct |
3 ms |
12636 KB |
Output is correct |
4 |
Correct |
5 ms |
12708 KB |
Output is correct |
5 |
Correct |
3 ms |
12636 KB |
Output is correct |
6 |
Correct |
3 ms |
12636 KB |
Output is correct |
7 |
Correct |
3 ms |
12636 KB |
Output is correct |
8 |
Correct |
5 ms |
12816 KB |
Output is correct |
9 |
Correct |
4 ms |
12636 KB |
Output is correct |
10 |
Correct |
4 ms |
12636 KB |
Output is correct |
11 |
Correct |
5 ms |
12776 KB |
Output is correct |
12 |
Correct |
4 ms |
12636 KB |
Output is correct |
13 |
Correct |
4 ms |
12636 KB |
Output is correct |
14 |
Correct |
4 ms |
12636 KB |
Output is correct |
15 |
Correct |
3 ms |
12636 KB |
Output is correct |
16 |
Correct |
4 ms |
12636 KB |
Output is correct |
17 |
Correct |
4 ms |
12636 KB |
Output is correct |
18 |
Correct |
3 ms |
12804 KB |
Output is correct |
19 |
Correct |
4 ms |
12636 KB |
Output is correct |
20 |
Correct |
4 ms |
12636 KB |
Output is correct |
21 |
Correct |
4 ms |
12632 KB |
Output is correct |
22 |
Correct |
4 ms |
12632 KB |
Output is correct |
23 |
Correct |
4 ms |
12632 KB |
Output is correct |
24 |
Correct |
4 ms |
12636 KB |
Output is correct |
25 |
Correct |
4 ms |
12636 KB |
Output is correct |
26 |
Correct |
4 ms |
12636 KB |
Output is correct |
27 |
Correct |
4 ms |
12632 KB |
Output is correct |
28 |
Correct |
4 ms |
12636 KB |
Output is correct |
29 |
Correct |
11 ms |
12932 KB |
Output is correct |
30 |
Correct |
11 ms |
12892 KB |
Output is correct |
31 |
Correct |
13 ms |
12888 KB |
Output is correct |
32 |
Correct |
14 ms |
12892 KB |
Output is correct |
33 |
Correct |
15 ms |
12988 KB |
Output is correct |
34 |
Correct |
7 ms |
12892 KB |
Output is correct |
35 |
Correct |
13 ms |
12892 KB |
Output is correct |
36 |
Correct |
6 ms |
12888 KB |
Output is correct |
37 |
Correct |
13 ms |
12792 KB |
Output is correct |
38 |
Correct |
9 ms |
12892 KB |
Output is correct |
39 |
Correct |
9 ms |
12892 KB |
Output is correct |
40 |
Correct |
7 ms |
12884 KB |
Output is correct |
41 |
Correct |
6 ms |
12892 KB |
Output is correct |
42 |
Correct |
7 ms |
12980 KB |
Output is correct |
43 |
Correct |
11 ms |
12992 KB |
Output is correct |
44 |
Correct |
11 ms |
12892 KB |
Output is correct |
45 |
Correct |
12 ms |
12888 KB |
Output is correct |
46 |
Correct |
11 ms |
12892 KB |
Output is correct |
47 |
Correct |
12 ms |
12984 KB |
Output is correct |
48 |
Correct |
12 ms |
12892 KB |
Output is correct |
49 |
Correct |
11 ms |
12992 KB |
Output is correct |
50 |
Correct |
12 ms |
12892 KB |
Output is correct |
51 |
Correct |
14 ms |
12892 KB |
Output is correct |
52 |
Correct |
15 ms |
12892 KB |
Output is correct |
53 |
Correct |
13 ms |
12892 KB |
Output is correct |
54 |
Correct |
13 ms |
12892 KB |
Output is correct |
55 |
Correct |
1563 ms |
24816 KB |
Output is correct |
56 |
Execution timed out |
2044 ms |
27264 KB |
Time limit exceeded |
57 |
Halted |
0 ms |
0 KB |
- |