This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
#define fi first
#define se second
using namespace std;
const int N=1e6;
struct Point
{
int x,y;
};
struct Quo
{
long long x,y;
bool operator<(const Quo &oth) const
{
return (__int128)x*oth.y<(__int128)oth.x*y;
}
bool operator<=(const Quo &oth) const
{
return (__int128)x*oth.y<=(__int128)oth.x*y;
}
};
Point tab[N+10];
pair<Quo,Quo> seg[N+10];
set<Quo> st;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n,h;
cin>>n>>h;
for(int i=1;i<=n;i++)
cin>>tab[i].x>>tab[i].y;
int m=(n-2)/2;
for(int i=3;i<n;i+=2)
{
seg[i/2].fi=
{(long long)tab[i].x*(tab[i-1].y-tab[i].y)+(long long)(tab[i-1].x-tab[i].x)*(h-tab[i].y),
(tab[i-1].y-tab[i].y)};
seg[i/2].se=
{(long long)tab[i].x*(tab[i+1].y-tab[i].y)+(long long)(tab[i+1].x-tab[i].x)*(h-tab[i].y),
(tab[i+1].y-tab[i].y)};
}
//for(int i=1;i<=m;i++)
// cerr<<seg[i].fi.x<<"/"<<seg[i].fi.y<<" "<<seg[i].se.x<<"/"<<seg[i].se.y<<"\n";
pair<Quo,Quo> curr=seg[1];
for(int i=2;i<=m;i++)
{
auto it=st.lower_bound(seg[i].fi);
if(it!=st.end() && *it<=seg[i].se)
continue;
if(curr.se<seg[i].fi)
{
st.insert(curr.se);
curr=seg[i];
}
else
{
curr.fi=max(curr.fi,seg[i].fi);
curr.se=min(curr.se,seg[i].se);
}
}
cout<<st.size()+1<<"\n";
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |