#include <bits/stdc++.h>
using namespace std;
int32_t main(){
ios::sync_with_stdio(0);
cin.tie(0);
int n,m;
cin >> n >> m;
pair<int,int> arr[n];
for(int i=0; i<n; i++) cin >> arr[i].first >> arr[i].second;
vector<pair<int,pair<int,int> > > vert;
for(int i=0; i<n-1; i++){
if(arr[i].first==arr[i+1].first) vert.push_back({arr[i].first,{arr[i].second,arr[i+1].second}});
}
if(arr[0].first==arr[n-1].first) vert.push_back({arr[0].first,{arr[0].second,arr[n-1].second}});
set<pair<int,int> > odd,even,all;
set<pair<int,int> >::iterator it;
sort(vert.begin(),vert.end());
int ans=0,bad=0;
for(int o=0; o<(int)vert.size(); o++){
pair<int,pair<int,int> > i=vert[o];
pair<int,int> ln=i.second;
if(ln.second<ln.first) swap(ln.second,ln.first);
it=all.upper_bound({ln.first,1e9});
if(it!=all.begin()) it--;
if(it!=all.end()&&it->first<=ln.first&&it->second>=ln.second){
pair<int,int> tmp=*it;
all.erase(it);
if((it->second-it->first)%2) bad--;
if(tmp.first<ln.first) all.insert({tmp.first,ln.first});
if(ln.second<tmp.second) all.insert({ln.second,tmp.second});
if((ln.first-tmp.first)%2) bad++;
if((tmp.second-ln.second)%2) bad++;
}
else{
it=all.lower_bound(ln);
if(it!=all.end()&&it->first==ln.second){
ln.second=it->second;
if((it->second-it->first)%2) bad--;
all.erase(it);
}
it=all.lower_bound(ln);
if(it!=all.begin()) it--;
if(it!=all.end()&&it->second==ln.first){
ln.first=it->first;
if((it->second-it->first)%2) bad--;
all.erase(it);
}
all.insert(ln);
if((ln.second-ln.first)%2) bad++;
}
if(o==(int)vert.size()-1||vert[o+1].first!=vert[o].first){
if(bad>0){
cout << ans;
return 0;
}
}
bool got=false;
it=odd.lower_bound(ln);
if(it!=odd.begin()) it--;
for(;it!=odd.end();it++){
if(it->second<=ln.first) continue;
if(it->first>=ln.second) break;
if(i.first%2==0){
cout << ans;
return 0;
}
got=true;
pair<int,int> tmp=*it;
odd.erase(it);
odd.insert({max(tmp.first,ln.first),min(tmp.second,ln.second)});
}
it=even.lower_bound(ln);
if(it!=even.begin()) it--;
for(;it!=even.end();it++){
if(it->second<=ln.first) continue;
if(it->first>=ln.second) break;
if(i.first%2==1){
cout << ans;
return 0;
}
got=true;
pair<int,int> tmp=*it;
even.erase(it);
even.insert({max(tmp.first,ln.first),min(tmp.second,ln.second)});
}
if(!got){
if(i.first%2==1) odd.insert(ln);
else even.insert(ln);
}
if(i.first%2==1&&even.empty()){
if(o==(int)vert.size()-1||vert[o+1].first!=vert[o].first){
if(vert[o+1].first%2==1) ans=vert[o+1].first;
else ans=vert[o+1].first-1;
}
}
else if(i.first%2==0&&odd.empty()){
if(o==(int)vert.size()-1||vert[o+1].first!=vert[o].first) ans=i.first;
if(o!=(int)vert.size()-1&&vert[o+1].first!=vert[o].first){
if(vert[o+1].first%2==0) ans=vert[o+1].first;
else ans=vert[o+1].first-1;
}
}
}
cout << ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 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 |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 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 |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
0 ms |
348 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
0 ms |
348 KB |
Output is correct |
26 |
Correct |
0 ms |
348 KB |
Output is correct |
27 |
Correct |
0 ms |
348 KB |
Output is correct |
28 |
Correct |
0 ms |
348 KB |
Output is correct |
29 |
Correct |
0 ms |
348 KB |
Output is correct |
30 |
Correct |
0 ms |
348 KB |
Output is correct |
31 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
6 ms |
1184 KB |
Output is correct |
3 |
Correct |
55 ms |
6716 KB |
Output is correct |
4 |
Correct |
30 ms |
3996 KB |
Output is correct |
5 |
Correct |
27 ms |
4168 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
43 ms |
5372 KB |
Output is correct |
9 |
Correct |
32 ms |
4564 KB |
Output is correct |
10 |
Correct |
52 ms |
7628 KB |
Output is correct |
11 |
Correct |
25 ms |
3796 KB |
Output is correct |
12 |
Correct |
0 ms |
344 KB |
Output is correct |
13 |
Correct |
53 ms |
7880 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 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 |
24 ms |
3540 KB |
Output is correct |
6 |
Correct |
40 ms |
3540 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
51 ms |
604 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
344 KB |
Output is correct |
13 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
14 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
28 ms |
4048 KB |
Output is correct |
3 |
Correct |
28 ms |
4008 KB |
Output is correct |
4 |
Correct |
23 ms |
3672 KB |
Output is correct |
5 |
Correct |
42 ms |
3784 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
29 ms |
3676 KB |
Output is correct |
9 |
Correct |
33 ms |
3528 KB |
Output is correct |
10 |
Correct |
59 ms |
3540 KB |
Output is correct |
11 |
Correct |
61 ms |
3664 KB |
Output is correct |
12 |
Correct |
27 ms |
3676 KB |
Output is correct |
13 |
Correct |
27 ms |
3536 KB |
Output is correct |
14 |
Correct |
50 ms |
7776 KB |
Output is correct |
15 |
Correct |
60 ms |
3540 KB |
Output is correct |
16 |
Correct |
387 ms |
3528 KB |
Output is correct |
17 |
Correct |
47 ms |
3540 KB |
Output is correct |
18 |
Correct |
34 ms |
3536 KB |
Output is correct |
19 |
Correct |
32 ms |
3668 KB |
Output is correct |
20 |
Correct |
61 ms |
3532 KB |
Output is correct |
21 |
Correct |
128 ms |
3528 KB |
Output is correct |
22 |
Incorrect |
155 ms |
3532 KB |
Output isn't correct |
23 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
52 ms |
6964 KB |
Output is correct |
2 |
Correct |
24 ms |
4168 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
33 ms |
3668 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
77 ms |
3676 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
60 ms |
4744 KB |
Output is correct |
9 |
Correct |
132 ms |
3532 KB |
Output is correct |
10 |
Correct |
32 ms |
3536 KB |
Output is correct |
11 |
Correct |
27 ms |
3536 KB |
Output is correct |
12 |
Correct |
33 ms |
4552 KB |
Output is correct |
13 |
Correct |
125 ms |
3532 KB |
Output is correct |
14 |
Correct |
65 ms |
3664 KB |
Output is correct |
15 |
Correct |
122 ms |
3536 KB |
Output is correct |
16 |
Correct |
54 ms |
7616 KB |
Output is correct |
17 |
Correct |
56 ms |
7620 KB |
Output is correct |
18 |
Correct |
54 ms |
7620 KB |
Output is correct |
19 |
Correct |
29 ms |
3944 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
46 ms |
5292 KB |
Output is correct |
22 |
Correct |
32 ms |
4560 KB |
Output is correct |
23 |
Correct |
0 ms |
348 KB |
Output is correct |
24 |
Correct |
0 ms |
344 KB |
Output is correct |
25 |
Correct |
0 ms |
348 KB |
Output is correct |
26 |
Correct |
0 ms |
344 KB |
Output is correct |
27 |
Correct |
0 ms |
348 KB |
Output is correct |
28 |
Correct |
0 ms |
348 KB |
Output is correct |
29 |
Correct |
0 ms |
348 KB |
Output is correct |
30 |
Correct |
1 ms |
348 KB |
Output is correct |
31 |
Correct |
0 ms |
348 KB |
Output is correct |
32 |
Correct |
0 ms |
348 KB |
Output is correct |
33 |
Correct |
0 ms |
344 KB |
Output is correct |
34 |
Correct |
1 ms |
348 KB |
Output is correct |
35 |
Correct |
0 ms |
348 KB |
Output is correct |
36 |
Correct |
30 ms |
4172 KB |
Output is correct |
37 |
Correct |
397 ms |
3540 KB |
Output is correct |
38 |
Correct |
365 ms |
3532 KB |
Output is correct |
39 |
Correct |
39 ms |
3540 KB |
Output is correct |
40 |
Correct |
43 ms |
3540 KB |
Output is correct |
41 |
Correct |
0 ms |
348 KB |
Output is correct |
42 |
Correct |
0 ms |
348 KB |
Output is correct |
43 |
Correct |
0 ms |
348 KB |
Output is correct |
44 |
Correct |
0 ms |
348 KB |
Output is correct |
45 |
Correct |
0 ms |
348 KB |
Output is correct |
46 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 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 |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
0 ms |
348 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
0 ms |
348 KB |
Output is correct |
26 |
Correct |
0 ms |
348 KB |
Output is correct |
27 |
Correct |
0 ms |
348 KB |
Output is correct |
28 |
Correct |
0 ms |
348 KB |
Output is correct |
29 |
Correct |
0 ms |
348 KB |
Output is correct |
30 |
Correct |
0 ms |
348 KB |
Output is correct |
31 |
Correct |
0 ms |
348 KB |
Output is correct |
32 |
Correct |
0 ms |
348 KB |
Output is correct |
33 |
Correct |
6 ms |
1184 KB |
Output is correct |
34 |
Correct |
55 ms |
6716 KB |
Output is correct |
35 |
Correct |
30 ms |
3996 KB |
Output is correct |
36 |
Correct |
27 ms |
4168 KB |
Output is correct |
37 |
Correct |
1 ms |
348 KB |
Output is correct |
38 |
Correct |
1 ms |
348 KB |
Output is correct |
39 |
Correct |
43 ms |
5372 KB |
Output is correct |
40 |
Correct |
32 ms |
4564 KB |
Output is correct |
41 |
Correct |
52 ms |
7628 KB |
Output is correct |
42 |
Correct |
25 ms |
3796 KB |
Output is correct |
43 |
Correct |
0 ms |
344 KB |
Output is correct |
44 |
Correct |
53 ms |
7880 KB |
Output is correct |
45 |
Correct |
0 ms |
348 KB |
Output is correct |
46 |
Correct |
0 ms |
348 KB |
Output is correct |
47 |
Correct |
0 ms |
348 KB |
Output is correct |
48 |
Correct |
0 ms |
348 KB |
Output is correct |
49 |
Correct |
0 ms |
348 KB |
Output is correct |
50 |
Correct |
0 ms |
348 KB |
Output is correct |
51 |
Correct |
0 ms |
348 KB |
Output is correct |
52 |
Correct |
0 ms |
348 KB |
Output is correct |
53 |
Correct |
24 ms |
3540 KB |
Output is correct |
54 |
Correct |
40 ms |
3540 KB |
Output is correct |
55 |
Correct |
0 ms |
348 KB |
Output is correct |
56 |
Correct |
0 ms |
348 KB |
Output is correct |
57 |
Correct |
0 ms |
348 KB |
Output is correct |
58 |
Correct |
51 ms |
604 KB |
Output is correct |
59 |
Correct |
0 ms |
348 KB |
Output is correct |
60 |
Correct |
0 ms |
344 KB |
Output is correct |
61 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
62 |
Halted |
0 ms |
0 KB |
- |