답안 #871025

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
871025 2023-11-09T17:52:23 Z NaimSS Joker (BOI20_joker) C++14
14 / 100
2000 ms 24516 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 = 250;
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,0,m){
		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;
		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 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();
			assert(qtd <= SQ);
			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();
      |        ^
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 12792 KB Output is correct
2 Correct 2 ms 12776 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 12736 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 12648 KB Output is correct
9 Correct 3 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 3 ms 12636 KB Output is correct
14 Correct 3 ms 12632 KB Output is correct
15 Correct 3 ms 12732 KB Output is correct
16 Correct 3 ms 12636 KB Output is correct
17 Correct 3 ms 12636 KB Output is correct
18 Correct 3 ms 12636 KB Output is correct
19 Correct 2 ms 12636 KB Output is correct
20 Correct 3 ms 12636 KB Output is correct
21 Correct 3 ms 12636 KB Output is correct
22 Correct 3 ms 12636 KB Output is correct
23 Correct 2 ms 12636 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 12636 KB Output is correct
27 Correct 3 ms 12636 KB Output is correct
28 Correct 3 ms 12636 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 12792 KB Output is correct
2 Correct 2 ms 12776 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 12736 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 12648 KB Output is correct
9 Correct 3 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 3 ms 12636 KB Output is correct
14 Correct 3 ms 12632 KB Output is correct
15 Correct 3 ms 12732 KB Output is correct
16 Correct 3 ms 12636 KB Output is correct
17 Correct 3 ms 12636 KB Output is correct
18 Correct 3 ms 12636 KB Output is correct
19 Correct 2 ms 12636 KB Output is correct
20 Correct 3 ms 12636 KB Output is correct
21 Correct 3 ms 12636 KB Output is correct
22 Correct 3 ms 12636 KB Output is correct
23 Correct 2 ms 12636 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 12636 KB Output is correct
27 Correct 3 ms 12636 KB Output is correct
28 Correct 3 ms 12636 KB Output is correct
29 Correct 8 ms 12892 KB Output is correct
30 Correct 8 ms 12892 KB Output is correct
31 Correct 10 ms 12956 KB Output is correct
32 Correct 11 ms 12952 KB Output is correct
33 Correct 10 ms 12892 KB Output is correct
34 Correct 5 ms 12964 KB Output is correct
35 Correct 9 ms 12892 KB Output is correct
36 Correct 4 ms 12892 KB Output is correct
37 Correct 8 ms 12892 KB Output is correct
38 Correct 6 ms 12892 KB Output is correct
39 Correct 6 ms 12892 KB Output is correct
40 Correct 5 ms 12736 KB Output is correct
41 Correct 5 ms 12892 KB Output is correct
42 Correct 5 ms 12892 KB Output is correct
43 Correct 8 ms 12960 KB Output is correct
44 Correct 9 ms 12892 KB Output is correct
45 Correct 7 ms 12892 KB Output is correct
46 Correct 8 ms 12964 KB Output is correct
47 Correct 8 ms 12892 KB Output is correct
48 Correct 8 ms 12956 KB Output is correct
49 Correct 8 ms 12888 KB Output is correct
50 Correct 8 ms 12908 KB Output is correct
51 Correct 9 ms 12892 KB Output is correct
52 Correct 9 ms 12892 KB Output is correct
53 Correct 9 ms 12892 KB Output is correct
54 Correct 9 ms 12892 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 12792 KB Output is correct
2 Correct 2 ms 12776 KB Output is correct
3 Execution timed out 2035 ms 24516 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 12792 KB Output is correct
2 Correct 2 ms 12776 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 12736 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 12648 KB Output is correct
9 Correct 3 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 3 ms 12636 KB Output is correct
14 Correct 3 ms 12632 KB Output is correct
15 Correct 3 ms 12732 KB Output is correct
16 Correct 3 ms 12636 KB Output is correct
17 Correct 3 ms 12636 KB Output is correct
18 Correct 3 ms 12636 KB Output is correct
19 Correct 2 ms 12636 KB Output is correct
20 Correct 3 ms 12636 KB Output is correct
21 Correct 3 ms 12636 KB Output is correct
22 Correct 3 ms 12636 KB Output is correct
23 Correct 2 ms 12636 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 12636 KB Output is correct
27 Correct 3 ms 12636 KB Output is correct
28 Correct 3 ms 12636 KB Output is correct
29 Execution timed out 2035 ms 24516 KB Time limit exceeded
30 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 12792 KB Output is correct
2 Correct 2 ms 12776 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 12736 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 12648 KB Output is correct
9 Correct 3 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 3 ms 12636 KB Output is correct
14 Correct 3 ms 12632 KB Output is correct
15 Correct 3 ms 12732 KB Output is correct
16 Correct 3 ms 12636 KB Output is correct
17 Correct 3 ms 12636 KB Output is correct
18 Correct 3 ms 12636 KB Output is correct
19 Correct 2 ms 12636 KB Output is correct
20 Correct 3 ms 12636 KB Output is correct
21 Correct 3 ms 12636 KB Output is correct
22 Correct 3 ms 12636 KB Output is correct
23 Correct 2 ms 12636 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 12636 KB Output is correct
27 Correct 3 ms 12636 KB Output is correct
28 Correct 3 ms 12636 KB Output is correct
29 Correct 8 ms 12892 KB Output is correct
30 Correct 8 ms 12892 KB Output is correct
31 Correct 10 ms 12956 KB Output is correct
32 Correct 11 ms 12952 KB Output is correct
33 Correct 10 ms 12892 KB Output is correct
34 Correct 5 ms 12964 KB Output is correct
35 Correct 9 ms 12892 KB Output is correct
36 Correct 4 ms 12892 KB Output is correct
37 Correct 8 ms 12892 KB Output is correct
38 Correct 6 ms 12892 KB Output is correct
39 Correct 6 ms 12892 KB Output is correct
40 Correct 5 ms 12736 KB Output is correct
41 Correct 5 ms 12892 KB Output is correct
42 Correct 5 ms 12892 KB Output is correct
43 Correct 8 ms 12960 KB Output is correct
44 Correct 9 ms 12892 KB Output is correct
45 Correct 7 ms 12892 KB Output is correct
46 Correct 8 ms 12964 KB Output is correct
47 Correct 8 ms 12892 KB Output is correct
48 Correct 8 ms 12956 KB Output is correct
49 Correct 8 ms 12888 KB Output is correct
50 Correct 8 ms 12908 KB Output is correct
51 Correct 9 ms 12892 KB Output is correct
52 Correct 9 ms 12892 KB Output is correct
53 Correct 9 ms 12892 KB Output is correct
54 Correct 9 ms 12892 KB Output is correct
55 Correct 1596 ms 22976 KB Output is correct
56 Execution timed out 2063 ms 23952 KB Time limit exceeded
57 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 12792 KB Output is correct
2 Correct 2 ms 12776 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 12736 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 12648 KB Output is correct
9 Correct 3 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 3 ms 12636 KB Output is correct
14 Correct 3 ms 12632 KB Output is correct
15 Correct 3 ms 12732 KB Output is correct
16 Correct 3 ms 12636 KB Output is correct
17 Correct 3 ms 12636 KB Output is correct
18 Correct 3 ms 12636 KB Output is correct
19 Correct 2 ms 12636 KB Output is correct
20 Correct 3 ms 12636 KB Output is correct
21 Correct 3 ms 12636 KB Output is correct
22 Correct 3 ms 12636 KB Output is correct
23 Correct 2 ms 12636 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 12636 KB Output is correct
27 Correct 3 ms 12636 KB Output is correct
28 Correct 3 ms 12636 KB Output is correct
29 Correct 8 ms 12892 KB Output is correct
30 Correct 8 ms 12892 KB Output is correct
31 Correct 10 ms 12956 KB Output is correct
32 Correct 11 ms 12952 KB Output is correct
33 Correct 10 ms 12892 KB Output is correct
34 Correct 5 ms 12964 KB Output is correct
35 Correct 9 ms 12892 KB Output is correct
36 Correct 4 ms 12892 KB Output is correct
37 Correct 8 ms 12892 KB Output is correct
38 Correct 6 ms 12892 KB Output is correct
39 Correct 6 ms 12892 KB Output is correct
40 Correct 5 ms 12736 KB Output is correct
41 Correct 5 ms 12892 KB Output is correct
42 Correct 5 ms 12892 KB Output is correct
43 Correct 8 ms 12960 KB Output is correct
44 Correct 9 ms 12892 KB Output is correct
45 Correct 7 ms 12892 KB Output is correct
46 Correct 8 ms 12964 KB Output is correct
47 Correct 8 ms 12892 KB Output is correct
48 Correct 8 ms 12956 KB Output is correct
49 Correct 8 ms 12888 KB Output is correct
50 Correct 8 ms 12908 KB Output is correct
51 Correct 9 ms 12892 KB Output is correct
52 Correct 9 ms 12892 KB Output is correct
53 Correct 9 ms 12892 KB Output is correct
54 Correct 9 ms 12892 KB Output is correct
55 Execution timed out 2035 ms 24516 KB Time limit exceeded
56 Halted 0 ms 0 KB -