답안 #670009

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
670009 2022-12-07T18:13:51 Z radal Joker (BOI20_joker) C++17
100 / 100
434 ms 11732 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(l,mid,s,opt[mid]+1);
	solve(mid+1,r,opt[mid],e);
	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 284 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 336 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 340 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 324 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 336 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 0 ms 340 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 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 284 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 336 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 340 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 324 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 336 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 0 ms 340 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 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 332 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 2 ms 404 KB Output is correct
31 Correct 2 ms 340 KB Output is correct
32 Correct 2 ms 340 KB Output is correct
33 Correct 1 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 340 KB Output is correct
37 Correct 3 ms 340 KB Output is correct
38 Correct 1 ms 412 KB Output is correct
39 Correct 2 ms 340 KB Output is correct
40 Correct 2 ms 340 KB Output is correct
41 Correct 2 ms 340 KB Output is correct
42 Correct 2 ms 424 KB Output is correct
43 Correct 2 ms 340 KB Output is correct
44 Correct 2 ms 420 KB Output is correct
45 Correct 2 ms 340 KB Output is correct
46 Correct 4 ms 340 KB Output is correct
47 Correct 2 ms 340 KB Output is correct
48 Correct 2 ms 340 KB Output is correct
49 Correct 2 ms 340 KB Output is correct
50 Correct 2 ms 336 KB Output is correct
51 Correct 2 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 2 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 284 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 225 ms 8944 KB Output is correct
4 Correct 47 ms 7616 KB Output is correct
5 Correct 136 ms 10416 KB Output is correct
6 Correct 191 ms 8896 KB Output is correct
7 Correct 222 ms 8924 KB Output is correct
8 Correct 228 ms 7976 KB Output is correct
9 Correct 244 ms 8356 KB Output is correct
10 Correct 332 ms 9676 KB Output is correct
11 Correct 250 ms 8808 KB Output is correct
12 Correct 267 ms 9916 KB Output is correct
13 Correct 197 ms 7744 KB Output is correct
14 Correct 236 ms 8468 KB Output is correct
15 Correct 291 ms 9376 KB Output is correct
16 Correct 323 ms 10120 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 284 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 336 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 340 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 324 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 336 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 0 ms 340 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 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 332 KB Output is correct
29 Correct 225 ms 8944 KB Output is correct
30 Correct 47 ms 7616 KB Output is correct
31 Correct 136 ms 10416 KB Output is correct
32 Correct 191 ms 8896 KB Output is correct
33 Correct 222 ms 8924 KB Output is correct
34 Correct 228 ms 7976 KB Output is correct
35 Correct 244 ms 8356 KB Output is correct
36 Correct 332 ms 9676 KB Output is correct
37 Correct 250 ms 8808 KB Output is correct
38 Correct 267 ms 9916 KB Output is correct
39 Correct 197 ms 7744 KB Output is correct
40 Correct 236 ms 8468 KB Output is correct
41 Correct 291 ms 9376 KB Output is correct
42 Correct 323 ms 10120 KB Output is correct
43 Correct 227 ms 9144 KB Output is correct
44 Correct 46 ms 7540 KB Output is correct
45 Correct 318 ms 10796 KB Output is correct
46 Correct 192 ms 9136 KB Output is correct
47 Correct 226 ms 9152 KB Output is correct
48 Correct 284 ms 8868 KB Output is correct
49 Correct 341 ms 10224 KB Output is correct
50 Correct 240 ms 8920 KB Output is correct
51 Correct 257 ms 9760 KB Output is correct
52 Correct 269 ms 10352 KB Output is correct
53 Correct 199 ms 8088 KB Output is correct
54 Correct 272 ms 8884 KB Output is correct
55 Correct 292 ms 9792 KB Output is correct
56 Correct 337 ms 10464 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 284 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 336 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 340 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 324 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 336 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 0 ms 340 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 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 332 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 2 ms 404 KB Output is correct
31 Correct 2 ms 340 KB Output is correct
32 Correct 2 ms 340 KB Output is correct
33 Correct 1 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 340 KB Output is correct
37 Correct 3 ms 340 KB Output is correct
38 Correct 1 ms 412 KB Output is correct
39 Correct 2 ms 340 KB Output is correct
40 Correct 2 ms 340 KB Output is correct
41 Correct 2 ms 340 KB Output is correct
42 Correct 2 ms 424 KB Output is correct
43 Correct 2 ms 340 KB Output is correct
44 Correct 2 ms 420 KB Output is correct
45 Correct 2 ms 340 KB Output is correct
46 Correct 4 ms 340 KB Output is correct
47 Correct 2 ms 340 KB Output is correct
48 Correct 2 ms 340 KB Output is correct
49 Correct 2 ms 340 KB Output is correct
50 Correct 2 ms 336 KB Output is correct
51 Correct 2 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 2 ms 340 KB Output is correct
55 Correct 185 ms 6596 KB Output is correct
56 Correct 49 ms 6944 KB Output is correct
57 Correct 92 ms 8060 KB Output is correct
58 Correct 163 ms 6596 KB Output is correct
59 Correct 236 ms 6480 KB Output is correct
60 Correct 276 ms 7468 KB Output is correct
61 Correct 221 ms 6672 KB Output is correct
62 Correct 243 ms 7752 KB Output is correct
63 Correct 174 ms 5812 KB Output is correct
64 Correct 252 ms 6800 KB Output is correct
65 Correct 286 ms 7728 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 284 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 336 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 340 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 324 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 336 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 0 ms 340 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 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 332 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 2 ms 404 KB Output is correct
31 Correct 2 ms 340 KB Output is correct
32 Correct 2 ms 340 KB Output is correct
33 Correct 1 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 340 KB Output is correct
37 Correct 3 ms 340 KB Output is correct
38 Correct 1 ms 412 KB Output is correct
39 Correct 2 ms 340 KB Output is correct
40 Correct 2 ms 340 KB Output is correct
41 Correct 2 ms 340 KB Output is correct
42 Correct 2 ms 424 KB Output is correct
43 Correct 2 ms 340 KB Output is correct
44 Correct 2 ms 420 KB Output is correct
45 Correct 2 ms 340 KB Output is correct
46 Correct 4 ms 340 KB Output is correct
47 Correct 2 ms 340 KB Output is correct
48 Correct 2 ms 340 KB Output is correct
49 Correct 2 ms 340 KB Output is correct
50 Correct 2 ms 336 KB Output is correct
51 Correct 2 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 2 ms 340 KB Output is correct
55 Correct 225 ms 8944 KB Output is correct
56 Correct 47 ms 7616 KB Output is correct
57 Correct 136 ms 10416 KB Output is correct
58 Correct 191 ms 8896 KB Output is correct
59 Correct 222 ms 8924 KB Output is correct
60 Correct 228 ms 7976 KB Output is correct
61 Correct 244 ms 8356 KB Output is correct
62 Correct 332 ms 9676 KB Output is correct
63 Correct 250 ms 8808 KB Output is correct
64 Correct 267 ms 9916 KB Output is correct
65 Correct 197 ms 7744 KB Output is correct
66 Correct 236 ms 8468 KB Output is correct
67 Correct 291 ms 9376 KB Output is correct
68 Correct 323 ms 10120 KB Output is correct
69 Correct 227 ms 9144 KB Output is correct
70 Correct 46 ms 7540 KB Output is correct
71 Correct 318 ms 10796 KB Output is correct
72 Correct 192 ms 9136 KB Output is correct
73 Correct 226 ms 9152 KB Output is correct
74 Correct 284 ms 8868 KB Output is correct
75 Correct 341 ms 10224 KB Output is correct
76 Correct 240 ms 8920 KB Output is correct
77 Correct 257 ms 9760 KB Output is correct
78 Correct 269 ms 10352 KB Output is correct
79 Correct 199 ms 8088 KB Output is correct
80 Correct 272 ms 8884 KB Output is correct
81 Correct 292 ms 9792 KB Output is correct
82 Correct 337 ms 10464 KB Output is correct
83 Correct 185 ms 6596 KB Output is correct
84 Correct 49 ms 6944 KB Output is correct
85 Correct 92 ms 8060 KB Output is correct
86 Correct 163 ms 6596 KB Output is correct
87 Correct 236 ms 6480 KB Output is correct
88 Correct 276 ms 7468 KB Output is correct
89 Correct 221 ms 6672 KB Output is correct
90 Correct 243 ms 7752 KB Output is correct
91 Correct 174 ms 5812 KB Output is correct
92 Correct 252 ms 6800 KB Output is correct
93 Correct 286 ms 7728 KB Output is correct
94 Correct 226 ms 9796 KB Output is correct
95 Correct 434 ms 11448 KB Output is correct
96 Correct 133 ms 11200 KB Output is correct
97 Correct 206 ms 9888 KB Output is correct
98 Correct 224 ms 9892 KB Output is correct
99 Correct 231 ms 9384 KB Output is correct
100 Correct 283 ms 11200 KB Output is correct
101 Correct 247 ms 9568 KB Output is correct
102 Correct 273 ms 10496 KB Output is correct
103 Correct 305 ms 11308 KB Output is correct
104 Correct 230 ms 9148 KB Output is correct
105 Correct 296 ms 10236 KB Output is correct
106 Correct 338 ms 11072 KB Output is correct
107 Correct 168 ms 11732 KB Output is correct
108 Correct 228 ms 9728 KB Output is correct
109 Correct 237 ms 9664 KB Output is correct
110 Correct 228 ms 9664 KB Output is correct
111 Correct 228 ms 9664 KB Output is correct
112 Correct 225 ms 9680 KB Output is correct
113 Correct 233 ms 9664 KB Output is correct
114 Correct 237 ms 9660 KB Output is correct
115 Correct 231 ms 9636 KB Output is correct
116 Correct 223 ms 9640 KB Output is correct