Submission #1054523

# Submission time Handle Problem Language Result Execution time Memory
1054523 2024-08-12T10:28:18 Z allin27x Joker (BOI20_joker) C++17
49 / 100
2000 ms 12856 KB
#include <bits/stdc++.h>
using namespace std;
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];

int e1[2*N];
void build1(int N) {for (int i=0; i<N; i++) e1[i] = -1;}
int get1(int x) { return e1[x] < 0 ? x : e1[x] = get1(e1[x]); }
bool conn1(int a, int b) { return get1(a) == get1(b); }
int size1(int x) { return -e1[get1(x)]; }
void unite1(int x, int y) {
	x = get1(x), y = get1(y);
	if (x == y) return;
	if (e1[x] > e1[y]) swap(x, y);
	e1[x] += e1[y];
	e1[y] = x;
}
int nd = 0;
int ch[2*N];

int e2[2*N];
void build2(int N) {for (int i=0; i<N; i++) e2[i] = -1;}
int get2(int x) { 
	if (e2[x] < 0) return x;
	ch[nd++] = x;
	return e2[x] = get2(e2[x]); 

}
bool conn2(int a, int b) { return get2(a) == get2(b); }
int size2(int x) { return -e2[get2(x)]; }
void unite2(int x, int y) {
	x = get2(x), y = get2(y);
	if (x == y) return;
	if (e2[x] > e2[y]) swap(x, y);
	ch[nd++] = x; ch[nd++] = y;
	e2[x] += e2[y];
	e2[y] = x;
}

int st[2*N];

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());
	build1(2*n); build2(2*n);
	int fM =0; 
	for (int t=0; t<SQRT; t++){
		for (int i=0; i<2*n; i++) e2[i] = e1[i],st[i] = e2[i];
		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;
				nd = 0;
				for (int ll=t*SQRT; ll<p.l; ll++){
					if (conn2(edges[ll][0],edges[ll][1])) f++;
					unite2(edges[ll][0]+n, edges[ll][1]);
					unite2(edges[ll][0], edges[ll][1]+n);
				}
				for (int rr =0; rr<nd; rr++){
					e2[ch[rr]] = st[ch[rr]];
				}
				if (f || fm || fM) ans[p.i] = 1;
				j--;
				if (j<0) break;
				p = queries[t][j];
			}
			if (j<0) break;
			nd = 0;
			fm += conn2(edges[i][0], edges[i][1]);
			unite2(edges[i][0] + n, edges[i][1]);
			unite2(edges[i][0], edges[i][1] + n);
			for (int rr =0; rr<nd; rr++){
				st[ch[rr]] = e2[ch[rr]];
			}
			i--;
		}
		for (int ll=SQRT*t; ll<min(m, SQRT*t + SQRT); ll++){
			fM += conn1(edges[ll][0], edges[ll][1]);
			unite1(edges[ll][0] + n, edges[ll][1]);
			unite1(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;
}

# Verdict Execution time Memory Grader output
1 Correct 1 ms 6488 KB Output is correct
2 Correct 1 ms 6488 KB Output is correct
3 Correct 1 ms 8540 KB Output is correct
4 Correct 1 ms 8540 KB Output is correct
5 Correct 1 ms 8540 KB Output is correct
6 Correct 1 ms 8540 KB Output is correct
7 Correct 1 ms 8540 KB Output is correct
8 Correct 1 ms 8540 KB Output is correct
9 Correct 1 ms 8536 KB Output is correct
10 Correct 1 ms 8536 KB Output is correct
11 Correct 1 ms 8676 KB Output is correct
12 Correct 1 ms 8536 KB Output is correct
13 Correct 1 ms 8540 KB Output is correct
14 Correct 1 ms 8540 KB Output is correct
15 Correct 1 ms 8540 KB Output is correct
16 Correct 1 ms 8540 KB Output is correct
17 Correct 1 ms 8540 KB Output is correct
18 Correct 1 ms 8540 KB Output is correct
19 Correct 1 ms 8540 KB Output is correct
20 Correct 1 ms 8540 KB Output is correct
21 Correct 1 ms 8540 KB Output is correct
22 Correct 1 ms 8548 KB Output is correct
23 Correct 1 ms 8540 KB Output is correct
24 Correct 1 ms 8540 KB Output is correct
25 Correct 1 ms 8540 KB Output is correct
26 Correct 1 ms 8680 KB Output is correct
27 Correct 1 ms 8540 KB Output is correct
28 Correct 1 ms 8540 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6488 KB Output is correct
2 Correct 1 ms 6488 KB Output is correct
3 Correct 1 ms 8540 KB Output is correct
4 Correct 1 ms 8540 KB Output is correct
5 Correct 1 ms 8540 KB Output is correct
6 Correct 1 ms 8540 KB Output is correct
7 Correct 1 ms 8540 KB Output is correct
8 Correct 1 ms 8540 KB Output is correct
9 Correct 1 ms 8536 KB Output is correct
10 Correct 1 ms 8536 KB Output is correct
11 Correct 1 ms 8676 KB Output is correct
12 Correct 1 ms 8536 KB Output is correct
13 Correct 1 ms 8540 KB Output is correct
14 Correct 1 ms 8540 KB Output is correct
15 Correct 1 ms 8540 KB Output is correct
16 Correct 1 ms 8540 KB Output is correct
17 Correct 1 ms 8540 KB Output is correct
18 Correct 1 ms 8540 KB Output is correct
19 Correct 1 ms 8540 KB Output is correct
20 Correct 1 ms 8540 KB Output is correct
21 Correct 1 ms 8540 KB Output is correct
22 Correct 1 ms 8548 KB Output is correct
23 Correct 1 ms 8540 KB Output is correct
24 Correct 1 ms 8540 KB Output is correct
25 Correct 1 ms 8540 KB Output is correct
26 Correct 1 ms 8680 KB Output is correct
27 Correct 1 ms 8540 KB Output is correct
28 Correct 1 ms 8540 KB Output is correct
29 Correct 8 ms 8552 KB Output is correct
30 Correct 9 ms 8540 KB Output is correct
31 Correct 9 ms 8760 KB Output is correct
32 Correct 10 ms 8756 KB Output is correct
33 Correct 9 ms 8748 KB Output is correct
34 Correct 9 ms 8540 KB Output is correct
35 Correct 9 ms 8540 KB Output is correct
36 Correct 10 ms 8540 KB Output is correct
37 Correct 9 ms 8764 KB Output is correct
38 Correct 9 ms 8540 KB Output is correct
39 Correct 10 ms 8756 KB Output is correct
40 Correct 9 ms 8540 KB Output is correct
41 Correct 9 ms 8668 KB Output is correct
42 Correct 9 ms 8540 KB Output is correct
43 Correct 9 ms 8540 KB Output is correct
44 Correct 10 ms 8536 KB Output is correct
45 Correct 10 ms 8764 KB Output is correct
46 Correct 10 ms 8764 KB Output is correct
47 Correct 9 ms 8748 KB Output is correct
48 Correct 9 ms 8540 KB Output is correct
49 Correct 9 ms 8540 KB Output is correct
50 Correct 9 ms 8764 KB Output is correct
51 Correct 10 ms 8700 KB Output is correct
52 Correct 10 ms 8540 KB Output is correct
53 Correct 12 ms 8760 KB Output is correct
54 Correct 11 ms 8536 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6488 KB Output is correct
2 Correct 1 ms 6488 KB Output is correct
3 Correct 76 ms 12052 KB Output is correct
4 Correct 97 ms 11704 KB Output is correct
5 Correct 94 ms 12088 KB Output is correct
6 Correct 76 ms 12224 KB Output is correct
7 Correct 76 ms 12856 KB Output is correct
8 Correct 72 ms 12152 KB Output is correct
9 Correct 77 ms 12220 KB Output is correct
10 Correct 99 ms 12220 KB Output is correct
11 Correct 81 ms 12756 KB Output is correct
12 Correct 94 ms 12340 KB Output is correct
13 Correct 54 ms 12136 KB Output is correct
14 Correct 68 ms 12072 KB Output is correct
15 Correct 88 ms 11968 KB Output is correct
16 Correct 100 ms 11976 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6488 KB Output is correct
2 Correct 1 ms 6488 KB Output is correct
3 Correct 1 ms 8540 KB Output is correct
4 Correct 1 ms 8540 KB Output is correct
5 Correct 1 ms 8540 KB Output is correct
6 Correct 1 ms 8540 KB Output is correct
7 Correct 1 ms 8540 KB Output is correct
8 Correct 1 ms 8540 KB Output is correct
9 Correct 1 ms 8536 KB Output is correct
10 Correct 1 ms 8536 KB Output is correct
11 Correct 1 ms 8676 KB Output is correct
12 Correct 1 ms 8536 KB Output is correct
13 Correct 1 ms 8540 KB Output is correct
14 Correct 1 ms 8540 KB Output is correct
15 Correct 1 ms 8540 KB Output is correct
16 Correct 1 ms 8540 KB Output is correct
17 Correct 1 ms 8540 KB Output is correct
18 Correct 1 ms 8540 KB Output is correct
19 Correct 1 ms 8540 KB Output is correct
20 Correct 1 ms 8540 KB Output is correct
21 Correct 1 ms 8540 KB Output is correct
22 Correct 1 ms 8548 KB Output is correct
23 Correct 1 ms 8540 KB Output is correct
24 Correct 1 ms 8540 KB Output is correct
25 Correct 1 ms 8540 KB Output is correct
26 Correct 1 ms 8680 KB Output is correct
27 Correct 1 ms 8540 KB Output is correct
28 Correct 1 ms 8540 KB Output is correct
29 Correct 76 ms 12052 KB Output is correct
30 Correct 97 ms 11704 KB Output is correct
31 Correct 94 ms 12088 KB Output is correct
32 Correct 76 ms 12224 KB Output is correct
33 Correct 76 ms 12856 KB Output is correct
34 Correct 72 ms 12152 KB Output is correct
35 Correct 77 ms 12220 KB Output is correct
36 Correct 99 ms 12220 KB Output is correct
37 Correct 81 ms 12756 KB Output is correct
38 Correct 94 ms 12340 KB Output is correct
39 Correct 54 ms 12136 KB Output is correct
40 Correct 68 ms 12072 KB Output is correct
41 Correct 88 ms 11968 KB Output is correct
42 Correct 100 ms 11976 KB Output is correct
43 Correct 428 ms 12152 KB Output is correct
44 Correct 424 ms 11708 KB Output is correct
45 Correct 439 ms 11960 KB Output is correct
46 Correct 428 ms 12476 KB Output is correct
47 Correct 430 ms 12336 KB Output is correct
48 Correct 491 ms 12740 KB Output is correct
49 Correct 521 ms 12656 KB Output is correct
50 Correct 498 ms 11968 KB Output is correct
51 Correct 488 ms 12356 KB Output is correct
52 Correct 487 ms 12332 KB Output is correct
53 Correct 431 ms 12040 KB Output is correct
54 Correct 502 ms 12176 KB Output is correct
55 Correct 501 ms 12440 KB Output is correct
56 Correct 522 ms 12080 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6488 KB Output is correct
2 Correct 1 ms 6488 KB Output is correct
3 Correct 1 ms 8540 KB Output is correct
4 Correct 1 ms 8540 KB Output is correct
5 Correct 1 ms 8540 KB Output is correct
6 Correct 1 ms 8540 KB Output is correct
7 Correct 1 ms 8540 KB Output is correct
8 Correct 1 ms 8540 KB Output is correct
9 Correct 1 ms 8536 KB Output is correct
10 Correct 1 ms 8536 KB Output is correct
11 Correct 1 ms 8676 KB Output is correct
12 Correct 1 ms 8536 KB Output is correct
13 Correct 1 ms 8540 KB Output is correct
14 Correct 1 ms 8540 KB Output is correct
15 Correct 1 ms 8540 KB Output is correct
16 Correct 1 ms 8540 KB Output is correct
17 Correct 1 ms 8540 KB Output is correct
18 Correct 1 ms 8540 KB Output is correct
19 Correct 1 ms 8540 KB Output is correct
20 Correct 1 ms 8540 KB Output is correct
21 Correct 1 ms 8540 KB Output is correct
22 Correct 1 ms 8548 KB Output is correct
23 Correct 1 ms 8540 KB Output is correct
24 Correct 1 ms 8540 KB Output is correct
25 Correct 1 ms 8540 KB Output is correct
26 Correct 1 ms 8680 KB Output is correct
27 Correct 1 ms 8540 KB Output is correct
28 Correct 1 ms 8540 KB Output is correct
29 Correct 8 ms 8552 KB Output is correct
30 Correct 9 ms 8540 KB Output is correct
31 Correct 9 ms 8760 KB Output is correct
32 Correct 10 ms 8756 KB Output is correct
33 Correct 9 ms 8748 KB Output is correct
34 Correct 9 ms 8540 KB Output is correct
35 Correct 9 ms 8540 KB Output is correct
36 Correct 10 ms 8540 KB Output is correct
37 Correct 9 ms 8764 KB Output is correct
38 Correct 9 ms 8540 KB Output is correct
39 Correct 10 ms 8756 KB Output is correct
40 Correct 9 ms 8540 KB Output is correct
41 Correct 9 ms 8668 KB Output is correct
42 Correct 9 ms 8540 KB Output is correct
43 Correct 9 ms 8540 KB Output is correct
44 Correct 10 ms 8536 KB Output is correct
45 Correct 10 ms 8764 KB Output is correct
46 Correct 10 ms 8764 KB Output is correct
47 Correct 9 ms 8748 KB Output is correct
48 Correct 9 ms 8540 KB Output is correct
49 Correct 9 ms 8540 KB Output is correct
50 Correct 9 ms 8764 KB Output is correct
51 Correct 10 ms 8700 KB Output is correct
52 Correct 10 ms 8540 KB Output is correct
53 Correct 12 ms 8760 KB Output is correct
54 Correct 11 ms 8536 KB Output is correct
55 Correct 784 ms 11196 KB Output is correct
56 Correct 1482 ms 11408 KB Output is correct
57 Correct 843 ms 10400 KB Output is correct
58 Correct 903 ms 10320 KB Output is correct
59 Correct 1798 ms 10404 KB Output is correct
60 Execution timed out 2055 ms 11352 KB Time limit exceeded
61 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6488 KB Output is correct
2 Correct 1 ms 6488 KB Output is correct
3 Correct 1 ms 8540 KB Output is correct
4 Correct 1 ms 8540 KB Output is correct
5 Correct 1 ms 8540 KB Output is correct
6 Correct 1 ms 8540 KB Output is correct
7 Correct 1 ms 8540 KB Output is correct
8 Correct 1 ms 8540 KB Output is correct
9 Correct 1 ms 8536 KB Output is correct
10 Correct 1 ms 8536 KB Output is correct
11 Correct 1 ms 8676 KB Output is correct
12 Correct 1 ms 8536 KB Output is correct
13 Correct 1 ms 8540 KB Output is correct
14 Correct 1 ms 8540 KB Output is correct
15 Correct 1 ms 8540 KB Output is correct
16 Correct 1 ms 8540 KB Output is correct
17 Correct 1 ms 8540 KB Output is correct
18 Correct 1 ms 8540 KB Output is correct
19 Correct 1 ms 8540 KB Output is correct
20 Correct 1 ms 8540 KB Output is correct
21 Correct 1 ms 8540 KB Output is correct
22 Correct 1 ms 8548 KB Output is correct
23 Correct 1 ms 8540 KB Output is correct
24 Correct 1 ms 8540 KB Output is correct
25 Correct 1 ms 8540 KB Output is correct
26 Correct 1 ms 8680 KB Output is correct
27 Correct 1 ms 8540 KB Output is correct
28 Correct 1 ms 8540 KB Output is correct
29 Correct 8 ms 8552 KB Output is correct
30 Correct 9 ms 8540 KB Output is correct
31 Correct 9 ms 8760 KB Output is correct
32 Correct 10 ms 8756 KB Output is correct
33 Correct 9 ms 8748 KB Output is correct
34 Correct 9 ms 8540 KB Output is correct
35 Correct 9 ms 8540 KB Output is correct
36 Correct 10 ms 8540 KB Output is correct
37 Correct 9 ms 8764 KB Output is correct
38 Correct 9 ms 8540 KB Output is correct
39 Correct 10 ms 8756 KB Output is correct
40 Correct 9 ms 8540 KB Output is correct
41 Correct 9 ms 8668 KB Output is correct
42 Correct 9 ms 8540 KB Output is correct
43 Correct 9 ms 8540 KB Output is correct
44 Correct 10 ms 8536 KB Output is correct
45 Correct 10 ms 8764 KB Output is correct
46 Correct 10 ms 8764 KB Output is correct
47 Correct 9 ms 8748 KB Output is correct
48 Correct 9 ms 8540 KB Output is correct
49 Correct 9 ms 8540 KB Output is correct
50 Correct 9 ms 8764 KB Output is correct
51 Correct 10 ms 8700 KB Output is correct
52 Correct 10 ms 8540 KB Output is correct
53 Correct 12 ms 8760 KB Output is correct
54 Correct 11 ms 8536 KB Output is correct
55 Correct 76 ms 12052 KB Output is correct
56 Correct 97 ms 11704 KB Output is correct
57 Correct 94 ms 12088 KB Output is correct
58 Correct 76 ms 12224 KB Output is correct
59 Correct 76 ms 12856 KB Output is correct
60 Correct 72 ms 12152 KB Output is correct
61 Correct 77 ms 12220 KB Output is correct
62 Correct 99 ms 12220 KB Output is correct
63 Correct 81 ms 12756 KB Output is correct
64 Correct 94 ms 12340 KB Output is correct
65 Correct 54 ms 12136 KB Output is correct
66 Correct 68 ms 12072 KB Output is correct
67 Correct 88 ms 11968 KB Output is correct
68 Correct 100 ms 11976 KB Output is correct
69 Correct 428 ms 12152 KB Output is correct
70 Correct 424 ms 11708 KB Output is correct
71 Correct 439 ms 11960 KB Output is correct
72 Correct 428 ms 12476 KB Output is correct
73 Correct 430 ms 12336 KB Output is correct
74 Correct 491 ms 12740 KB Output is correct
75 Correct 521 ms 12656 KB Output is correct
76 Correct 498 ms 11968 KB Output is correct
77 Correct 488 ms 12356 KB Output is correct
78 Correct 487 ms 12332 KB Output is correct
79 Correct 431 ms 12040 KB Output is correct
80 Correct 502 ms 12176 KB Output is correct
81 Correct 501 ms 12440 KB Output is correct
82 Correct 522 ms 12080 KB Output is correct
83 Correct 784 ms 11196 KB Output is correct
84 Correct 1482 ms 11408 KB Output is correct
85 Correct 843 ms 10400 KB Output is correct
86 Correct 903 ms 10320 KB Output is correct
87 Correct 1798 ms 10404 KB Output is correct
88 Execution timed out 2055 ms 11352 KB Time limit exceeded
89 Halted 0 ms 0 KB -