답안 #670011

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
670011 2022-12-07T18:15:13 Z radal Joker (BOI20_joker) C++17
100 / 100
453 ms 11264 KB
#include <bits/stdc++.h>
#pragma GCC target("sse,sse2,avx2")
#pragma GCC optimize("unroll-loops,O2")
#define rep(i,l,r) for (int i = l; i < r; i++)
#define repr(i,r,l) for (int i = r; i >= l; i--)
#define X first
#define Y second
#define all(x) (x).begin() , (x).end()
#define pb push_back
#define endl '\n'
#define debug(x) cerr << #x << " : " << x << endl;
using namespace std;
typedef long long ll;
typedef pair<int,int> pll;
constexpr int N = 2e5+10,mod = 1e9+7,maxm = 210;
constexpr ll inf = 1e9+10;
inline int mkay(int a,int b){
    if (a+b >= mod) return a+b-mod;
   // if (a+b < 0) return a+b+mod;
    return a+b;
}

inline int poww(int a,int k){
    if (k < 0) return 0;
    int z = 1;
    while (k){
        if (k&1) z = 1ll*z*a%mod;
        a = 1ll*a*a%mod;
        k >>= 1;
    } 
    return z; 
}

int n,m,q;
int par[N],h[N],sz[N];
int opt[N];
vector<pll> ed;
pll pa;
stack<int> st;

int getpar(int v){
	if (v == par[v]) return v;
	return getpar(par[v]);
}

bool geth(int v){
	if (v == par[v]) return 0;
	return geth(par[v])^h[v]; 
}

bool mg(int u,int v){
	int p1 = getpar(u);
	int p2 = getpar(v);
	if (p1 == p2){
		if (geth(v) == geth(u)) return 0;
		st.push(-1);
		return 1;
	}
	if (sz[p1] > sz[p2]) swap(p1,p2);
	st.push(p1);
	h[p1] = geth(u)^geth(v)^1;
	par[p1] = p2;
	sz[p2] += sz[p1];
	return 1;
}

void undo(){
	int v = st.top();
	int p = par[v];
	sz[p] -= sz[v];
	par[v] = v;
	h[v] = 0;
	st.pop();
}

void solve(int l,int r,int s,int e){
	if (r == l) return;
	int siz = st.size();
	int mid = (l+r) >> 1;
	pll tmp = pa;
	while (pa.Y-1 > mid){
		pa.Y--;
		mg(ed[pa.Y].X,ed[pa.Y].Y);
	}
	while (pa.X < s){
		mg(ed[pa.X].X,ed[pa.X].Y);
		pa.X++;
	}
	int R = min(e,mid+1);
	rep(i,s,R){
		if (!mg(ed[i].X,ed[i].Y)){
			opt[mid] = i;
			break;
		}
	}
	while ((int) st.size() > siz) undo();
	pa = tmp;
	if (r-l == 1) return;
    while (pa.X < s){
        mg(ed[pa.X].X,ed[pa.X].Y);
        pa.X++;
    }
    while (pa.Y > r){
        pa.Y--;
        mg(ed[pa.Y].X,ed[pa.Y].Y);
    }
	solve(mid+1,r,opt[mid],e);
	solve(l,mid,s,opt[mid]+1);
	while ((int) st.size() > siz) undo();
	pa = tmp;
}

int main(){
	ios :: sync_with_stdio(0);	cin.tie(0);
	cin >> n >> m >> q;
	rep(i,1,n+1){
	   	par[i] = i;
		sz[i] = 1;
	}
	rep(i,0,m){
		int u,v;
		cin >> u >> v;
		ed.pb({u,v});
	}

	int L = -1;
	repr(i,m-1,0){
		int u = ed[i].X,v = ed[i].Y;
		int p1 = getpar(u),p2 = getpar(v);
		if (p1 != p2){
			if (sz[p1] > sz[p2]) swap(p1,p2);
			h[p1] = geth(u)^geth(v)^1;
			par[p1] = p2;
			sz[p2] += sz[p1];
			continue;
		}
		else if (geth(u) == geth(v)){
		   	L = i;
			break;
		}
	}
	if (L == -1){
		while (q--) cout << "NO" << endl;
		return 0;
	}
	rep(i,0,L) opt[i] = -inf;
	pa = {0,m};
	rep(i,1,n+1){
		par[i] = i;
		h[i] = 0;
		sz[i] = 1;
	}
	solve(L,m,0,m);
	//rep(i,0,m) debug(opt[i]);
	while (q--){
		int l,r;
		cin >> l >> r;
		l--;
		if (opt[r-1] < l) cout << "YES" << endl;
		else cout << "NO" << endl;
	}
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 328 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 356 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 328 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 356 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 2 ms 408 KB Output is correct
31 Correct 2 ms 340 KB Output is correct
32 Correct 2 ms 340 KB Output is correct
33 Correct 2 ms 340 KB Output is correct
34 Correct 2 ms 340 KB Output is correct
35 Correct 3 ms 340 KB Output is correct
36 Correct 2 ms 344 KB Output is correct
37 Correct 3 ms 340 KB Output is correct
38 Correct 1 ms 340 KB Output is correct
39 Correct 2 ms 340 KB Output is correct
40 Correct 3 ms 540 KB Output is correct
41 Correct 2 ms 340 KB Output is correct
42 Correct 2 ms 340 KB Output is correct
43 Correct 2 ms 344 KB Output is correct
44 Correct 2 ms 340 KB Output is correct
45 Correct 2 ms 348 KB Output is correct
46 Correct 3 ms 408 KB Output is correct
47 Correct 2 ms 340 KB Output is correct
48 Correct 3 ms 340 KB Output is correct
49 Correct 2 ms 340 KB Output is correct
50 Correct 2 ms 344 KB Output is correct
51 Correct 4 ms 340 KB Output is correct
52 Correct 2 ms 340 KB Output is correct
53 Correct 2 ms 340 KB Output is correct
54 Correct 3 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 233 ms 7588 KB Output is correct
4 Correct 48 ms 7544 KB Output is correct
5 Correct 146 ms 8824 KB Output is correct
6 Correct 205 ms 7468 KB Output is correct
7 Correct 225 ms 7472 KB Output is correct
8 Correct 237 ms 7264 KB Output is correct
9 Correct 283 ms 7844 KB Output is correct
10 Correct 338 ms 8812 KB Output is correct
11 Correct 266 ms 7488 KB Output is correct
12 Correct 277 ms 8512 KB Output is correct
13 Correct 235 ms 6568 KB Output is correct
14 Correct 233 ms 7076 KB Output is correct
15 Correct 303 ms 8160 KB Output is correct
16 Correct 362 ms 8872 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 328 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 356 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 233 ms 7588 KB Output is correct
30 Correct 48 ms 7544 KB Output is correct
31 Correct 146 ms 8824 KB Output is correct
32 Correct 205 ms 7468 KB Output is correct
33 Correct 225 ms 7472 KB Output is correct
34 Correct 237 ms 7264 KB Output is correct
35 Correct 283 ms 7844 KB Output is correct
36 Correct 338 ms 8812 KB Output is correct
37 Correct 266 ms 7488 KB Output is correct
38 Correct 277 ms 8512 KB Output is correct
39 Correct 235 ms 6568 KB Output is correct
40 Correct 233 ms 7076 KB Output is correct
41 Correct 303 ms 8160 KB Output is correct
42 Correct 362 ms 8872 KB Output is correct
43 Correct 237 ms 7680 KB Output is correct
44 Correct 49 ms 7592 KB Output is correct
45 Correct 324 ms 9324 KB Output is correct
46 Correct 203 ms 7768 KB Output is correct
47 Correct 247 ms 7848 KB Output is correct
48 Correct 307 ms 8000 KB Output is correct
49 Correct 368 ms 9664 KB Output is correct
50 Correct 304 ms 8388 KB Output is correct
51 Correct 279 ms 9112 KB Output is correct
52 Correct 278 ms 9920 KB Output is correct
53 Correct 208 ms 7964 KB Output is correct
54 Correct 279 ms 8516 KB Output is correct
55 Correct 302 ms 9128 KB Output is correct
56 Correct 352 ms 9944 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 328 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 356 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 2 ms 408 KB Output is correct
31 Correct 2 ms 340 KB Output is correct
32 Correct 2 ms 340 KB Output is correct
33 Correct 2 ms 340 KB Output is correct
34 Correct 2 ms 340 KB Output is correct
35 Correct 3 ms 340 KB Output is correct
36 Correct 2 ms 344 KB Output is correct
37 Correct 3 ms 340 KB Output is correct
38 Correct 1 ms 340 KB Output is correct
39 Correct 2 ms 340 KB Output is correct
40 Correct 3 ms 540 KB Output is correct
41 Correct 2 ms 340 KB Output is correct
42 Correct 2 ms 340 KB Output is correct
43 Correct 2 ms 344 KB Output is correct
44 Correct 2 ms 340 KB Output is correct
45 Correct 2 ms 348 KB Output is correct
46 Correct 3 ms 408 KB Output is correct
47 Correct 2 ms 340 KB Output is correct
48 Correct 3 ms 340 KB Output is correct
49 Correct 2 ms 340 KB Output is correct
50 Correct 2 ms 344 KB Output is correct
51 Correct 4 ms 340 KB Output is correct
52 Correct 2 ms 340 KB Output is correct
53 Correct 2 ms 340 KB Output is correct
54 Correct 3 ms 340 KB Output is correct
55 Correct 191 ms 6540 KB Output is correct
56 Correct 38 ms 6920 KB Output is correct
57 Correct 96 ms 8000 KB Output is correct
58 Correct 164 ms 6632 KB Output is correct
59 Correct 255 ms 6572 KB Output is correct
60 Correct 290 ms 7400 KB Output is correct
61 Correct 223 ms 6528 KB Output is correct
62 Correct 253 ms 7656 KB Output is correct
63 Correct 211 ms 5936 KB Output is correct
64 Correct 263 ms 6852 KB Output is correct
65 Correct 303 ms 7640 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 328 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 356 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 2 ms 408 KB Output is correct
31 Correct 2 ms 340 KB Output is correct
32 Correct 2 ms 340 KB Output is correct
33 Correct 2 ms 340 KB Output is correct
34 Correct 2 ms 340 KB Output is correct
35 Correct 3 ms 340 KB Output is correct
36 Correct 2 ms 344 KB Output is correct
37 Correct 3 ms 340 KB Output is correct
38 Correct 1 ms 340 KB Output is correct
39 Correct 2 ms 340 KB Output is correct
40 Correct 3 ms 540 KB Output is correct
41 Correct 2 ms 340 KB Output is correct
42 Correct 2 ms 340 KB Output is correct
43 Correct 2 ms 344 KB Output is correct
44 Correct 2 ms 340 KB Output is correct
45 Correct 2 ms 348 KB Output is correct
46 Correct 3 ms 408 KB Output is correct
47 Correct 2 ms 340 KB Output is correct
48 Correct 3 ms 340 KB Output is correct
49 Correct 2 ms 340 KB Output is correct
50 Correct 2 ms 344 KB Output is correct
51 Correct 4 ms 340 KB Output is correct
52 Correct 2 ms 340 KB Output is correct
53 Correct 2 ms 340 KB Output is correct
54 Correct 3 ms 340 KB Output is correct
55 Correct 233 ms 7588 KB Output is correct
56 Correct 48 ms 7544 KB Output is correct
57 Correct 146 ms 8824 KB Output is correct
58 Correct 205 ms 7468 KB Output is correct
59 Correct 225 ms 7472 KB Output is correct
60 Correct 237 ms 7264 KB Output is correct
61 Correct 283 ms 7844 KB Output is correct
62 Correct 338 ms 8812 KB Output is correct
63 Correct 266 ms 7488 KB Output is correct
64 Correct 277 ms 8512 KB Output is correct
65 Correct 235 ms 6568 KB Output is correct
66 Correct 233 ms 7076 KB Output is correct
67 Correct 303 ms 8160 KB Output is correct
68 Correct 362 ms 8872 KB Output is correct
69 Correct 237 ms 7680 KB Output is correct
70 Correct 49 ms 7592 KB Output is correct
71 Correct 324 ms 9324 KB Output is correct
72 Correct 203 ms 7768 KB Output is correct
73 Correct 247 ms 7848 KB Output is correct
74 Correct 307 ms 8000 KB Output is correct
75 Correct 368 ms 9664 KB Output is correct
76 Correct 304 ms 8388 KB Output is correct
77 Correct 279 ms 9112 KB Output is correct
78 Correct 278 ms 9920 KB Output is correct
79 Correct 208 ms 7964 KB Output is correct
80 Correct 279 ms 8516 KB Output is correct
81 Correct 302 ms 9128 KB Output is correct
82 Correct 352 ms 9944 KB Output is correct
83 Correct 191 ms 6540 KB Output is correct
84 Correct 38 ms 6920 KB Output is correct
85 Correct 96 ms 8000 KB Output is correct
86 Correct 164 ms 6632 KB Output is correct
87 Correct 255 ms 6572 KB Output is correct
88 Correct 290 ms 7400 KB Output is correct
89 Correct 223 ms 6528 KB Output is correct
90 Correct 253 ms 7656 KB Output is correct
91 Correct 211 ms 5936 KB Output is correct
92 Correct 263 ms 6852 KB Output is correct
93 Correct 303 ms 7640 KB Output is correct
94 Correct 233 ms 8768 KB Output is correct
95 Correct 453 ms 10272 KB Output is correct
96 Correct 141 ms 10048 KB Output is correct
97 Correct 204 ms 8828 KB Output is correct
98 Correct 268 ms 8920 KB Output is correct
99 Correct 337 ms 8576 KB Output is correct
100 Correct 297 ms 10300 KB Output is correct
101 Correct 262 ms 8776 KB Output is correct
102 Correct 311 ms 9500 KB Output is correct
103 Correct 319 ms 10188 KB Output is correct
104 Correct 243 ms 8272 KB Output is correct
105 Correct 313 ms 9360 KB Output is correct
106 Correct 364 ms 10520 KB Output is correct
107 Correct 181 ms 11264 KB Output is correct
108 Correct 229 ms 9696 KB Output is correct
109 Correct 232 ms 9596 KB Output is correct
110 Correct 228 ms 9536 KB Output is correct
111 Correct 230 ms 9708 KB Output is correct
112 Correct 230 ms 9652 KB Output is correct
113 Correct 243 ms 9484 KB Output is correct
114 Correct 233 ms 9604 KB Output is correct
115 Correct 230 ms 9468 KB Output is correct
116 Correct 238 ms 9420 KB Output is correct