Submission #871035

# Submission time Handle Problem Language Result Execution time Memory
871035 2023-11-09T18:12:00 Z NaimSS Joker (BOI20_joker) C++14
49 / 100
2000 ms 31184 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, ps[i] = 1, ar[i] = 0;
		is_good = 1;
	}
	int f(int x){
		while(x!=p[x])x = p[x];
		return x;
	}
	int cor(int x){
		int c=0;
		while(x!=p[x])c^=ar[x],x=p[x];
		return c;
	}
	pii F(int x){
		int c=0;
		while(x!=p[x])c^=ar[x],x=p[x];
		return pii(x,c);
	}
	bool join(int A,int B){
		auto [a,ca] = F(A);
		auto [b,cb] = F(B);
		if(ps[a] > ps[b])swap(a,b),swap(ca,cb);
		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);
		// dbg(a,b,ps[a], ps[b], p[a], p[b]);
		return 1;
	}
	void undo(int qtd=1){
		while(qtd--){
			auto x = st.back();
			p[x.a] = x.pa,ps[x.b] = x.psb,is_good = x.is_good;
			ar[x.a] = x.corA;
			st.pop_back();
		}
	}
	void clear(){
		undo(sz(st));
	}
	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;
	for(int i=m-1;i>=0;i--){
		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;
		--l,--r;
		l = m-1-l,r = m-1-r;swap(l,r);
		if( l == 0 && r == m - 1){
			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/SQ) + 1;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 fim = (bk + 1) * SQ - 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=l; i <= min(r, fim); i++){
				d.join(a[i], b[i]);
				qtd++;
			}
			res[q.id] = d.ok();
			assert(qtd <= SQ);
			d.undo(qtd);
		}
	}
	rep(i,1,q+1){
		cout << (res[i] == 1 ? "NO" : "YES") << endl; 
	}
	
}

Compilation message

Joker.cpp: In member function 'bool DSU::join(int, int)':
Joker.cpp:60:8: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   60 |   auto [a,ca] = F(A);
      |        ^
Joker.cpp:61:8: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   61 |   auto [b,cb] = F(B);
      |        ^
# Verdict Execution time Memory Grader output
1 Correct 2 ms 12748 KB Output is correct
2 Correct 3 ms 12636 KB Output is correct
3 Correct 2 ms 12636 KB Output is correct
4 Correct 2 ms 12636 KB Output is correct
5 Correct 2 ms 12740 KB Output is correct
6 Correct 2 ms 12636 KB Output is correct
7 Correct 3 ms 12636 KB Output is correct
8 Correct 3 ms 12736 KB Output is correct
9 Correct 4 ms 12636 KB Output is correct
10 Correct 3 ms 12636 KB Output is correct
11 Correct 3 ms 12636 KB Output is correct
12 Correct 3 ms 12636 KB Output is correct
13 Correct 4 ms 12636 KB Output is correct
14 Correct 3 ms 12636 KB Output is correct
15 Correct 3 ms 12636 KB Output is correct
16 Correct 3 ms 12632 KB Output is correct
17 Correct 3 ms 12636 KB Output is correct
18 Correct 3 ms 12636 KB Output is correct
19 Correct 3 ms 12636 KB Output is correct
20 Correct 5 ms 12740 KB Output is correct
21 Correct 4 ms 12636 KB Output is correct
22 Correct 4 ms 12636 KB Output is correct
23 Correct 3 ms 12632 KB Output is correct
24 Correct 3 ms 12636 KB Output is correct
25 Correct 3 ms 12636 KB Output is correct
26 Correct 3 ms 12680 KB Output is correct
27 Correct 3 ms 12636 KB Output is correct
28 Correct 3 ms 12636 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 12748 KB Output is correct
2 Correct 3 ms 12636 KB Output is correct
3 Correct 2 ms 12636 KB Output is correct
4 Correct 2 ms 12636 KB Output is correct
5 Correct 2 ms 12740 KB Output is correct
6 Correct 2 ms 12636 KB Output is correct
7 Correct 3 ms 12636 KB Output is correct
8 Correct 3 ms 12736 KB Output is correct
9 Correct 4 ms 12636 KB Output is correct
10 Correct 3 ms 12636 KB Output is correct
11 Correct 3 ms 12636 KB Output is correct
12 Correct 3 ms 12636 KB Output is correct
13 Correct 4 ms 12636 KB Output is correct
14 Correct 3 ms 12636 KB Output is correct
15 Correct 3 ms 12636 KB Output is correct
16 Correct 3 ms 12632 KB Output is correct
17 Correct 3 ms 12636 KB Output is correct
18 Correct 3 ms 12636 KB Output is correct
19 Correct 3 ms 12636 KB Output is correct
20 Correct 5 ms 12740 KB Output is correct
21 Correct 4 ms 12636 KB Output is correct
22 Correct 4 ms 12636 KB Output is correct
23 Correct 3 ms 12632 KB Output is correct
24 Correct 3 ms 12636 KB Output is correct
25 Correct 3 ms 12636 KB Output is correct
26 Correct 3 ms 12680 KB Output is correct
27 Correct 3 ms 12636 KB Output is correct
28 Correct 3 ms 12636 KB Output is correct
29 Correct 9 ms 12888 KB Output is correct
30 Correct 9 ms 12948 KB Output is correct
31 Correct 10 ms 12892 KB Output is correct
32 Correct 9 ms 12892 KB Output is correct
33 Correct 9 ms 12892 KB Output is correct
34 Correct 9 ms 12892 KB Output is correct
35 Correct 10 ms 12892 KB Output is correct
36 Correct 9 ms 12892 KB Output is correct
37 Correct 9 ms 12892 KB Output is correct
38 Correct 9 ms 13148 KB Output is correct
39 Correct 11 ms 13132 KB Output is correct
40 Correct 9 ms 12960 KB Output is correct
41 Correct 9 ms 12892 KB Output is correct
42 Correct 9 ms 12956 KB Output is correct
43 Correct 9 ms 12888 KB Output is correct
44 Correct 9 ms 12952 KB Output is correct
45 Correct 9 ms 12892 KB Output is correct
46 Correct 9 ms 12892 KB Output is correct
47 Correct 9 ms 12892 KB Output is correct
48 Correct 9 ms 12892 KB Output is correct
49 Correct 9 ms 12892 KB Output is correct
50 Correct 9 ms 12892 KB Output is correct
51 Correct 10 ms 12952 KB Output is correct
52 Correct 10 ms 12892 KB Output is correct
53 Correct 9 ms 12956 KB Output is correct
54 Correct 11 ms 13148 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 12748 KB Output is correct
2 Correct 3 ms 12636 KB Output is correct
3 Correct 72 ms 24544 KB Output is correct
4 Correct 1222 ms 27448 KB Output is correct
5 Correct 1285 ms 31184 KB Output is correct
6 Correct 78 ms 30016 KB Output is correct
7 Correct 88 ms 29304 KB Output is correct
8 Correct 1324 ms 28648 KB Output is correct
9 Correct 1367 ms 28976 KB Output is correct
10 Correct 1451 ms 30772 KB Output is correct
11 Correct 1258 ms 29488 KB Output is correct
12 Correct 1279 ms 29908 KB Output is correct
13 Correct 1222 ms 28684 KB Output is correct
14 Correct 1293 ms 28980 KB Output is correct
15 Correct 1427 ms 29872 KB Output is correct
16 Correct 1429 ms 31012 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 12748 KB Output is correct
2 Correct 3 ms 12636 KB Output is correct
3 Correct 2 ms 12636 KB Output is correct
4 Correct 2 ms 12636 KB Output is correct
5 Correct 2 ms 12740 KB Output is correct
6 Correct 2 ms 12636 KB Output is correct
7 Correct 3 ms 12636 KB Output is correct
8 Correct 3 ms 12736 KB Output is correct
9 Correct 4 ms 12636 KB Output is correct
10 Correct 3 ms 12636 KB Output is correct
11 Correct 3 ms 12636 KB Output is correct
12 Correct 3 ms 12636 KB Output is correct
13 Correct 4 ms 12636 KB Output is correct
14 Correct 3 ms 12636 KB Output is correct
15 Correct 3 ms 12636 KB Output is correct
16 Correct 3 ms 12632 KB Output is correct
17 Correct 3 ms 12636 KB Output is correct
18 Correct 3 ms 12636 KB Output is correct
19 Correct 3 ms 12636 KB Output is correct
20 Correct 5 ms 12740 KB Output is correct
21 Correct 4 ms 12636 KB Output is correct
22 Correct 4 ms 12636 KB Output is correct
23 Correct 3 ms 12632 KB Output is correct
24 Correct 3 ms 12636 KB Output is correct
25 Correct 3 ms 12636 KB Output is correct
26 Correct 3 ms 12680 KB Output is correct
27 Correct 3 ms 12636 KB Output is correct
28 Correct 3 ms 12636 KB Output is correct
29 Correct 72 ms 24544 KB Output is correct
30 Correct 1222 ms 27448 KB Output is correct
31 Correct 1285 ms 31184 KB Output is correct
32 Correct 78 ms 30016 KB Output is correct
33 Correct 88 ms 29304 KB Output is correct
34 Correct 1324 ms 28648 KB Output is correct
35 Correct 1367 ms 28976 KB Output is correct
36 Correct 1451 ms 30772 KB Output is correct
37 Correct 1258 ms 29488 KB Output is correct
38 Correct 1279 ms 29908 KB Output is correct
39 Correct 1222 ms 28684 KB Output is correct
40 Correct 1293 ms 28980 KB Output is correct
41 Correct 1427 ms 29872 KB Output is correct
42 Correct 1429 ms 31012 KB Output is correct
43 Correct 353 ms 28732 KB Output is correct
44 Correct 372 ms 30524 KB Output is correct
45 Correct 371 ms 30756 KB Output is correct
46 Correct 363 ms 30424 KB Output is correct
47 Correct 395 ms 30336 KB Output is correct
48 Correct 422 ms 30020 KB Output is correct
49 Correct 434 ms 30452 KB Output is correct
50 Correct 359 ms 29364 KB Output is correct
51 Correct 386 ms 30440 KB Output is correct
52 Correct 371 ms 30784 KB Output is correct
53 Correct 411 ms 29252 KB Output is correct
54 Correct 462 ms 30024 KB Output is correct
55 Correct 424 ms 30352 KB Output is correct
56 Correct 430 ms 30456 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 12748 KB Output is correct
2 Correct 3 ms 12636 KB Output is correct
3 Correct 2 ms 12636 KB Output is correct
4 Correct 2 ms 12636 KB Output is correct
5 Correct 2 ms 12740 KB Output is correct
6 Correct 2 ms 12636 KB Output is correct
7 Correct 3 ms 12636 KB Output is correct
8 Correct 3 ms 12736 KB Output is correct
9 Correct 4 ms 12636 KB Output is correct
10 Correct 3 ms 12636 KB Output is correct
11 Correct 3 ms 12636 KB Output is correct
12 Correct 3 ms 12636 KB Output is correct
13 Correct 4 ms 12636 KB Output is correct
14 Correct 3 ms 12636 KB Output is correct
15 Correct 3 ms 12636 KB Output is correct
16 Correct 3 ms 12632 KB Output is correct
17 Correct 3 ms 12636 KB Output is correct
18 Correct 3 ms 12636 KB Output is correct
19 Correct 3 ms 12636 KB Output is correct
20 Correct 5 ms 12740 KB Output is correct
21 Correct 4 ms 12636 KB Output is correct
22 Correct 4 ms 12636 KB Output is correct
23 Correct 3 ms 12632 KB Output is correct
24 Correct 3 ms 12636 KB Output is correct
25 Correct 3 ms 12636 KB Output is correct
26 Correct 3 ms 12680 KB Output is correct
27 Correct 3 ms 12636 KB Output is correct
28 Correct 3 ms 12636 KB Output is correct
29 Correct 9 ms 12888 KB Output is correct
30 Correct 9 ms 12948 KB Output is correct
31 Correct 10 ms 12892 KB Output is correct
32 Correct 9 ms 12892 KB Output is correct
33 Correct 9 ms 12892 KB Output is correct
34 Correct 9 ms 12892 KB Output is correct
35 Correct 10 ms 12892 KB Output is correct
36 Correct 9 ms 12892 KB Output is correct
37 Correct 9 ms 12892 KB Output is correct
38 Correct 9 ms 13148 KB Output is correct
39 Correct 11 ms 13132 KB Output is correct
40 Correct 9 ms 12960 KB Output is correct
41 Correct 9 ms 12892 KB Output is correct
42 Correct 9 ms 12956 KB Output is correct
43 Correct 9 ms 12888 KB Output is correct
44 Correct 9 ms 12952 KB Output is correct
45 Correct 9 ms 12892 KB Output is correct
46 Correct 9 ms 12892 KB Output is correct
47 Correct 9 ms 12892 KB Output is correct
48 Correct 9 ms 12892 KB Output is correct
49 Correct 9 ms 12892 KB Output is correct
50 Correct 9 ms 12892 KB Output is correct
51 Correct 10 ms 12952 KB Output is correct
52 Correct 10 ms 12892 KB Output is correct
53 Correct 9 ms 12956 KB Output is correct
54 Correct 11 ms 13148 KB Output is correct
55 Correct 1575 ms 23748 KB Output is correct
56 Execution timed out 2025 ms 24768 KB Time limit exceeded
57 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 12748 KB Output is correct
2 Correct 3 ms 12636 KB Output is correct
3 Correct 2 ms 12636 KB Output is correct
4 Correct 2 ms 12636 KB Output is correct
5 Correct 2 ms 12740 KB Output is correct
6 Correct 2 ms 12636 KB Output is correct
7 Correct 3 ms 12636 KB Output is correct
8 Correct 3 ms 12736 KB Output is correct
9 Correct 4 ms 12636 KB Output is correct
10 Correct 3 ms 12636 KB Output is correct
11 Correct 3 ms 12636 KB Output is correct
12 Correct 3 ms 12636 KB Output is correct
13 Correct 4 ms 12636 KB Output is correct
14 Correct 3 ms 12636 KB Output is correct
15 Correct 3 ms 12636 KB Output is correct
16 Correct 3 ms 12632 KB Output is correct
17 Correct 3 ms 12636 KB Output is correct
18 Correct 3 ms 12636 KB Output is correct
19 Correct 3 ms 12636 KB Output is correct
20 Correct 5 ms 12740 KB Output is correct
21 Correct 4 ms 12636 KB Output is correct
22 Correct 4 ms 12636 KB Output is correct
23 Correct 3 ms 12632 KB Output is correct
24 Correct 3 ms 12636 KB Output is correct
25 Correct 3 ms 12636 KB Output is correct
26 Correct 3 ms 12680 KB Output is correct
27 Correct 3 ms 12636 KB Output is correct
28 Correct 3 ms 12636 KB Output is correct
29 Correct 9 ms 12888 KB Output is correct
30 Correct 9 ms 12948 KB Output is correct
31 Correct 10 ms 12892 KB Output is correct
32 Correct 9 ms 12892 KB Output is correct
33 Correct 9 ms 12892 KB Output is correct
34 Correct 9 ms 12892 KB Output is correct
35 Correct 10 ms 12892 KB Output is correct
36 Correct 9 ms 12892 KB Output is correct
37 Correct 9 ms 12892 KB Output is correct
38 Correct 9 ms 13148 KB Output is correct
39 Correct 11 ms 13132 KB Output is correct
40 Correct 9 ms 12960 KB Output is correct
41 Correct 9 ms 12892 KB Output is correct
42 Correct 9 ms 12956 KB Output is correct
43 Correct 9 ms 12888 KB Output is correct
44 Correct 9 ms 12952 KB Output is correct
45 Correct 9 ms 12892 KB Output is correct
46 Correct 9 ms 12892 KB Output is correct
47 Correct 9 ms 12892 KB Output is correct
48 Correct 9 ms 12892 KB Output is correct
49 Correct 9 ms 12892 KB Output is correct
50 Correct 9 ms 12892 KB Output is correct
51 Correct 10 ms 12952 KB Output is correct
52 Correct 10 ms 12892 KB Output is correct
53 Correct 9 ms 12956 KB Output is correct
54 Correct 11 ms 13148 KB Output is correct
55 Correct 72 ms 24544 KB Output is correct
56 Correct 1222 ms 27448 KB Output is correct
57 Correct 1285 ms 31184 KB Output is correct
58 Correct 78 ms 30016 KB Output is correct
59 Correct 88 ms 29304 KB Output is correct
60 Correct 1324 ms 28648 KB Output is correct
61 Correct 1367 ms 28976 KB Output is correct
62 Correct 1451 ms 30772 KB Output is correct
63 Correct 1258 ms 29488 KB Output is correct
64 Correct 1279 ms 29908 KB Output is correct
65 Correct 1222 ms 28684 KB Output is correct
66 Correct 1293 ms 28980 KB Output is correct
67 Correct 1427 ms 29872 KB Output is correct
68 Correct 1429 ms 31012 KB Output is correct
69 Correct 353 ms 28732 KB Output is correct
70 Correct 372 ms 30524 KB Output is correct
71 Correct 371 ms 30756 KB Output is correct
72 Correct 363 ms 30424 KB Output is correct
73 Correct 395 ms 30336 KB Output is correct
74 Correct 422 ms 30020 KB Output is correct
75 Correct 434 ms 30452 KB Output is correct
76 Correct 359 ms 29364 KB Output is correct
77 Correct 386 ms 30440 KB Output is correct
78 Correct 371 ms 30784 KB Output is correct
79 Correct 411 ms 29252 KB Output is correct
80 Correct 462 ms 30024 KB Output is correct
81 Correct 424 ms 30352 KB Output is correct
82 Correct 430 ms 30456 KB Output is correct
83 Correct 1575 ms 23748 KB Output is correct
84 Execution timed out 2025 ms 24768 KB Time limit exceeded
85 Halted 0 ms 0 KB -