Submission #544647

#TimeUsernameProblemLanguageResultExecution timeMemory
544647AbdelmagedNourLightning Rod (NOI18_lightningrod)C++17
44 / 100
1682 ms262144 KiB
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") using namespace std; const int N=10000005; int n,a[N],b[N],nxta[N],nxtb[N]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin>>n; for(int i=0;i<n;i++){ int x,y; cin>>x>>y; a[i]=y-x; b[i]=y+x; } vector<int>st; for(int i=n-1;i>=0;i--){ while(!st.empty()&&a[st.back()]<a[i])st.pop_back(); nxta[i]=(st.empty()?-1:st.back()); st.push_back(i); } st.clear(); for(int i=n-1;i>=0;i--){ while(!st.empty()&&b[st.back()]<b[i])st.pop_back(); nxtb[i]=(st.empty()?n:st.back()); st.push_back(i); } int res=0,pos=0; while(pos<n){ res++; while(nxta[pos]!=-1)pos=nxta[pos]; pos=nxtb[pos]; } cout<<res; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...