Submission #957002

# Submission time Handle Problem Language Result Execution time Memory
957002 2024-04-02T19:19:45 Z Rawlat_vanak Joker (BOI20_joker) C++17
100 / 100
343 ms 25532 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define speedIO ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define mod 1000000007
#define f first
#define s second

int poww(int a,int n){
	if(n==0) return 1;
	int b=poww(a,n/2);
	b=b*b;
	if(n%2==1) b*=a;
	return b;
}

struct changes{
	int u,v,sz,parity,idx;bool prev;
	changes(int _u,int _v,int _sz,int _parity,int _idx, bool _prev): u(_u), v(_v), sz(_sz),idx(_idx), parity(_parity), prev(_prev){}
};
	
vector<pair<int,int>> parent;
vector<pair<int,int>> edges;
vector<int> rk;
stack<changes> roll;
bool curr;
int n,m;

pair<int,int> find(int v){
	if(v==parent[v].f) return {parent[v].f,parent[v].s};
	pair<int,int> x=find(parent[v].f);
	return {x.f,x.s^parent[v].s};
}

void back(){
	if(roll.empty()) return;
	int u=roll.top().u;
	int v=roll.top().v;
	int sz=roll.top().sz;
	int parity=roll.top().parity;
	bool prev=roll.top().prev;
	roll.pop();
	parent[v].f=v;
	parent[v].s=parity;
	rk[u]=sz;
	curr=prev;
	return;
}

void merge(int e){
	int u=edges[e].f;int v=edges[e].s;
	auto x=find(u);
	auto y=find(v);
	u=x.f;v=y.f;
	int du=x.s;int dv=y.s;
	if(rk[u]<rk[v]) swap(u,v);
	bool prev=curr;
	int prprppr=parent[v].s;
	if(u==v){
		if(du^dv^1) curr=false;
	}else{
		parent[v].f=u;
		rk[u]+=rk[v];
		parent[v].s=du^dv^1;
	}
	roll.push({u,v,rk[u],prprppr,e,prev});
	return;
}

void rangeback(int l, int r){
	if(l>r) return;
	stack<changes> tmp;
	vector<bool> found(r-l+1,false);
	for(int i=l;i<=r;i++){
		if(roll.empty()) continue;
		if(found[i-l]) continue;
		while(roll.top().idx!=i){
			if(roll.top().idx<=r and roll.top().idx>=l){
				found[roll.top().idx-l]=true;
			}else{
				tmp.push(roll.top());
			}
			back();
		}
		found[i-l]=true;
		back();
	}
	while(!tmp.empty()){
		merge(tmp.top().idx);
		tmp.pop();
	}
}


vector<int> opt;
bool allbipar;

void calculate(int l,int r,int optl,int optr){
	if(l>r) return;
	int mid=(l+r)/2;
	for(int i=l;i<mid;i++) merge(i);//mid-1,optr+1

	for(int i=optr;i>=max(mid,optl);i--){
		if(curr==false) {opt[mid]=i;break;}
		merge(i);
	}
	if(opt[mid]==0) opt[mid]=mid-1;


	rangeback(opt[mid]+1,optr);
	merge(mid);
	calculate(mid+1,r,opt[mid],optr);

	rangeback(l,mid);
	for(int i=opt[mid]+1;i<=optr;i++) merge(i);
	calculate(l,mid-1,optl,opt[mid]);

	rangeback(opt[mid]+1,optr);
	return;

}

int32_t main(){
	speedIO;
	int t,q;
	//cin>>t;
	//t=1;
	///while(t--){
		cin>>n>>m>>q;
		parent.clear();parent.resize(n+5);
		rk.clear();rk.resize(n+5,1);
		opt.clear();opt.resize(m+5,0);
		edges.clear();edges.resize(m+5);
		curr=true;
		for(int i=0;i<n+5;i++){
			parent[i].f=i;parent[i].s=0;
		}
		for(int i=1;i<=m;i++){
			int a,b;
			cin>>a>>b;
			edges[i]={a,b};
		}
		edges[m+1]={n+1,n+2};edges[0]={n+3,n+4};
		allbipar=false;
		calculate(1,m,0,m+1);


		for(int i=0;i<q;i++){
			int l,r;
			cin>>l>>r;
			if(r<=opt[l]){
				cout<<"YES"<<'\n';
			}else{
				cout<<"NO"<<'\n';
			}
		}
		

		

	//}
	return 0;
}

Compilation message

Joker.cpp: In constructor 'changes::changes(long long int, long long int, long long int, long long int, long long int, bool)':
Joker.cpp:18:20: warning: 'changes::idx' will be initialized after [-Wreorder]
   18 |  int u,v,sz,parity,idx;bool prev;
      |                    ^~~
Joker.cpp:18:13: warning:   'long long int changes::parity' [-Wreorder]
   18 |  int u,v,sz,parity,idx;bool prev;
      |             ^~~~~~
Joker.cpp:19:2: warning:   when initialized here [-Wreorder]
   19 |  changes(int _u,int _v,int _sz,int _parity,int _idx, bool _prev): u(_u), v(_v), sz(_sz),idx(_idx), parity(_parity), prev(_prev){}
      |  ^~~~~~~
Joker.cpp: In function 'int32_t main()':
Joker.cpp:125:6: warning: unused variable 't' [-Wunused-variable]
  125 |  int t,q;
      |      ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 456 KB Output is correct
7 Correct 1 ms 352 KB Output is correct
8 Correct 1 ms 360 KB Output is correct
9 Correct 1 ms 352 KB Output is correct
10 Correct 0 ms 356 KB Output is correct
11 Correct 0 ms 352 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 360 KB Output is correct
14 Correct 1 ms 360 KB Output is correct
15 Correct 1 ms 360 KB Output is correct
16 Correct 1 ms 356 KB Output is correct
17 Correct 0 ms 360 KB Output is correct
18 Correct 1 ms 360 KB Output is correct
19 Correct 1 ms 360 KB Output is correct
20 Correct 1 ms 360 KB Output is correct
21 Correct 1 ms 360 KB Output is correct
22 Correct 1 ms 360 KB Output is correct
23 Correct 0 ms 360 KB Output is correct
24 Correct 1 ms 360 KB Output is correct
25 Correct 1 ms 360 KB Output is correct
26 Correct 1 ms 616 KB Output is correct
27 Correct 1 ms 360 KB Output is correct
28 Correct 0 ms 360 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 456 KB Output is correct
7 Correct 1 ms 352 KB Output is correct
8 Correct 1 ms 360 KB Output is correct
9 Correct 1 ms 352 KB Output is correct
10 Correct 0 ms 356 KB Output is correct
11 Correct 0 ms 352 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 360 KB Output is correct
14 Correct 1 ms 360 KB Output is correct
15 Correct 1 ms 360 KB Output is correct
16 Correct 1 ms 356 KB Output is correct
17 Correct 0 ms 360 KB Output is correct
18 Correct 1 ms 360 KB Output is correct
19 Correct 1 ms 360 KB Output is correct
20 Correct 1 ms 360 KB Output is correct
21 Correct 1 ms 360 KB Output is correct
22 Correct 1 ms 360 KB Output is correct
23 Correct 0 ms 360 KB Output is correct
24 Correct 1 ms 360 KB Output is correct
25 Correct 1 ms 360 KB Output is correct
26 Correct 1 ms 616 KB Output is correct
27 Correct 1 ms 360 KB Output is correct
28 Correct 0 ms 360 KB Output is correct
29 Correct 2 ms 616 KB Output is correct
30 Correct 2 ms 616 KB Output is correct
31 Correct 2 ms 612 KB Output is correct
32 Correct 2 ms 468 KB Output is correct
33 Correct 2 ms 616 KB Output is correct
34 Correct 2 ms 480 KB Output is correct
35 Correct 2 ms 616 KB Output is correct
36 Correct 2 ms 616 KB Output is correct
37 Correct 2 ms 604 KB Output is correct
38 Correct 2 ms 604 KB Output is correct
39 Correct 2 ms 604 KB Output is correct
40 Correct 2 ms 604 KB Output is correct
41 Correct 2 ms 616 KB Output is correct
42 Correct 2 ms 616 KB Output is correct
43 Correct 2 ms 624 KB Output is correct
44 Correct 2 ms 616 KB Output is correct
45 Correct 2 ms 616 KB Output is correct
46 Correct 2 ms 616 KB Output is correct
47 Correct 3 ms 616 KB Output is correct
48 Correct 3 ms 616 KB Output is correct
49 Correct 3 ms 616 KB Output is correct
50 Correct 2 ms 616 KB Output is correct
51 Correct 2 ms 616 KB Output is correct
52 Correct 2 ms 616 KB Output is correct
53 Correct 2 ms 616 KB Output is correct
54 Correct 3 ms 616 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 203 ms 21984 KB Output is correct
4 Correct 295 ms 23708 KB Output is correct
5 Correct 155 ms 23904 KB Output is correct
6 Correct 167 ms 21768 KB Output is correct
7 Correct 178 ms 21976 KB Output is correct
8 Correct 204 ms 20452 KB Output is correct
9 Correct 206 ms 21468 KB Output is correct
10 Correct 262 ms 24176 KB Output is correct
11 Correct 228 ms 21712 KB Output is correct
12 Correct 234 ms 23968 KB Output is correct
13 Correct 223 ms 19836 KB Output is correct
14 Correct 193 ms 20884 KB Output is correct
15 Correct 260 ms 22912 KB Output is correct
16 Correct 285 ms 24328 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 456 KB Output is correct
7 Correct 1 ms 352 KB Output is correct
8 Correct 1 ms 360 KB Output is correct
9 Correct 1 ms 352 KB Output is correct
10 Correct 0 ms 356 KB Output is correct
11 Correct 0 ms 352 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 360 KB Output is correct
14 Correct 1 ms 360 KB Output is correct
15 Correct 1 ms 360 KB Output is correct
16 Correct 1 ms 356 KB Output is correct
17 Correct 0 ms 360 KB Output is correct
18 Correct 1 ms 360 KB Output is correct
19 Correct 1 ms 360 KB Output is correct
20 Correct 1 ms 360 KB Output is correct
21 Correct 1 ms 360 KB Output is correct
22 Correct 1 ms 360 KB Output is correct
23 Correct 0 ms 360 KB Output is correct
24 Correct 1 ms 360 KB Output is correct
25 Correct 1 ms 360 KB Output is correct
26 Correct 1 ms 616 KB Output is correct
27 Correct 1 ms 360 KB Output is correct
28 Correct 0 ms 360 KB Output is correct
29 Correct 203 ms 21984 KB Output is correct
30 Correct 295 ms 23708 KB Output is correct
31 Correct 155 ms 23904 KB Output is correct
32 Correct 167 ms 21768 KB Output is correct
33 Correct 178 ms 21976 KB Output is correct
34 Correct 204 ms 20452 KB Output is correct
35 Correct 206 ms 21468 KB Output is correct
36 Correct 262 ms 24176 KB Output is correct
37 Correct 228 ms 21712 KB Output is correct
38 Correct 234 ms 23968 KB Output is correct
39 Correct 223 ms 19836 KB Output is correct
40 Correct 193 ms 20884 KB Output is correct
41 Correct 260 ms 22912 KB Output is correct
42 Correct 285 ms 24328 KB Output is correct
43 Correct 186 ms 22100 KB Output is correct
44 Correct 343 ms 24208 KB Output is correct
45 Correct 303 ms 24728 KB Output is correct
46 Correct 225 ms 22228 KB Output is correct
47 Correct 179 ms 22244 KB Output is correct
48 Correct 237 ms 21856 KB Output is correct
49 Correct 277 ms 24544 KB Output is correct
50 Correct 218 ms 21748 KB Output is correct
51 Correct 249 ms 23328 KB Output is correct
52 Correct 233 ms 24708 KB Output is correct
53 Correct 219 ms 20104 KB Output is correct
54 Correct 302 ms 21760 KB Output is correct
55 Correct 243 ms 23160 KB Output is correct
56 Correct 303 ms 24708 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 456 KB Output is correct
7 Correct 1 ms 352 KB Output is correct
8 Correct 1 ms 360 KB Output is correct
9 Correct 1 ms 352 KB Output is correct
10 Correct 0 ms 356 KB Output is correct
11 Correct 0 ms 352 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 360 KB Output is correct
14 Correct 1 ms 360 KB Output is correct
15 Correct 1 ms 360 KB Output is correct
16 Correct 1 ms 356 KB Output is correct
17 Correct 0 ms 360 KB Output is correct
18 Correct 1 ms 360 KB Output is correct
19 Correct 1 ms 360 KB Output is correct
20 Correct 1 ms 360 KB Output is correct
21 Correct 1 ms 360 KB Output is correct
22 Correct 1 ms 360 KB Output is correct
23 Correct 0 ms 360 KB Output is correct
24 Correct 1 ms 360 KB Output is correct
25 Correct 1 ms 360 KB Output is correct
26 Correct 1 ms 616 KB Output is correct
27 Correct 1 ms 360 KB Output is correct
28 Correct 0 ms 360 KB Output is correct
29 Correct 2 ms 616 KB Output is correct
30 Correct 2 ms 616 KB Output is correct
31 Correct 2 ms 612 KB Output is correct
32 Correct 2 ms 468 KB Output is correct
33 Correct 2 ms 616 KB Output is correct
34 Correct 2 ms 480 KB Output is correct
35 Correct 2 ms 616 KB Output is correct
36 Correct 2 ms 616 KB Output is correct
37 Correct 2 ms 604 KB Output is correct
38 Correct 2 ms 604 KB Output is correct
39 Correct 2 ms 604 KB Output is correct
40 Correct 2 ms 604 KB Output is correct
41 Correct 2 ms 616 KB Output is correct
42 Correct 2 ms 616 KB Output is correct
43 Correct 2 ms 624 KB Output is correct
44 Correct 2 ms 616 KB Output is correct
45 Correct 2 ms 616 KB Output is correct
46 Correct 2 ms 616 KB Output is correct
47 Correct 3 ms 616 KB Output is correct
48 Correct 3 ms 616 KB Output is correct
49 Correct 3 ms 616 KB Output is correct
50 Correct 2 ms 616 KB Output is correct
51 Correct 2 ms 616 KB Output is correct
52 Correct 2 ms 616 KB Output is correct
53 Correct 2 ms 616 KB Output is correct
54 Correct 3 ms 616 KB Output is correct
55 Correct 184 ms 19712 KB Output is correct
56 Correct 326 ms 22284 KB Output is correct
57 Correct 111 ms 21736 KB Output is correct
58 Correct 161 ms 19708 KB Output is correct
59 Correct 213 ms 19684 KB Output is correct
60 Correct 284 ms 21212 KB Output is correct
61 Correct 203 ms 19712 KB Output is correct
62 Correct 206 ms 21680 KB Output is correct
63 Correct 173 ms 18268 KB Output is correct
64 Correct 213 ms 20252 KB Output is correct
65 Correct 228 ms 21684 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 456 KB Output is correct
7 Correct 1 ms 352 KB Output is correct
8 Correct 1 ms 360 KB Output is correct
9 Correct 1 ms 352 KB Output is correct
10 Correct 0 ms 356 KB Output is correct
11 Correct 0 ms 352 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 360 KB Output is correct
14 Correct 1 ms 360 KB Output is correct
15 Correct 1 ms 360 KB Output is correct
16 Correct 1 ms 356 KB Output is correct
17 Correct 0 ms 360 KB Output is correct
18 Correct 1 ms 360 KB Output is correct
19 Correct 1 ms 360 KB Output is correct
20 Correct 1 ms 360 KB Output is correct
21 Correct 1 ms 360 KB Output is correct
22 Correct 1 ms 360 KB Output is correct
23 Correct 0 ms 360 KB Output is correct
24 Correct 1 ms 360 KB Output is correct
25 Correct 1 ms 360 KB Output is correct
26 Correct 1 ms 616 KB Output is correct
27 Correct 1 ms 360 KB Output is correct
28 Correct 0 ms 360 KB Output is correct
29 Correct 2 ms 616 KB Output is correct
30 Correct 2 ms 616 KB Output is correct
31 Correct 2 ms 612 KB Output is correct
32 Correct 2 ms 468 KB Output is correct
33 Correct 2 ms 616 KB Output is correct
34 Correct 2 ms 480 KB Output is correct
35 Correct 2 ms 616 KB Output is correct
36 Correct 2 ms 616 KB Output is correct
37 Correct 2 ms 604 KB Output is correct
38 Correct 2 ms 604 KB Output is correct
39 Correct 2 ms 604 KB Output is correct
40 Correct 2 ms 604 KB Output is correct
41 Correct 2 ms 616 KB Output is correct
42 Correct 2 ms 616 KB Output is correct
43 Correct 2 ms 624 KB Output is correct
44 Correct 2 ms 616 KB Output is correct
45 Correct 2 ms 616 KB Output is correct
46 Correct 2 ms 616 KB Output is correct
47 Correct 3 ms 616 KB Output is correct
48 Correct 3 ms 616 KB Output is correct
49 Correct 3 ms 616 KB Output is correct
50 Correct 2 ms 616 KB Output is correct
51 Correct 2 ms 616 KB Output is correct
52 Correct 2 ms 616 KB Output is correct
53 Correct 2 ms 616 KB Output is correct
54 Correct 3 ms 616 KB Output is correct
55 Correct 203 ms 21984 KB Output is correct
56 Correct 295 ms 23708 KB Output is correct
57 Correct 155 ms 23904 KB Output is correct
58 Correct 167 ms 21768 KB Output is correct
59 Correct 178 ms 21976 KB Output is correct
60 Correct 204 ms 20452 KB Output is correct
61 Correct 206 ms 21468 KB Output is correct
62 Correct 262 ms 24176 KB Output is correct
63 Correct 228 ms 21712 KB Output is correct
64 Correct 234 ms 23968 KB Output is correct
65 Correct 223 ms 19836 KB Output is correct
66 Correct 193 ms 20884 KB Output is correct
67 Correct 260 ms 22912 KB Output is correct
68 Correct 285 ms 24328 KB Output is correct
69 Correct 186 ms 22100 KB Output is correct
70 Correct 343 ms 24208 KB Output is correct
71 Correct 303 ms 24728 KB Output is correct
72 Correct 225 ms 22228 KB Output is correct
73 Correct 179 ms 22244 KB Output is correct
74 Correct 237 ms 21856 KB Output is correct
75 Correct 277 ms 24544 KB Output is correct
76 Correct 218 ms 21748 KB Output is correct
77 Correct 249 ms 23328 KB Output is correct
78 Correct 233 ms 24708 KB Output is correct
79 Correct 219 ms 20104 KB Output is correct
80 Correct 302 ms 21760 KB Output is correct
81 Correct 243 ms 23160 KB Output is correct
82 Correct 303 ms 24708 KB Output is correct
83 Correct 184 ms 19712 KB Output is correct
84 Correct 326 ms 22284 KB Output is correct
85 Correct 111 ms 21736 KB Output is correct
86 Correct 161 ms 19708 KB Output is correct
87 Correct 213 ms 19684 KB Output is correct
88 Correct 284 ms 21212 KB Output is correct
89 Correct 203 ms 19712 KB Output is correct
90 Correct 206 ms 21680 KB Output is correct
91 Correct 173 ms 18268 KB Output is correct
92 Correct 213 ms 20252 KB Output is correct
93 Correct 228 ms 21684 KB Output is correct
94 Correct 213 ms 22896 KB Output is correct
95 Correct 217 ms 25228 KB Output is correct
96 Correct 147 ms 24872 KB Output is correct
97 Correct 213 ms 22788 KB Output is correct
98 Correct 214 ms 23004 KB Output is correct
99 Correct 258 ms 22152 KB Output is correct
100 Correct 246 ms 25472 KB Output is correct
101 Correct 257 ms 22496 KB Output is correct
102 Correct 256 ms 24064 KB Output is correct
103 Correct 281 ms 25364 KB Output is correct
104 Correct 256 ms 21516 KB Output is correct
105 Correct 264 ms 23480 KB Output is correct
106 Correct 286 ms 24908 KB Output is correct
107 Correct 121 ms 25532 KB Output is correct
108 Correct 259 ms 22704 KB Output is correct
109 Correct 244 ms 22812 KB Output is correct
110 Correct 216 ms 22748 KB Output is correct
111 Correct 184 ms 22744 KB Output is correct
112 Correct 217 ms 22756 KB Output is correct
113 Correct 242 ms 22820 KB Output is correct
114 Correct 215 ms 22724 KB Output is correct
115 Correct 191 ms 22740 KB Output is correct
116 Correct 186 ms 22728 KB Output is correct