Submission #447847

#TimeUsernameProblemLanguageResultExecution timeMemory
447847JasiekstrzPlanine (COCI21_planine)C++17
110 / 110
474 ms61056 KiB
#include<bits/stdc++.h> #define fi first #define se second using namespace std; const int N=1e6; struct Point { long long x,y; }; Point operator-(Point a,Point b) { return {a.x-b.x,a.y-b.y}; } long long operator*(Point a,Point b) { return a.x*b.y-a.y*b.x; } 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; vector<Point> stck; 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=2;i<n;i++) { if(i%2==0) { while(stck.size()>2) { auto tp=stck.back(); stck.pop_back(); if((tab[i]-stck.back())*(tp-stck.back())>0) { stck.push_back(tp); break; } } stck.push_back(tab[i]); } else { while(stck.size()>2) { auto tp=stck.back(); stck.pop_back(); if((tp-tab[i])*(stck.back()-tab[i])>0) { stck.push_back(tp); break; } } seg[i/2].fi= {tab[i].x*(stck.back().y-tab[i].y)+(stck.back().x-tab[i].x)*(h-tab[i].y), (stck.back().y-tab[i].y)}; } } stck.clear(); for(int i=n-1;i>1;i--) { if(i%2==0) { while(stck.size()>2) { auto tp=stck.back(); stck.pop_back(); if((tab[i]-stck.back())*(tp-stck.back())<0) { stck.push_back(tp); break; } } stck.push_back(tab[i]); } else { while(stck.size()>2) { auto tp=stck.back(); stck.pop_back(); if((tp-tab[i])*(stck.back()-tab[i])<0) { stck.push_back(tp); break; } } seg[i/2].se= {tab[i].x*(stck.back().y-tab[i].y)+(stck.back().x-tab[i].x)*(h-tab[i].y), (stck.back().y-tab[i].y)}; } } //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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...