답안 #1054310

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1054310 2024-08-12T08:37:28 Z allin27x Joker (BOI20_joker) C++17
49 / 100
2000 ms 25788 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long 
const int mod = 1e9+7;
#define forn(i,n) for(int i=0; i<n; i++)
#define readv(a,n) vector<int>a(n);forn(i,n)cin>>a[i];
#define readvv(a,n,m) vector<vector<int>> a(n,vector<int>(m));forn(i,n)forn(j,m)cin>>a[i][j];
#define all(a) a.begin(), a.end()
#define _max(x,y) x = max(x,y)
#define _min(x,y) x = min(x,y)
// #define f first
// #define s second

const int N = 2e5+4;
const int SQRT = 460;
int ans[N];

struct qr{
	int l, r, i;
	bool operator<(qr b){
		return make_pair(l/SQRT, r) < make_pair(b.l/SQRT,b.r);
	}
};

vector<qr> queries[SQRT];
int edges[N][2];

struct DSU{
	vector<int> par;
	vector<int> size;
	stack<int> rb;
	int cmp;
	DSU(int n){
		par.resize(n); for(int i=0; i<n; ++i) par[i]=i;
		size.resize(n,1); cmp = n;
	}
	int get(int p){
		return par[p]==p? p: get(par[p]);
	}
	void unite(int a, int b){
		a = get(a); b = get(b);
		if (a==b){
			rb.push(-1);
			return;
		}
		cmp--;
		if (size[a] > size[b]) swap(a,b);
		rb.push(a);
		size[b]+=size[a];
		par[a] = b;
	}
	int conn(int a, int b){
		return get(a) == get(b);
	}
	void rollback(){
		int f = rb.top();
		rb.pop();
		if (f==-1) return;
		cmp++;
		size[par[f]] -= size[f];
		par[f] = f;
	}
};


void solve(){
	int n,m,q; cin>>n>>m>>q;
	for (int i=0; i<m; i++){
		int a,b; cin>>a>>b; a--;b--; edges[i][0]=a; edges[i][1] = b;
	}
	for (int i=0; i<q; i++){
		int l,r; cin>>l>>r; l--; r--;
		qr p; p.l=l;p.r=r;p.i=i;
		queries[l/SQRT].push_back(p);
	}
	for (int i=0; i<SQRT; i++) sort(queries[i].begin(), queries[i].end());
	DSU dsu(2*n);
	int fM =0; 
	for (int t=0; t<SQRT; t++){
		if (t*SQRT >= m) break;
		int fm = 0;
		int i = m-1; int j = queries[t].size()-1;
		while (i>=0){
			if (j<0) break;
			qr p = queries[t][j];
			while (p.r == i){
				int f = 0;
				for (int ll=t*SQRT; ll<p.l; ll++){
					if (dsu.conn(edges[ll][0],edges[ll][1])) f++;
					dsu.unite(edges[ll][0]+n, edges[ll][1]);
					dsu.unite(edges[ll][0], edges[ll][1]+n);
				}
				for (int ll=t*SQRT; ll<p.l; ll++){
					dsu.rollback(); dsu.rollback();
				}
				if (f || fm || fM) ans[p.i] = 1;
				j--;
				if (j<0) break;
				p = queries[t][j];
			}
			if (j<0) break;
			fm += dsu.conn(edges[i][0], edges[i][1]);
			dsu.unite(edges[i][0] + n, edges[i][1]);
			dsu.unite(edges[i][0], edges[i][1] + n);
			i--;
		}
		for (int ll=2*(i+1); ll<2*m; ll++) dsu.rollback();
		for (int ll=SQRT*t; ll<min(m, SQRT*t + SQRT); ll++){
			fM += dsu.conn(edges[ll][0], edges[ll][1]);
			dsu.unite(edges[ll][0] + n, edges[ll][1]);
			dsu.unite(edges[ll][0], edges[ll][1] + n);
		}
	}
	for (int i=0;i<q; i++) cout<<(ans[i]?"YES\n":"NO\n");
}


signed main(){ 
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	int t=1;
	while(t--){
		solve();
	}	
	return 0;
}

# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2392 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 0 ms 2392 KB Output is correct
4 Correct 0 ms 2392 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 0 ms 2396 KB Output is correct
7 Correct 0 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2392 KB Output is correct
10 Correct 1 ms 2392 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 1 ms 2392 KB Output is correct
22 Correct 1 ms 2396 KB Output is correct
23 Correct 1 ms 2396 KB Output is correct
24 Correct 1 ms 2392 KB Output is correct
25 Correct 1 ms 2396 KB Output is correct
26 Correct 1 ms 2396 KB Output is correct
27 Correct 1 ms 2396 KB Output is correct
28 Correct 1 ms 2396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2392 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 0 ms 2392 KB Output is correct
4 Correct 0 ms 2392 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 0 ms 2396 KB Output is correct
7 Correct 0 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2392 KB Output is correct
10 Correct 1 ms 2392 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 1 ms 2392 KB Output is correct
22 Correct 1 ms 2396 KB Output is correct
23 Correct 1 ms 2396 KB Output is correct
24 Correct 1 ms 2392 KB Output is correct
25 Correct 1 ms 2396 KB Output is correct
26 Correct 1 ms 2396 KB Output is correct
27 Correct 1 ms 2396 KB Output is correct
28 Correct 1 ms 2396 KB Output is correct
29 Correct 8 ms 2652 KB Output is correct
30 Correct 8 ms 2652 KB Output is correct
31 Correct 8 ms 2652 KB Output is correct
32 Correct 8 ms 2652 KB Output is correct
33 Correct 8 ms 2652 KB Output is correct
34 Correct 10 ms 2648 KB Output is correct
35 Correct 9 ms 2652 KB Output is correct
36 Correct 9 ms 2680 KB Output is correct
37 Correct 10 ms 2712 KB Output is correct
38 Correct 8 ms 2648 KB Output is correct
39 Correct 7 ms 2672 KB Output is correct
40 Correct 9 ms 2676 KB Output is correct
41 Correct 8 ms 2652 KB Output is correct
42 Correct 8 ms 2652 KB Output is correct
43 Correct 8 ms 2664 KB Output is correct
44 Correct 13 ms 2652 KB Output is correct
45 Correct 9 ms 2652 KB Output is correct
46 Correct 9 ms 2652 KB Output is correct
47 Correct 7 ms 2652 KB Output is correct
48 Correct 7 ms 2652 KB Output is correct
49 Correct 8 ms 2652 KB Output is correct
50 Correct 8 ms 2652 KB Output is correct
51 Correct 8 ms 2652 KB Output is correct
52 Correct 9 ms 2652 KB Output is correct
53 Correct 8 ms 2652 KB Output is correct
54 Correct 8 ms 2652 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2392 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 61 ms 17328 KB Output is correct
4 Correct 61 ms 19424 KB Output is correct
5 Correct 79 ms 20432 KB Output is correct
6 Correct 63 ms 16824 KB Output is correct
7 Correct 68 ms 17328 KB Output is correct
8 Correct 64 ms 15724 KB Output is correct
9 Correct 67 ms 18356 KB Output is correct
10 Correct 66 ms 20408 KB Output is correct
11 Correct 61 ms 18112 KB Output is correct
12 Correct 69 ms 19676 KB Output is correct
13 Correct 71 ms 14776 KB Output is correct
14 Correct 67 ms 16276 KB Output is correct
15 Correct 71 ms 18100 KB Output is correct
16 Correct 68 ms 20564 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2392 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 0 ms 2392 KB Output is correct
4 Correct 0 ms 2392 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 0 ms 2396 KB Output is correct
7 Correct 0 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2392 KB Output is correct
10 Correct 1 ms 2392 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 1 ms 2392 KB Output is correct
22 Correct 1 ms 2396 KB Output is correct
23 Correct 1 ms 2396 KB Output is correct
24 Correct 1 ms 2392 KB Output is correct
25 Correct 1 ms 2396 KB Output is correct
26 Correct 1 ms 2396 KB Output is correct
27 Correct 1 ms 2396 KB Output is correct
28 Correct 1 ms 2396 KB Output is correct
29 Correct 61 ms 17328 KB Output is correct
30 Correct 61 ms 19424 KB Output is correct
31 Correct 79 ms 20432 KB Output is correct
32 Correct 63 ms 16824 KB Output is correct
33 Correct 68 ms 17328 KB Output is correct
34 Correct 64 ms 15724 KB Output is correct
35 Correct 67 ms 18356 KB Output is correct
36 Correct 66 ms 20408 KB Output is correct
37 Correct 61 ms 18112 KB Output is correct
38 Correct 69 ms 19676 KB Output is correct
39 Correct 71 ms 14776 KB Output is correct
40 Correct 67 ms 16276 KB Output is correct
41 Correct 71 ms 18100 KB Output is correct
42 Correct 68 ms 20564 KB Output is correct
43 Correct 384 ms 17844 KB Output is correct
44 Correct 364 ms 23944 KB Output is correct
45 Correct 371 ms 25012 KB Output is correct
46 Correct 397 ms 21488 KB Output is correct
47 Correct 448 ms 21292 KB Output is correct
48 Correct 451 ms 22200 KB Output is correct
49 Correct 577 ms 24236 KB Output is correct
50 Correct 341 ms 20404 KB Output is correct
51 Correct 373 ms 22476 KB Output is correct
52 Correct 365 ms 25336 KB Output is correct
53 Correct 388 ms 18356 KB Output is correct
54 Correct 494 ms 21132 KB Output is correct
55 Correct 537 ms 22572 KB Output is correct
56 Correct 505 ms 25788 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2392 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 0 ms 2392 KB Output is correct
4 Correct 0 ms 2392 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 0 ms 2396 KB Output is correct
7 Correct 0 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2392 KB Output is correct
10 Correct 1 ms 2392 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 1 ms 2392 KB Output is correct
22 Correct 1 ms 2396 KB Output is correct
23 Correct 1 ms 2396 KB Output is correct
24 Correct 1 ms 2392 KB Output is correct
25 Correct 1 ms 2396 KB Output is correct
26 Correct 1 ms 2396 KB Output is correct
27 Correct 1 ms 2396 KB Output is correct
28 Correct 1 ms 2396 KB Output is correct
29 Correct 8 ms 2652 KB Output is correct
30 Correct 8 ms 2652 KB Output is correct
31 Correct 8 ms 2652 KB Output is correct
32 Correct 8 ms 2652 KB Output is correct
33 Correct 8 ms 2652 KB Output is correct
34 Correct 10 ms 2648 KB Output is correct
35 Correct 9 ms 2652 KB Output is correct
36 Correct 9 ms 2680 KB Output is correct
37 Correct 10 ms 2712 KB Output is correct
38 Correct 8 ms 2648 KB Output is correct
39 Correct 7 ms 2672 KB Output is correct
40 Correct 9 ms 2676 KB Output is correct
41 Correct 8 ms 2652 KB Output is correct
42 Correct 8 ms 2652 KB Output is correct
43 Correct 8 ms 2664 KB Output is correct
44 Correct 13 ms 2652 KB Output is correct
45 Correct 9 ms 2652 KB Output is correct
46 Correct 9 ms 2652 KB Output is correct
47 Correct 7 ms 2652 KB Output is correct
48 Correct 7 ms 2652 KB Output is correct
49 Correct 8 ms 2652 KB Output is correct
50 Correct 8 ms 2652 KB Output is correct
51 Correct 8 ms 2652 KB Output is correct
52 Correct 9 ms 2652 KB Output is correct
53 Correct 8 ms 2652 KB Output is correct
54 Correct 8 ms 2652 KB Output is correct
55 Correct 628 ms 11092 KB Output is correct
56 Correct 1738 ms 14364 KB Output is correct
57 Correct 834 ms 16256 KB Output is correct
58 Correct 959 ms 13532 KB Output is correct
59 Execution timed out 2012 ms 13392 KB Time limit exceeded
60 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2392 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 0 ms 2392 KB Output is correct
4 Correct 0 ms 2392 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 0 ms 2396 KB Output is correct
7 Correct 0 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2392 KB Output is correct
10 Correct 1 ms 2392 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 1 ms 2392 KB Output is correct
22 Correct 1 ms 2396 KB Output is correct
23 Correct 1 ms 2396 KB Output is correct
24 Correct 1 ms 2392 KB Output is correct
25 Correct 1 ms 2396 KB Output is correct
26 Correct 1 ms 2396 KB Output is correct
27 Correct 1 ms 2396 KB Output is correct
28 Correct 1 ms 2396 KB Output is correct
29 Correct 8 ms 2652 KB Output is correct
30 Correct 8 ms 2652 KB Output is correct
31 Correct 8 ms 2652 KB Output is correct
32 Correct 8 ms 2652 KB Output is correct
33 Correct 8 ms 2652 KB Output is correct
34 Correct 10 ms 2648 KB Output is correct
35 Correct 9 ms 2652 KB Output is correct
36 Correct 9 ms 2680 KB Output is correct
37 Correct 10 ms 2712 KB Output is correct
38 Correct 8 ms 2648 KB Output is correct
39 Correct 7 ms 2672 KB Output is correct
40 Correct 9 ms 2676 KB Output is correct
41 Correct 8 ms 2652 KB Output is correct
42 Correct 8 ms 2652 KB Output is correct
43 Correct 8 ms 2664 KB Output is correct
44 Correct 13 ms 2652 KB Output is correct
45 Correct 9 ms 2652 KB Output is correct
46 Correct 9 ms 2652 KB Output is correct
47 Correct 7 ms 2652 KB Output is correct
48 Correct 7 ms 2652 KB Output is correct
49 Correct 8 ms 2652 KB Output is correct
50 Correct 8 ms 2652 KB Output is correct
51 Correct 8 ms 2652 KB Output is correct
52 Correct 9 ms 2652 KB Output is correct
53 Correct 8 ms 2652 KB Output is correct
54 Correct 8 ms 2652 KB Output is correct
55 Correct 61 ms 17328 KB Output is correct
56 Correct 61 ms 19424 KB Output is correct
57 Correct 79 ms 20432 KB Output is correct
58 Correct 63 ms 16824 KB Output is correct
59 Correct 68 ms 17328 KB Output is correct
60 Correct 64 ms 15724 KB Output is correct
61 Correct 67 ms 18356 KB Output is correct
62 Correct 66 ms 20408 KB Output is correct
63 Correct 61 ms 18112 KB Output is correct
64 Correct 69 ms 19676 KB Output is correct
65 Correct 71 ms 14776 KB Output is correct
66 Correct 67 ms 16276 KB Output is correct
67 Correct 71 ms 18100 KB Output is correct
68 Correct 68 ms 20564 KB Output is correct
69 Correct 384 ms 17844 KB Output is correct
70 Correct 364 ms 23944 KB Output is correct
71 Correct 371 ms 25012 KB Output is correct
72 Correct 397 ms 21488 KB Output is correct
73 Correct 448 ms 21292 KB Output is correct
74 Correct 451 ms 22200 KB Output is correct
75 Correct 577 ms 24236 KB Output is correct
76 Correct 341 ms 20404 KB Output is correct
77 Correct 373 ms 22476 KB Output is correct
78 Correct 365 ms 25336 KB Output is correct
79 Correct 388 ms 18356 KB Output is correct
80 Correct 494 ms 21132 KB Output is correct
81 Correct 537 ms 22572 KB Output is correct
82 Correct 505 ms 25788 KB Output is correct
83 Correct 628 ms 11092 KB Output is correct
84 Correct 1738 ms 14364 KB Output is correct
85 Correct 834 ms 16256 KB Output is correct
86 Correct 959 ms 13532 KB Output is correct
87 Execution timed out 2012 ms 13392 KB Time limit exceeded
88 Halted 0 ms 0 KB -