답안 #907407

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
907407 2024-01-15T13:36:01 Z sunwukong123 Joker (BOI20_joker) C++14
100 / 100
225 ms 31060 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long 
#ifdef LOCAL
void debug_out() {cerr<<endl;}
template <typename Head, typename... Tail>
void debug_out(Head _H, Tail... _T) {cerr<<" "<<to_string(_H);debug_out(_T...);}
#define debug(...) cerr<<"["<<#__VA_ARGS__<<"]:",debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif
const int MAXN = 200005;
const int inf=1000000500ll;
const long long oo =1000000000000000500ll;
const int MOD = (int)1e9 + 7;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef pair<int,int> pi; 
int n,m,q;
pi E[MAXN];
int ans[MAXN];//suppose [1,i] is blocked, what is the minimum r such that the answer is yes?
struct ufds_{
	vector<array<int,4>> rb;
	pi par[MAXN];
	int sz[MAXN];
	bool bad=0;
	ufds_(){
		fill(sz,sz+MAXN,1);
		for(int i=0;i<MAXN;i++){
			par[i]=pi(i,0);
		}
	}
	pi find(int x){ // NO PATH COMPRESSION IN ROLLBACKS!!!
		int OFF=0;
		while(par[x].first != x){
			OFF^=par[x].second;
			x=par[x].first;
		}
		return make_pair(x,OFF);
	}
	void merge(int x, int y){
		pi px=find(x);
		pi py=find(y);
		if(px.first == py.first){//same component
			if((px.second ^ py.second)== 0){ // not bipartite!
				rb.push_back({-1,bad,0,0});
				bad=1;
				return;
			} else{
				return;
			}
		}
		if(sz[px.first]<sz[py.first]){ // sz[x]>=sz[y]
			swap(px,py);
			swap(x,y);
		}
		rb.push_back({px.first,par[px.first].first,par[px.first].second,sz[px.first]});
		sz[px.first] += sz[py.first];
		rb.push_back({py.first,par[py.first].first,par[py.first].second,sz[py.first]});
		par[py.first].first = px.first;
		par[py.first].second = 1^px.second^py.second;
	}
	void rollback(int ss){
		while(rb.size() > ss){
			array<int,4>cur=rb.back();
			if(cur[0]==-1){
				bad=cur[1];
				rb.pop_back();
			} else{
				par[cur[0]].first=cur[1];
				par[cur[0]].second=cur[2];
				sz[cur[0]]=cur[3];
				rb.pop_back();
			}
			
		}
	}
}ufds;
void dnc(int s, int e, int optl, int optr){

	if(s>e)return;
	int mi=(s+e)/2;
	// use all of [1,mi]
	int sz1=ufds.rb.size();
	for(int i=s;i<=mi;i++){
		ufds.merge(E[i].first,E[i].second);
	}
	int sz2=ufds.rb.size();
	for(int i=optr;i>=optl;i--){
		ufds.merge(E[i].first,E[i].second);
		if(ufds.bad){
			ans[mi]=i;
			break;
		}
	}
	ufds.rollback(sz2);
	dnc(mi+1,e,ans[mi],optr);
	ufds.rollback(sz1);
	int rr=ufds.rb.size();
	for(int i=optr;i>=ans[mi];i--){
		ufds.merge(E[i].first,E[i].second);
	}
	dnc(s,mi-1,optl,ans[mi]);
	ufds.rollback(rr);
}

int32_t main() 
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	cin >> n >> m >> q;

	for(int i=1;i<=m;i++){
		cin >> E[i].first >> E[i].second;
	}
	E[0].first=0;
	E[0].second=1;
	E[m+1].first=0;
	E[m+1].second=1;
	dnc(0,m,1,m+1); 
	while(q--){
		int l,r;cin>>l>>r;
		if(r<ans[l-1]){
			cout<<"YES\n";
		} else{
			cout<<"NO\n";
		}
	}
}	

Compilation message

Joker.cpp: In member function 'void ufds_::rollback(long long int)':
Joker.cpp:63:19: warning: comparison of integer expressions of different signedness: 'std::vector<std::array<long long int, 4> >::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
   63 |   while(rb.size() > ss){
      |         ~~~~~~~~~~^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 6744 KB Output is correct
2 Correct 2 ms 6748 KB Output is correct
3 Correct 2 ms 6748 KB Output is correct
4 Correct 1 ms 6748 KB Output is correct
5 Correct 2 ms 6748 KB Output is correct
6 Correct 2 ms 6760 KB Output is correct
7 Correct 2 ms 6748 KB Output is correct
8 Correct 2 ms 6748 KB Output is correct
9 Correct 2 ms 6748 KB Output is correct
10 Correct 2 ms 6748 KB Output is correct
11 Correct 2 ms 6748 KB Output is correct
12 Correct 2 ms 6748 KB Output is correct
13 Correct 2 ms 6748 KB Output is correct
14 Correct 3 ms 6748 KB Output is correct
15 Correct 2 ms 6748 KB Output is correct
16 Correct 2 ms 6748 KB Output is correct
17 Correct 2 ms 6748 KB Output is correct
18 Correct 3 ms 6748 KB Output is correct
19 Correct 2 ms 6744 KB Output is correct
20 Correct 2 ms 6748 KB Output is correct
21 Correct 2 ms 6748 KB Output is correct
22 Correct 2 ms 6804 KB Output is correct
23 Correct 2 ms 6744 KB Output is correct
24 Correct 2 ms 6588 KB Output is correct
25 Correct 2 ms 6748 KB Output is correct
26 Correct 2 ms 6748 KB Output is correct
27 Correct 2 ms 6748 KB Output is correct
28 Correct 2 ms 6748 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 6744 KB Output is correct
2 Correct 2 ms 6748 KB Output is correct
3 Correct 2 ms 6748 KB Output is correct
4 Correct 1 ms 6748 KB Output is correct
5 Correct 2 ms 6748 KB Output is correct
6 Correct 2 ms 6760 KB Output is correct
7 Correct 2 ms 6748 KB Output is correct
8 Correct 2 ms 6748 KB Output is correct
9 Correct 2 ms 6748 KB Output is correct
10 Correct 2 ms 6748 KB Output is correct
11 Correct 2 ms 6748 KB Output is correct
12 Correct 2 ms 6748 KB Output is correct
13 Correct 2 ms 6748 KB Output is correct
14 Correct 3 ms 6748 KB Output is correct
15 Correct 2 ms 6748 KB Output is correct
16 Correct 2 ms 6748 KB Output is correct
17 Correct 2 ms 6748 KB Output is correct
18 Correct 3 ms 6748 KB Output is correct
19 Correct 2 ms 6744 KB Output is correct
20 Correct 2 ms 6748 KB Output is correct
21 Correct 2 ms 6748 KB Output is correct
22 Correct 2 ms 6804 KB Output is correct
23 Correct 2 ms 6744 KB Output is correct
24 Correct 2 ms 6588 KB Output is correct
25 Correct 2 ms 6748 KB Output is correct
26 Correct 2 ms 6748 KB Output is correct
27 Correct 2 ms 6748 KB Output is correct
28 Correct 2 ms 6748 KB Output is correct
29 Correct 2 ms 6748 KB Output is correct
30 Correct 3 ms 7068 KB Output is correct
31 Correct 3 ms 7004 KB Output is correct
32 Correct 3 ms 7004 KB Output is correct
33 Correct 3 ms 6744 KB Output is correct
34 Correct 3 ms 7000 KB Output is correct
35 Correct 3 ms 7004 KB Output is correct
36 Correct 3 ms 7004 KB Output is correct
37 Correct 3 ms 7004 KB Output is correct
38 Correct 3 ms 7020 KB Output is correct
39 Correct 3 ms 7072 KB Output is correct
40 Correct 3 ms 7004 KB Output is correct
41 Correct 3 ms 7004 KB Output is correct
42 Correct 3 ms 7004 KB Output is correct
43 Correct 3 ms 6748 KB Output is correct
44 Correct 3 ms 7000 KB Output is correct
45 Correct 3 ms 7256 KB Output is correct
46 Correct 3 ms 7004 KB Output is correct
47 Correct 3 ms 6744 KB Output is correct
48 Correct 3 ms 7004 KB Output is correct
49 Correct 3 ms 7004 KB Output is correct
50 Correct 3 ms 7024 KB Output is correct
51 Correct 3 ms 6748 KB Output is correct
52 Correct 3 ms 7004 KB Output is correct
53 Correct 3 ms 7000 KB Output is correct
54 Correct 4 ms 7000 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 6744 KB Output is correct
2 Correct 2 ms 6748 KB Output is correct
3 Correct 149 ms 27956 KB Output is correct
4 Correct 166 ms 28100 KB Output is correct
5 Correct 121 ms 27584 KB Output is correct
6 Correct 141 ms 19392 KB Output is correct
7 Correct 130 ms 18428 KB Output is correct
8 Correct 135 ms 19140 KB Output is correct
9 Correct 149 ms 18356 KB Output is correct
10 Correct 219 ms 27132 KB Output is correct
11 Correct 143 ms 18384 KB Output is correct
12 Correct 168 ms 28096 KB Output is correct
13 Correct 136 ms 15056 KB Output is correct
14 Correct 139 ms 20076 KB Output is correct
15 Correct 192 ms 26888 KB Output is correct
16 Correct 197 ms 28012 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 6744 KB Output is correct
2 Correct 2 ms 6748 KB Output is correct
3 Correct 2 ms 6748 KB Output is correct
4 Correct 1 ms 6748 KB Output is correct
5 Correct 2 ms 6748 KB Output is correct
6 Correct 2 ms 6760 KB Output is correct
7 Correct 2 ms 6748 KB Output is correct
8 Correct 2 ms 6748 KB Output is correct
9 Correct 2 ms 6748 KB Output is correct
10 Correct 2 ms 6748 KB Output is correct
11 Correct 2 ms 6748 KB Output is correct
12 Correct 2 ms 6748 KB Output is correct
13 Correct 2 ms 6748 KB Output is correct
14 Correct 3 ms 6748 KB Output is correct
15 Correct 2 ms 6748 KB Output is correct
16 Correct 2 ms 6748 KB Output is correct
17 Correct 2 ms 6748 KB Output is correct
18 Correct 3 ms 6748 KB Output is correct
19 Correct 2 ms 6744 KB Output is correct
20 Correct 2 ms 6748 KB Output is correct
21 Correct 2 ms 6748 KB Output is correct
22 Correct 2 ms 6804 KB Output is correct
23 Correct 2 ms 6744 KB Output is correct
24 Correct 2 ms 6588 KB Output is correct
25 Correct 2 ms 6748 KB Output is correct
26 Correct 2 ms 6748 KB Output is correct
27 Correct 2 ms 6748 KB Output is correct
28 Correct 2 ms 6748 KB Output is correct
29 Correct 149 ms 27956 KB Output is correct
30 Correct 166 ms 28100 KB Output is correct
31 Correct 121 ms 27584 KB Output is correct
32 Correct 141 ms 19392 KB Output is correct
33 Correct 130 ms 18428 KB Output is correct
34 Correct 135 ms 19140 KB Output is correct
35 Correct 149 ms 18356 KB Output is correct
36 Correct 219 ms 27132 KB Output is correct
37 Correct 143 ms 18384 KB Output is correct
38 Correct 168 ms 28096 KB Output is correct
39 Correct 136 ms 15056 KB Output is correct
40 Correct 139 ms 20076 KB Output is correct
41 Correct 192 ms 26888 KB Output is correct
42 Correct 197 ms 28012 KB Output is correct
43 Correct 149 ms 29636 KB Output is correct
44 Correct 194 ms 29124 KB Output is correct
45 Correct 190 ms 30916 KB Output is correct
46 Correct 131 ms 22712 KB Output is correct
47 Correct 131 ms 22660 KB Output is correct
48 Correct 166 ms 21940 KB Output is correct
49 Correct 203 ms 29976 KB Output is correct
50 Correct 143 ms 22296 KB Output is correct
51 Correct 164 ms 29120 KB Output is correct
52 Correct 179 ms 30660 KB Output is correct
53 Correct 140 ms 17344 KB Output is correct
54 Correct 165 ms 22456 KB Output is correct
55 Correct 187 ms 30352 KB Output is correct
56 Correct 225 ms 29908 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 6744 KB Output is correct
2 Correct 2 ms 6748 KB Output is correct
3 Correct 2 ms 6748 KB Output is correct
4 Correct 1 ms 6748 KB Output is correct
5 Correct 2 ms 6748 KB Output is correct
6 Correct 2 ms 6760 KB Output is correct
7 Correct 2 ms 6748 KB Output is correct
8 Correct 2 ms 6748 KB Output is correct
9 Correct 2 ms 6748 KB Output is correct
10 Correct 2 ms 6748 KB Output is correct
11 Correct 2 ms 6748 KB Output is correct
12 Correct 2 ms 6748 KB Output is correct
13 Correct 2 ms 6748 KB Output is correct
14 Correct 3 ms 6748 KB Output is correct
15 Correct 2 ms 6748 KB Output is correct
16 Correct 2 ms 6748 KB Output is correct
17 Correct 2 ms 6748 KB Output is correct
18 Correct 3 ms 6748 KB Output is correct
19 Correct 2 ms 6744 KB Output is correct
20 Correct 2 ms 6748 KB Output is correct
21 Correct 2 ms 6748 KB Output is correct
22 Correct 2 ms 6804 KB Output is correct
23 Correct 2 ms 6744 KB Output is correct
24 Correct 2 ms 6588 KB Output is correct
25 Correct 2 ms 6748 KB Output is correct
26 Correct 2 ms 6748 KB Output is correct
27 Correct 2 ms 6748 KB Output is correct
28 Correct 2 ms 6748 KB Output is correct
29 Correct 2 ms 6748 KB Output is correct
30 Correct 3 ms 7068 KB Output is correct
31 Correct 3 ms 7004 KB Output is correct
32 Correct 3 ms 7004 KB Output is correct
33 Correct 3 ms 6744 KB Output is correct
34 Correct 3 ms 7000 KB Output is correct
35 Correct 3 ms 7004 KB Output is correct
36 Correct 3 ms 7004 KB Output is correct
37 Correct 3 ms 7004 KB Output is correct
38 Correct 3 ms 7020 KB Output is correct
39 Correct 3 ms 7072 KB Output is correct
40 Correct 3 ms 7004 KB Output is correct
41 Correct 3 ms 7004 KB Output is correct
42 Correct 3 ms 7004 KB Output is correct
43 Correct 3 ms 6748 KB Output is correct
44 Correct 3 ms 7000 KB Output is correct
45 Correct 3 ms 7256 KB Output is correct
46 Correct 3 ms 7004 KB Output is correct
47 Correct 3 ms 6744 KB Output is correct
48 Correct 3 ms 7004 KB Output is correct
49 Correct 3 ms 7004 KB Output is correct
50 Correct 3 ms 7024 KB Output is correct
51 Correct 3 ms 6748 KB Output is correct
52 Correct 3 ms 7004 KB Output is correct
53 Correct 3 ms 7000 KB Output is correct
54 Correct 4 ms 7000 KB Output is correct
55 Correct 126 ms 30144 KB Output is correct
56 Correct 173 ms 29532 KB Output is correct
57 Correct 94 ms 29868 KB Output is correct
58 Correct 112 ms 21744 KB Output is correct
59 Correct 136 ms 21488 KB Output is correct
60 Correct 172 ms 29120 KB Output is correct
61 Correct 136 ms 21188 KB Output is correct
62 Correct 147 ms 29888 KB Output is correct
63 Correct 109 ms 17364 KB Output is correct
64 Correct 149 ms 30400 KB Output is correct
65 Correct 178 ms 30144 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 6744 KB Output is correct
2 Correct 2 ms 6748 KB Output is correct
3 Correct 2 ms 6748 KB Output is correct
4 Correct 1 ms 6748 KB Output is correct
5 Correct 2 ms 6748 KB Output is correct
6 Correct 2 ms 6760 KB Output is correct
7 Correct 2 ms 6748 KB Output is correct
8 Correct 2 ms 6748 KB Output is correct
9 Correct 2 ms 6748 KB Output is correct
10 Correct 2 ms 6748 KB Output is correct
11 Correct 2 ms 6748 KB Output is correct
12 Correct 2 ms 6748 KB Output is correct
13 Correct 2 ms 6748 KB Output is correct
14 Correct 3 ms 6748 KB Output is correct
15 Correct 2 ms 6748 KB Output is correct
16 Correct 2 ms 6748 KB Output is correct
17 Correct 2 ms 6748 KB Output is correct
18 Correct 3 ms 6748 KB Output is correct
19 Correct 2 ms 6744 KB Output is correct
20 Correct 2 ms 6748 KB Output is correct
21 Correct 2 ms 6748 KB Output is correct
22 Correct 2 ms 6804 KB Output is correct
23 Correct 2 ms 6744 KB Output is correct
24 Correct 2 ms 6588 KB Output is correct
25 Correct 2 ms 6748 KB Output is correct
26 Correct 2 ms 6748 KB Output is correct
27 Correct 2 ms 6748 KB Output is correct
28 Correct 2 ms 6748 KB Output is correct
29 Correct 2 ms 6748 KB Output is correct
30 Correct 3 ms 7068 KB Output is correct
31 Correct 3 ms 7004 KB Output is correct
32 Correct 3 ms 7004 KB Output is correct
33 Correct 3 ms 6744 KB Output is correct
34 Correct 3 ms 7000 KB Output is correct
35 Correct 3 ms 7004 KB Output is correct
36 Correct 3 ms 7004 KB Output is correct
37 Correct 3 ms 7004 KB Output is correct
38 Correct 3 ms 7020 KB Output is correct
39 Correct 3 ms 7072 KB Output is correct
40 Correct 3 ms 7004 KB Output is correct
41 Correct 3 ms 7004 KB Output is correct
42 Correct 3 ms 7004 KB Output is correct
43 Correct 3 ms 6748 KB Output is correct
44 Correct 3 ms 7000 KB Output is correct
45 Correct 3 ms 7256 KB Output is correct
46 Correct 3 ms 7004 KB Output is correct
47 Correct 3 ms 6744 KB Output is correct
48 Correct 3 ms 7004 KB Output is correct
49 Correct 3 ms 7004 KB Output is correct
50 Correct 3 ms 7024 KB Output is correct
51 Correct 3 ms 6748 KB Output is correct
52 Correct 3 ms 7004 KB Output is correct
53 Correct 3 ms 7000 KB Output is correct
54 Correct 4 ms 7000 KB Output is correct
55 Correct 149 ms 27956 KB Output is correct
56 Correct 166 ms 28100 KB Output is correct
57 Correct 121 ms 27584 KB Output is correct
58 Correct 141 ms 19392 KB Output is correct
59 Correct 130 ms 18428 KB Output is correct
60 Correct 135 ms 19140 KB Output is correct
61 Correct 149 ms 18356 KB Output is correct
62 Correct 219 ms 27132 KB Output is correct
63 Correct 143 ms 18384 KB Output is correct
64 Correct 168 ms 28096 KB Output is correct
65 Correct 136 ms 15056 KB Output is correct
66 Correct 139 ms 20076 KB Output is correct
67 Correct 192 ms 26888 KB Output is correct
68 Correct 197 ms 28012 KB Output is correct
69 Correct 149 ms 29636 KB Output is correct
70 Correct 194 ms 29124 KB Output is correct
71 Correct 190 ms 30916 KB Output is correct
72 Correct 131 ms 22712 KB Output is correct
73 Correct 131 ms 22660 KB Output is correct
74 Correct 166 ms 21940 KB Output is correct
75 Correct 203 ms 29976 KB Output is correct
76 Correct 143 ms 22296 KB Output is correct
77 Correct 164 ms 29120 KB Output is correct
78 Correct 179 ms 30660 KB Output is correct
79 Correct 140 ms 17344 KB Output is correct
80 Correct 165 ms 22456 KB Output is correct
81 Correct 187 ms 30352 KB Output is correct
82 Correct 225 ms 29908 KB Output is correct
83 Correct 126 ms 30144 KB Output is correct
84 Correct 173 ms 29532 KB Output is correct
85 Correct 94 ms 29868 KB Output is correct
86 Correct 112 ms 21744 KB Output is correct
87 Correct 136 ms 21488 KB Output is correct
88 Correct 172 ms 29120 KB Output is correct
89 Correct 136 ms 21188 KB Output is correct
90 Correct 147 ms 29888 KB Output is correct
91 Correct 109 ms 17364 KB Output is correct
92 Correct 149 ms 30400 KB Output is correct
93 Correct 178 ms 30144 KB Output is correct
94 Correct 150 ms 30916 KB Output is correct
95 Correct 177 ms 29832 KB Output is correct
96 Correct 137 ms 31060 KB Output is correct
97 Correct 138 ms 23292 KB Output is correct
98 Correct 148 ms 23388 KB Output is correct
99 Correct 156 ms 21704 KB Output is correct
100 Correct 210 ms 29120 KB Output is correct
101 Correct 147 ms 23228 KB Output is correct
102 Correct 171 ms 30408 KB Output is correct
103 Correct 194 ms 30144 KB Output is correct
104 Correct 148 ms 19544 KB Output is correct
105 Correct 185 ms 30916 KB Output is correct
106 Correct 202 ms 29160 KB Output is correct
107 Correct 130 ms 30148 KB Output is correct
108 Correct 144 ms 29676 KB Output is correct
109 Correct 145 ms 30404 KB Output is correct
110 Correct 150 ms 30548 KB Output is correct
111 Correct 146 ms 29888 KB Output is correct
112 Correct 151 ms 30404 KB Output is correct
113 Correct 150 ms 29184 KB Output is correct
114 Correct 149 ms 30412 KB Output is correct
115 Correct 146 ms 29892 KB Output is correct
116 Correct 143 ms 29380 KB Output is correct