Submission #962052

# Submission time Handle Problem Language Result Execution time Memory
962052 2024-04-13T05:48:08 Z pcc Joker (BOI20_joker) C++17
100 / 100
408 ms 37324 KB
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define pll pair<ll,ll>
#define pii pair<int,int>
#define fs first
#define sc second
#define tlll tuple<ll,ll,ll>
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,popcnt,sse4")

const int mxn = 4e5+30;
int N,M,Q;

struct DSU{
	vector<pii> sop,dop;
	vector<int> cop;
	bool cyc;
	int dsu[mxn],sz[mxn];
	void init(int n){
		cyc = false;
		for(int i = 0;i<=n;i++)dsu[i] = i,sz[i] = 1;
	}
	int root(int k){
		return k == dsu[k]?k:root(dsu[k]);
	}
	void onion(int a,int b){
		 a = root(a),b = root(b);
		 if(a == b){
			 sop.push_back(pii(0,0));
			 dop.push_back(pii(0,0));
			 return;
		 }
		 if(sz[a]<sz[b])swap(a,b);
		 sop.push_back(pii(a,sz[a]));
		 dop.push_back(pii(b,b));
		 dsu[b] = a;
		 sz[a] += sz[b];
		 return;
	}
	void roll(){
		for(int i = 0;i<2;i++){
		{
			auto [a,b] = sop.back();sop.pop_back();
			sz[a] = b;
		}{
			auto [a,b] = dop.back();dop.pop_back();
			dsu[a] = b;
		}{
			auto a = cop.back();cop.pop_back();
			cyc = a;
		}}
		return;
	}
	void add_edge(int a,int b){
		onion(a,b+N);
		onion(b,a+N);
		cop.push_back(cyc);
		if(root(a) == root(a+N))cyc = true;
		cop.push_back(cyc);
		if(root(b) == root(b+N))cyc = true;
		assert(cop.size() == dop.size());
		return;
	}
};

DSU dsu;
pii edges[mxn];
pii req[mxn];
int rp[mxn];

void dc(int l,int r,int sl,int sr){
	//cerr<<l<<' '<<r<<':'<<sl<<' '<<sr<<endl;
	if(l == r){
		for(int i = sl;i<=sr;i++){
			rp[i] = l;
		}
		return;
	}
	int mid = (l+r)>>1;
	bool f = false;
	for(int i = r;i>mid;i--)dsu.add_edge(edges[i].fs,edges[i].sc);
	//cerr<<l<<' '<<mid<<' '<<r<<":"<<sl<<' '<<sr<<','<<dsu.cyc<<endl;
	//for(int i = 1;i<=N;i++)cerr<<dsu.root(i)<<' ';cerr<<endl;
	if(dsu.cyc){
		for(int i = r;i>mid;i--)dsu.roll();
		dc(mid+1,r,sl,sr);
		return;
	}
	int opt = sr+1;
	for(int i = sl;i<=sr;i++){
		dsu.add_edge(edges[i].fs,edges[i].sc);
		if(dsu.cyc){
			opt = i;
			break;
		}
	}
	for(int i = sl;i<=min(opt,sr);i++){
		dsu.roll();
	}
	if(sl != opt)dc(l,mid,sl,opt-1);
	for(int i = r;i>mid;i--){
		dsu.roll();
	}
	for(int i = sl;i<opt;i++){
		auto [a,b] = edges[i];
		dsu.add_edge(a,b);
	}
	if(sr>=opt)dc(mid+1,r,opt,sr);
	for(int i = sl;i<opt;i++){
		dsu.roll();
	}
	return;
}


int main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin>>N>>M>>Q;
	for(int i = 1;i<=M;i++)cin>>edges[i].fs>>edges[i].sc;
	for(int i = 1;i<=Q;i++)cin>>req[i].fs>>req[i].sc;
	edges[M+2] = edges[0] = edges[M+1] = pii(N+1,N+2);
	N += 2;
	dsu.init(N*2+10);

	dc(0,M+1,0,M);
	//for(int i = 0;i<=M;i++)cerr<<rp[i]<<' ';cerr<<endl;
	for(int i = 1;i<=Q;i++){
		auto [s,e] = req[i];
		if(rp[s-1]>=e+1)cout<<"YES\n";
		else cout<<"NO\n";
	}
	return 0;
}

Compilation message

Joker.cpp: In function 'void dc(int, int, int, int)':
Joker.cpp:82:7: warning: unused variable 'f' [-Wunused-variable]
   82 |  bool f = false;
      |       ^
# Verdict Execution time Memory Grader output
1 Correct 1 ms 8536 KB Output is correct
2 Correct 2 ms 8540 KB Output is correct
3 Correct 1 ms 8540 KB Output is correct
4 Correct 2 ms 8540 KB Output is correct
5 Correct 1 ms 8540 KB Output is correct
6 Correct 1 ms 8536 KB Output is correct
7 Correct 1 ms 8540 KB Output is correct
8 Correct 2 ms 8540 KB Output is correct
9 Correct 1 ms 8540 KB Output is correct
10 Correct 1 ms 8540 KB Output is correct
11 Correct 1 ms 8592 KB Output is correct
12 Correct 2 ms 8540 KB Output is correct
13 Correct 1 ms 8540 KB Output is correct
14 Correct 2 ms 8536 KB Output is correct
15 Correct 2 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 2 ms 8540 KB Output is correct
19 Correct 1 ms 8620 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 8536 KB Output is correct
23 Correct 1 ms 8540 KB Output is correct
24 Correct 1 ms 8540 KB Output is correct
25 Correct 2 ms 8540 KB Output is correct
26 Correct 1 ms 8540 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 8536 KB Output is correct
2 Correct 2 ms 8540 KB Output is correct
3 Correct 1 ms 8540 KB Output is correct
4 Correct 2 ms 8540 KB Output is correct
5 Correct 1 ms 8540 KB Output is correct
6 Correct 1 ms 8536 KB Output is correct
7 Correct 1 ms 8540 KB Output is correct
8 Correct 2 ms 8540 KB Output is correct
9 Correct 1 ms 8540 KB Output is correct
10 Correct 1 ms 8540 KB Output is correct
11 Correct 1 ms 8592 KB Output is correct
12 Correct 2 ms 8540 KB Output is correct
13 Correct 1 ms 8540 KB Output is correct
14 Correct 2 ms 8536 KB Output is correct
15 Correct 2 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 2 ms 8540 KB Output is correct
19 Correct 1 ms 8620 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 8536 KB Output is correct
23 Correct 1 ms 8540 KB Output is correct
24 Correct 1 ms 8540 KB Output is correct
25 Correct 2 ms 8540 KB Output is correct
26 Correct 1 ms 8540 KB Output is correct
27 Correct 1 ms 8540 KB Output is correct
28 Correct 1 ms 8540 KB Output is correct
29 Correct 2 ms 8796 KB Output is correct
30 Correct 2 ms 8796 KB Output is correct
31 Correct 2 ms 8540 KB Output is correct
32 Correct 2 ms 8540 KB Output is correct
33 Correct 2 ms 8540 KB Output is correct
34 Correct 2 ms 8800 KB Output is correct
35 Correct 3 ms 8796 KB Output is correct
36 Correct 3 ms 8796 KB Output is correct
37 Correct 2 ms 8796 KB Output is correct
38 Correct 3 ms 8796 KB Output is correct
39 Correct 2 ms 8740 KB Output is correct
40 Correct 2 ms 8796 KB Output is correct
41 Correct 2 ms 8796 KB Output is correct
42 Correct 2 ms 8792 KB Output is correct
43 Correct 2 ms 8796 KB Output is correct
44 Correct 2 ms 8792 KB Output is correct
45 Correct 2 ms 8792 KB Output is correct
46 Correct 3 ms 8796 KB Output is correct
47 Correct 2 ms 8796 KB Output is correct
48 Correct 3 ms 8792 KB Output is correct
49 Correct 3 ms 8796 KB Output is correct
50 Correct 3 ms 8676 KB Output is correct
51 Correct 3 ms 8796 KB Output is correct
52 Correct 2 ms 8796 KB Output is correct
53 Correct 2 ms 8796 KB Output is correct
54 Correct 3 ms 8796 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 8536 KB Output is correct
2 Correct 2 ms 8540 KB Output is correct
3 Correct 150 ms 21664 KB Output is correct
4 Correct 374 ms 34248 KB Output is correct
5 Correct 108 ms 23540 KB Output is correct
6 Correct 115 ms 22348 KB Output is correct
7 Correct 125 ms 21116 KB Output is correct
8 Correct 138 ms 21844 KB Output is correct
9 Correct 168 ms 22192 KB Output is correct
10 Correct 195 ms 20480 KB Output is correct
11 Correct 144 ms 22384 KB Output is correct
12 Correct 155 ms 22004 KB Output is correct
13 Correct 119 ms 22056 KB Output is correct
14 Correct 128 ms 21124 KB Output is correct
15 Correct 168 ms 22132 KB Output is correct
16 Correct 206 ms 23448 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 8536 KB Output is correct
2 Correct 2 ms 8540 KB Output is correct
3 Correct 1 ms 8540 KB Output is correct
4 Correct 2 ms 8540 KB Output is correct
5 Correct 1 ms 8540 KB Output is correct
6 Correct 1 ms 8536 KB Output is correct
7 Correct 1 ms 8540 KB Output is correct
8 Correct 2 ms 8540 KB Output is correct
9 Correct 1 ms 8540 KB Output is correct
10 Correct 1 ms 8540 KB Output is correct
11 Correct 1 ms 8592 KB Output is correct
12 Correct 2 ms 8540 KB Output is correct
13 Correct 1 ms 8540 KB Output is correct
14 Correct 2 ms 8536 KB Output is correct
15 Correct 2 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 2 ms 8540 KB Output is correct
19 Correct 1 ms 8620 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 8536 KB Output is correct
23 Correct 1 ms 8540 KB Output is correct
24 Correct 1 ms 8540 KB Output is correct
25 Correct 2 ms 8540 KB Output is correct
26 Correct 1 ms 8540 KB Output is correct
27 Correct 1 ms 8540 KB Output is correct
28 Correct 1 ms 8540 KB Output is correct
29 Correct 150 ms 21664 KB Output is correct
30 Correct 374 ms 34248 KB Output is correct
31 Correct 108 ms 23540 KB Output is correct
32 Correct 115 ms 22348 KB Output is correct
33 Correct 125 ms 21116 KB Output is correct
34 Correct 138 ms 21844 KB Output is correct
35 Correct 168 ms 22192 KB Output is correct
36 Correct 195 ms 20480 KB Output is correct
37 Correct 144 ms 22384 KB Output is correct
38 Correct 155 ms 22004 KB Output is correct
39 Correct 119 ms 22056 KB Output is correct
40 Correct 128 ms 21124 KB Output is correct
41 Correct 168 ms 22132 KB Output is correct
42 Correct 206 ms 23448 KB Output is correct
43 Correct 159 ms 24912 KB Output is correct
44 Correct 408 ms 37324 KB Output is correct
45 Correct 133 ms 27732 KB Output is correct
46 Correct 107 ms 25864 KB Output is correct
47 Correct 128 ms 27112 KB Output is correct
48 Correct 170 ms 25040 KB Output is correct
49 Correct 202 ms 24508 KB Output is correct
50 Correct 129 ms 26848 KB Output is correct
51 Correct 141 ms 26612 KB Output is correct
52 Correct 154 ms 27356 KB Output is correct
53 Correct 113 ms 23900 KB Output is correct
54 Correct 150 ms 24416 KB Output is correct
55 Correct 178 ms 27116 KB Output is correct
56 Correct 191 ms 26536 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 8536 KB Output is correct
2 Correct 2 ms 8540 KB Output is correct
3 Correct 1 ms 8540 KB Output is correct
4 Correct 2 ms 8540 KB Output is correct
5 Correct 1 ms 8540 KB Output is correct
6 Correct 1 ms 8536 KB Output is correct
7 Correct 1 ms 8540 KB Output is correct
8 Correct 2 ms 8540 KB Output is correct
9 Correct 1 ms 8540 KB Output is correct
10 Correct 1 ms 8540 KB Output is correct
11 Correct 1 ms 8592 KB Output is correct
12 Correct 2 ms 8540 KB Output is correct
13 Correct 1 ms 8540 KB Output is correct
14 Correct 2 ms 8536 KB Output is correct
15 Correct 2 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 2 ms 8540 KB Output is correct
19 Correct 1 ms 8620 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 8536 KB Output is correct
23 Correct 1 ms 8540 KB Output is correct
24 Correct 1 ms 8540 KB Output is correct
25 Correct 2 ms 8540 KB Output is correct
26 Correct 1 ms 8540 KB Output is correct
27 Correct 1 ms 8540 KB Output is correct
28 Correct 1 ms 8540 KB Output is correct
29 Correct 2 ms 8796 KB Output is correct
30 Correct 2 ms 8796 KB Output is correct
31 Correct 2 ms 8540 KB Output is correct
32 Correct 2 ms 8540 KB Output is correct
33 Correct 2 ms 8540 KB Output is correct
34 Correct 2 ms 8800 KB Output is correct
35 Correct 3 ms 8796 KB Output is correct
36 Correct 3 ms 8796 KB Output is correct
37 Correct 2 ms 8796 KB Output is correct
38 Correct 3 ms 8796 KB Output is correct
39 Correct 2 ms 8740 KB Output is correct
40 Correct 2 ms 8796 KB Output is correct
41 Correct 2 ms 8796 KB Output is correct
42 Correct 2 ms 8792 KB Output is correct
43 Correct 2 ms 8796 KB Output is correct
44 Correct 2 ms 8792 KB Output is correct
45 Correct 2 ms 8792 KB Output is correct
46 Correct 3 ms 8796 KB Output is correct
47 Correct 2 ms 8796 KB Output is correct
48 Correct 3 ms 8792 KB Output is correct
49 Correct 3 ms 8796 KB Output is correct
50 Correct 3 ms 8676 KB Output is correct
51 Correct 3 ms 8796 KB Output is correct
52 Correct 2 ms 8796 KB Output is correct
53 Correct 2 ms 8796 KB Output is correct
54 Correct 3 ms 8796 KB Output is correct
55 Correct 127 ms 20136 KB Output is correct
56 Correct 286 ms 34004 KB Output is correct
57 Correct 71 ms 23756 KB Output is correct
58 Correct 89 ms 21212 KB Output is correct
59 Correct 142 ms 20584 KB Output is correct
60 Correct 163 ms 20192 KB Output is correct
61 Correct 110 ms 19700 KB Output is correct
62 Correct 127 ms 23028 KB Output is correct
63 Correct 94 ms 19680 KB Output is correct
64 Correct 138 ms 20528 KB Output is correct
65 Correct 164 ms 23272 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 8536 KB Output is correct
2 Correct 2 ms 8540 KB Output is correct
3 Correct 1 ms 8540 KB Output is correct
4 Correct 2 ms 8540 KB Output is correct
5 Correct 1 ms 8540 KB Output is correct
6 Correct 1 ms 8536 KB Output is correct
7 Correct 1 ms 8540 KB Output is correct
8 Correct 2 ms 8540 KB Output is correct
9 Correct 1 ms 8540 KB Output is correct
10 Correct 1 ms 8540 KB Output is correct
11 Correct 1 ms 8592 KB Output is correct
12 Correct 2 ms 8540 KB Output is correct
13 Correct 1 ms 8540 KB Output is correct
14 Correct 2 ms 8536 KB Output is correct
15 Correct 2 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 2 ms 8540 KB Output is correct
19 Correct 1 ms 8620 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 8536 KB Output is correct
23 Correct 1 ms 8540 KB Output is correct
24 Correct 1 ms 8540 KB Output is correct
25 Correct 2 ms 8540 KB Output is correct
26 Correct 1 ms 8540 KB Output is correct
27 Correct 1 ms 8540 KB Output is correct
28 Correct 1 ms 8540 KB Output is correct
29 Correct 2 ms 8796 KB Output is correct
30 Correct 2 ms 8796 KB Output is correct
31 Correct 2 ms 8540 KB Output is correct
32 Correct 2 ms 8540 KB Output is correct
33 Correct 2 ms 8540 KB Output is correct
34 Correct 2 ms 8800 KB Output is correct
35 Correct 3 ms 8796 KB Output is correct
36 Correct 3 ms 8796 KB Output is correct
37 Correct 2 ms 8796 KB Output is correct
38 Correct 3 ms 8796 KB Output is correct
39 Correct 2 ms 8740 KB Output is correct
40 Correct 2 ms 8796 KB Output is correct
41 Correct 2 ms 8796 KB Output is correct
42 Correct 2 ms 8792 KB Output is correct
43 Correct 2 ms 8796 KB Output is correct
44 Correct 2 ms 8792 KB Output is correct
45 Correct 2 ms 8792 KB Output is correct
46 Correct 3 ms 8796 KB Output is correct
47 Correct 2 ms 8796 KB Output is correct
48 Correct 3 ms 8792 KB Output is correct
49 Correct 3 ms 8796 KB Output is correct
50 Correct 3 ms 8676 KB Output is correct
51 Correct 3 ms 8796 KB Output is correct
52 Correct 2 ms 8796 KB Output is correct
53 Correct 2 ms 8796 KB Output is correct
54 Correct 3 ms 8796 KB Output is correct
55 Correct 150 ms 21664 KB Output is correct
56 Correct 374 ms 34248 KB Output is correct
57 Correct 108 ms 23540 KB Output is correct
58 Correct 115 ms 22348 KB Output is correct
59 Correct 125 ms 21116 KB Output is correct
60 Correct 138 ms 21844 KB Output is correct
61 Correct 168 ms 22192 KB Output is correct
62 Correct 195 ms 20480 KB Output is correct
63 Correct 144 ms 22384 KB Output is correct
64 Correct 155 ms 22004 KB Output is correct
65 Correct 119 ms 22056 KB Output is correct
66 Correct 128 ms 21124 KB Output is correct
67 Correct 168 ms 22132 KB Output is correct
68 Correct 206 ms 23448 KB Output is correct
69 Correct 159 ms 24912 KB Output is correct
70 Correct 408 ms 37324 KB Output is correct
71 Correct 133 ms 27732 KB Output is correct
72 Correct 107 ms 25864 KB Output is correct
73 Correct 128 ms 27112 KB Output is correct
74 Correct 170 ms 25040 KB Output is correct
75 Correct 202 ms 24508 KB Output is correct
76 Correct 129 ms 26848 KB Output is correct
77 Correct 141 ms 26612 KB Output is correct
78 Correct 154 ms 27356 KB Output is correct
79 Correct 113 ms 23900 KB Output is correct
80 Correct 150 ms 24416 KB Output is correct
81 Correct 178 ms 27116 KB Output is correct
82 Correct 191 ms 26536 KB Output is correct
83 Correct 127 ms 20136 KB Output is correct
84 Correct 286 ms 34004 KB Output is correct
85 Correct 71 ms 23756 KB Output is correct
86 Correct 89 ms 21212 KB Output is correct
87 Correct 142 ms 20584 KB Output is correct
88 Correct 163 ms 20192 KB Output is correct
89 Correct 110 ms 19700 KB Output is correct
90 Correct 127 ms 23028 KB Output is correct
91 Correct 94 ms 19680 KB Output is correct
92 Correct 138 ms 20528 KB Output is correct
93 Correct 164 ms 23272 KB Output is correct
94 Correct 142 ms 25068 KB Output is correct
95 Correct 188 ms 26936 KB Output is correct
96 Correct 106 ms 26092 KB Output is correct
97 Correct 131 ms 27764 KB Output is correct
98 Correct 121 ms 27992 KB Output is correct
99 Correct 133 ms 27100 KB Output is correct
100 Correct 210 ms 27020 KB Output is correct
101 Correct 145 ms 26924 KB Output is correct
102 Correct 154 ms 27376 KB Output is correct
103 Correct 169 ms 27068 KB Output is correct
104 Correct 119 ms 24288 KB Output is correct
105 Correct 178 ms 26724 KB Output is correct
106 Correct 230 ms 28160 KB Output is correct
107 Correct 85 ms 27364 KB Output is correct
108 Correct 154 ms 24672 KB Output is correct
109 Correct 153 ms 26868 KB Output is correct
110 Correct 153 ms 24288 KB Output is correct
111 Correct 145 ms 24304 KB Output is correct
112 Correct 148 ms 25468 KB Output is correct
113 Correct 157 ms 25840 KB Output is correct
114 Correct 156 ms 26100 KB Output is correct
115 Correct 151 ms 24052 KB Output is correct
116 Correct 150 ms 24576 KB Output is correct