Submission #544637

#TimeUsernameProblemLanguageResultExecution timeMemory
544637AbdelmagedNourLightning Rod (NOI18_lightningrod)C++17
40 / 100
1701 ms262144 KiB
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") using namespace std; const int N=10000005; int n,x[N],y[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++){ cin>>x[i]>>y[i]; a[i]=y[i]-x[i]; b[i]=y[i]+x[i]; } 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...