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>
#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];
}
stack<int>st;
for(int i=n-1;i>=0;i--){
while(!st.empty()&&a[st.top()]<a[i])st.pop();
nxta[i]=(st.empty()?-1:st.top());
st.push(i);
}
st=stack<int>();
for(int i=n-1;i>=0;i--){
while(!st.empty()&&b[st.top()]<b[i])st.pop();
nxtb[i]=(st.empty()?n:st.top());
st.push(i);
}
int res=0;
int pos=0;
while(pos<n){
res++;
while(nxta[pos]!=-1)pos=nxta[pos];
pos=nxtb[pos];
}
cout<<res;
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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |