답안 #257444

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
257444 2020-08-04T09:22:41 Z easrui Joker (BOI20_joker) C++14
100 / 100
609 ms 16544 KB
#include <bits/stdc++.h>
#define va first
#define vb second
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef pair<int,int> pii;

const int MN = 2e5+5;

int N,M,Q,pos;
int par[MN<<1],sz[MN<<1],ans[MN];
pii E[MN];

vector<pii> qu;
vector<int> cnt;

int fnd(int u)
{
	return u==par[u] ? u : fnd(par[u]);
}

void join(int u, int v)
{
	u = fnd(u), v = fnd(v);
	if(u==v) u = v = 0;
	if(sz[u]>sz[v]) swap(u,v);
	qu.push_back({u,v});
	par[u] = v;
	sz[v] += sz[u];

}

void upt(int x)
{
	if(x>M){
		join(0,0);
		join(0,0);
		cnt.push_back(0);
		return;
	}
	if(!x){
		for(int i=0; i<2; i++){
			pii q = qu.back();
			sz[q.vb] -= sz[q.va];
			par[q.va] = q.va;
			qu.pop_back();
		}
		pos -= cnt.back();
		cnt.pop_back();
	}
	else{
		join(E[x].va,E[x].vb+N);
		join(E[x].va+N,E[x].vb);
		if(fnd(E[x].va)==fnd(E[x].va+N)){
			pos++;
			cnt.push_back(1);
		}
		else cnt.push_back(0);
	}
}

void solve(int s, int e, int x, int y)
{
	if(s>e) return;
	int m = (s+e)/2;
	int z = y;
	for(int i=s; i<m; i++) upt(i);
	while(1){
		upt(z);
		if(pos||z==m){
			ans[m] = z;
			break;
		}
		z--;
	}
	for(int i=z; i<=y; i++) upt(0);
	for(int i=s; i<m; i++) upt(0);

	for(int i=z+1; i<=y; i++) upt(i);	
	solve(s,m-1,x,z);
	for(int i=z+1; i<=y; i++) upt(0);	

	for(int i=s; i<=m; i++) upt(i);
	solve(m+1,e,max(m+1,z),y);
	for(int i=s; i<=m; i++) upt(0);
}

int main()
{
    ios_base::sync_with_stdio(0),cin.tie(0);
    cin >> N >> M >> Q;

    for(int i=1; i<=M; i++) cin >> E[i].va >> E[i].vb;

    for(int i=1; i<=2*N; i++){
    	par[i] = i;
    	sz[i] = 1;
    }
    solve(1,M,1,M+1);

    while(Q--){
    	int l,r;
    	cin >> l >> r;
    	cout << (r<ans[l] ? "YES\n" : "NO\n");
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 0 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 0 ms 384 KB Output is correct
17 Correct 0 ms 384 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 0 ms 384 KB Output is correct
20 Correct 0 ms 384 KB Output is correct
21 Correct 0 ms 384 KB Output is correct
22 Correct 1 ms 384 KB Output is correct
23 Correct 1 ms 384 KB Output is correct
24 Correct 0 ms 384 KB Output is correct
25 Correct 1 ms 384 KB Output is correct
26 Correct 1 ms 384 KB Output is correct
27 Correct 1 ms 384 KB Output is correct
28 Correct 1 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 0 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 0 ms 384 KB Output is correct
17 Correct 0 ms 384 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 0 ms 384 KB Output is correct
20 Correct 0 ms 384 KB Output is correct
21 Correct 0 ms 384 KB Output is correct
22 Correct 1 ms 384 KB Output is correct
23 Correct 1 ms 384 KB Output is correct
24 Correct 0 ms 384 KB Output is correct
25 Correct 1 ms 384 KB Output is correct
26 Correct 1 ms 384 KB Output is correct
27 Correct 1 ms 384 KB Output is correct
28 Correct 1 ms 384 KB Output is correct
29 Correct 2 ms 384 KB Output is correct
30 Correct 3 ms 512 KB Output is correct
31 Correct 3 ms 512 KB Output is correct
32 Correct 3 ms 512 KB Output is correct
33 Correct 3 ms 512 KB Output is correct
34 Correct 3 ms 512 KB Output is correct
35 Correct 3 ms 512 KB Output is correct
36 Correct 3 ms 512 KB Output is correct
37 Correct 3 ms 512 KB Output is correct
38 Correct 3 ms 512 KB Output is correct
39 Correct 2 ms 512 KB Output is correct
40 Correct 3 ms 512 KB Output is correct
41 Correct 3 ms 512 KB Output is correct
42 Correct 3 ms 512 KB Output is correct
43 Correct 3 ms 512 KB Output is correct
44 Correct 3 ms 512 KB Output is correct
45 Correct 3 ms 512 KB Output is correct
46 Correct 3 ms 512 KB Output is correct
47 Correct 3 ms 512 KB Output is correct
48 Correct 3 ms 512 KB Output is correct
49 Correct 3 ms 512 KB Output is correct
50 Correct 3 ms 512 KB Output is correct
51 Correct 3 ms 512 KB Output is correct
52 Correct 3 ms 512 KB Output is correct
53 Correct 4 ms 512 KB Output is correct
54 Correct 3 ms 512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 369 ms 9888 KB Output is correct
4 Correct 479 ms 11428 KB Output is correct
5 Correct 313 ms 11124 KB Output is correct
6 Correct 426 ms 9896 KB Output is correct
7 Correct 431 ms 10016 KB Output is correct
8 Correct 442 ms 9504 KB Output is correct
9 Correct 502 ms 10016 KB Output is correct
10 Correct 569 ms 11680 KB Output is correct
11 Correct 419 ms 10016 KB Output is correct
12 Correct 466 ms 11168 KB Output is correct
13 Correct 424 ms 8740 KB Output is correct
14 Correct 464 ms 9248 KB Output is correct
15 Correct 579 ms 10528 KB Output is correct
16 Correct 572 ms 11440 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 0 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 0 ms 384 KB Output is correct
17 Correct 0 ms 384 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 0 ms 384 KB Output is correct
20 Correct 0 ms 384 KB Output is correct
21 Correct 0 ms 384 KB Output is correct
22 Correct 1 ms 384 KB Output is correct
23 Correct 1 ms 384 KB Output is correct
24 Correct 0 ms 384 KB Output is correct
25 Correct 1 ms 384 KB Output is correct
26 Correct 1 ms 384 KB Output is correct
27 Correct 1 ms 384 KB Output is correct
28 Correct 1 ms 384 KB Output is correct
29 Correct 369 ms 9888 KB Output is correct
30 Correct 479 ms 11428 KB Output is correct
31 Correct 313 ms 11124 KB Output is correct
32 Correct 426 ms 9896 KB Output is correct
33 Correct 431 ms 10016 KB Output is correct
34 Correct 442 ms 9504 KB Output is correct
35 Correct 502 ms 10016 KB Output is correct
36 Correct 569 ms 11680 KB Output is correct
37 Correct 419 ms 10016 KB Output is correct
38 Correct 466 ms 11168 KB Output is correct
39 Correct 424 ms 8740 KB Output is correct
40 Correct 464 ms 9248 KB Output is correct
41 Correct 579 ms 10528 KB Output is correct
42 Correct 572 ms 11440 KB Output is correct
43 Correct 364 ms 9888 KB Output is correct
44 Correct 498 ms 11472 KB Output is correct
45 Correct 461 ms 11660 KB Output is correct
46 Correct 397 ms 9948 KB Output is correct
47 Correct 451 ms 9976 KB Output is correct
48 Correct 544 ms 10108 KB Output is correct
49 Correct 609 ms 11556 KB Output is correct
50 Correct 428 ms 9576 KB Output is correct
51 Correct 453 ms 10664 KB Output is correct
52 Correct 466 ms 11560 KB Output is correct
53 Correct 446 ms 8608 KB Output is correct
54 Correct 536 ms 9636 KB Output is correct
55 Correct 573 ms 10528 KB Output is correct
56 Correct 577 ms 11424 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 0 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 0 ms 384 KB Output is correct
17 Correct 0 ms 384 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 0 ms 384 KB Output is correct
20 Correct 0 ms 384 KB Output is correct
21 Correct 0 ms 384 KB Output is correct
22 Correct 1 ms 384 KB Output is correct
23 Correct 1 ms 384 KB Output is correct
24 Correct 0 ms 384 KB Output is correct
25 Correct 1 ms 384 KB Output is correct
26 Correct 1 ms 384 KB Output is correct
27 Correct 1 ms 384 KB Output is correct
28 Correct 1 ms 384 KB Output is correct
29 Correct 2 ms 384 KB Output is correct
30 Correct 3 ms 512 KB Output is correct
31 Correct 3 ms 512 KB Output is correct
32 Correct 3 ms 512 KB Output is correct
33 Correct 3 ms 512 KB Output is correct
34 Correct 3 ms 512 KB Output is correct
35 Correct 3 ms 512 KB Output is correct
36 Correct 3 ms 512 KB Output is correct
37 Correct 3 ms 512 KB Output is correct
38 Correct 3 ms 512 KB Output is correct
39 Correct 2 ms 512 KB Output is correct
40 Correct 3 ms 512 KB Output is correct
41 Correct 3 ms 512 KB Output is correct
42 Correct 3 ms 512 KB Output is correct
43 Correct 3 ms 512 KB Output is correct
44 Correct 3 ms 512 KB Output is correct
45 Correct 3 ms 512 KB Output is correct
46 Correct 3 ms 512 KB Output is correct
47 Correct 3 ms 512 KB Output is correct
48 Correct 3 ms 512 KB Output is correct
49 Correct 3 ms 512 KB Output is correct
50 Correct 3 ms 512 KB Output is correct
51 Correct 3 ms 512 KB Output is correct
52 Correct 3 ms 512 KB Output is correct
53 Correct 4 ms 512 KB Output is correct
54 Correct 3 ms 512 KB Output is correct
55 Correct 324 ms 9248 KB Output is correct
56 Correct 432 ms 13368 KB Output is correct
57 Correct 253 ms 12964 KB Output is correct
58 Correct 370 ms 11668 KB Output is correct
59 Correct 514 ms 11552 KB Output is correct
60 Correct 570 ms 12576 KB Output is correct
61 Correct 408 ms 11680 KB Output is correct
62 Correct 418 ms 12960 KB Output is correct
63 Correct 393 ms 10528 KB Output is correct
64 Correct 523 ms 12064 KB Output is correct
65 Correct 565 ms 13088 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 0 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 0 ms 384 KB Output is correct
17 Correct 0 ms 384 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 0 ms 384 KB Output is correct
20 Correct 0 ms 384 KB Output is correct
21 Correct 0 ms 384 KB Output is correct
22 Correct 1 ms 384 KB Output is correct
23 Correct 1 ms 384 KB Output is correct
24 Correct 0 ms 384 KB Output is correct
25 Correct 1 ms 384 KB Output is correct
26 Correct 1 ms 384 KB Output is correct
27 Correct 1 ms 384 KB Output is correct
28 Correct 1 ms 384 KB Output is correct
29 Correct 2 ms 384 KB Output is correct
30 Correct 3 ms 512 KB Output is correct
31 Correct 3 ms 512 KB Output is correct
32 Correct 3 ms 512 KB Output is correct
33 Correct 3 ms 512 KB Output is correct
34 Correct 3 ms 512 KB Output is correct
35 Correct 3 ms 512 KB Output is correct
36 Correct 3 ms 512 KB Output is correct
37 Correct 3 ms 512 KB Output is correct
38 Correct 3 ms 512 KB Output is correct
39 Correct 2 ms 512 KB Output is correct
40 Correct 3 ms 512 KB Output is correct
41 Correct 3 ms 512 KB Output is correct
42 Correct 3 ms 512 KB Output is correct
43 Correct 3 ms 512 KB Output is correct
44 Correct 3 ms 512 KB Output is correct
45 Correct 3 ms 512 KB Output is correct
46 Correct 3 ms 512 KB Output is correct
47 Correct 3 ms 512 KB Output is correct
48 Correct 3 ms 512 KB Output is correct
49 Correct 3 ms 512 KB Output is correct
50 Correct 3 ms 512 KB Output is correct
51 Correct 3 ms 512 KB Output is correct
52 Correct 3 ms 512 KB Output is correct
53 Correct 4 ms 512 KB Output is correct
54 Correct 3 ms 512 KB Output is correct
55 Correct 369 ms 9888 KB Output is correct
56 Correct 479 ms 11428 KB Output is correct
57 Correct 313 ms 11124 KB Output is correct
58 Correct 426 ms 9896 KB Output is correct
59 Correct 431 ms 10016 KB Output is correct
60 Correct 442 ms 9504 KB Output is correct
61 Correct 502 ms 10016 KB Output is correct
62 Correct 569 ms 11680 KB Output is correct
63 Correct 419 ms 10016 KB Output is correct
64 Correct 466 ms 11168 KB Output is correct
65 Correct 424 ms 8740 KB Output is correct
66 Correct 464 ms 9248 KB Output is correct
67 Correct 579 ms 10528 KB Output is correct
68 Correct 572 ms 11440 KB Output is correct
69 Correct 364 ms 9888 KB Output is correct
70 Correct 498 ms 11472 KB Output is correct
71 Correct 461 ms 11660 KB Output is correct
72 Correct 397 ms 9948 KB Output is correct
73 Correct 451 ms 9976 KB Output is correct
74 Correct 544 ms 10108 KB Output is correct
75 Correct 609 ms 11556 KB Output is correct
76 Correct 428 ms 9576 KB Output is correct
77 Correct 453 ms 10664 KB Output is correct
78 Correct 466 ms 11560 KB Output is correct
79 Correct 446 ms 8608 KB Output is correct
80 Correct 536 ms 9636 KB Output is correct
81 Correct 573 ms 10528 KB Output is correct
82 Correct 577 ms 11424 KB Output is correct
83 Correct 324 ms 9248 KB Output is correct
84 Correct 432 ms 13368 KB Output is correct
85 Correct 253 ms 12964 KB Output is correct
86 Correct 370 ms 11668 KB Output is correct
87 Correct 514 ms 11552 KB Output is correct
88 Correct 570 ms 12576 KB Output is correct
89 Correct 408 ms 11680 KB Output is correct
90 Correct 418 ms 12960 KB Output is correct
91 Correct 393 ms 10528 KB Output is correct
92 Correct 523 ms 12064 KB Output is correct
93 Correct 565 ms 13088 KB Output is correct
94 Correct 371 ms 14784 KB Output is correct
95 Correct 397 ms 16544 KB Output is correct
96 Correct 305 ms 11184 KB Output is correct
97 Correct 415 ms 10144 KB Output is correct
98 Correct 436 ms 10164 KB Output is correct
99 Correct 519 ms 9536 KB Output is correct
100 Correct 540 ms 11820 KB Output is correct
101 Correct 415 ms 9724 KB Output is correct
102 Correct 494 ms 10528 KB Output is correct
103 Correct 559 ms 11516 KB Output is correct
104 Correct 478 ms 9076 KB Output is correct
105 Correct 578 ms 10328 KB Output is correct
106 Correct 606 ms 11408 KB Output is correct
107 Correct 267 ms 11420 KB Output is correct
108 Correct 372 ms 9888 KB Output is correct
109 Correct 366 ms 10016 KB Output is correct
110 Correct 384 ms 10016 KB Output is correct
111 Correct 373 ms 9888 KB Output is correct
112 Correct 363 ms 9888 KB Output is correct
113 Correct 380 ms 10140 KB Output is correct
114 Correct 368 ms 10148 KB Output is correct
115 Correct 361 ms 9888 KB Output is correct
116 Correct 372 ms 9852 KB Output is correct