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>
using namespace std;
#define int long long
#define ld long double
#define show(x,y) cout << y << " " << #x << endl;
#define show2(x,y,i,j) cout << y << " " << #x << " " << j << " " << #i << endl;
#define show3(x,y,i,j,p,q) cout << y << " " << #x << " " << j << " " << #i << " " << q << " " << #p << endl;
#define show4(x,y) for(auto it:x) cout << it << " "; cout << #y << endl;
typedef pair<int,int>pii;
//typedef pair<pii,pii>pi2;
typedef array<int,4>pi2;
inline pii combine(pii a, pii b){
//max min
return {max(a.first,b.first),min(a.second,b.second)};
}
struct node{
int s,e,m;
node *l,*r;
pii v;
node(int ss, int ee):s(ss),e(ee),m((s+e)>>1),l(NULL),r(NULL){
v={LONG_LONG_MIN,LONG_LONG_MAX};
}
inline void inst(){
if(l==NULL)l=new node(s,m);
if(r==NULL)r=new node(m+1,e);
}
void upd(int x, int y){
if(s==e){
v.first=max(v.first,y);
v.second=min(v.second,y);
return;
}
inst();
if(x<=m)l->upd(x,y);
else r->upd(x,y);
v=combine(l->v,r->v);
}
pii query(int x, int y){
if(x<=s&&y>=e) return v;
inst();
if(y<=m)return l->query(x,y);
if(x>m)return r->query(x,y);
return combine(l->query(x,m),r->query(m+1,y));
}
};
bool cmp(const pii a, const pii b){
return a.second>b.second;
}
void solve(){
int n;
cin >> n;
pii arr[n];
vector<int>v;
for(int x=0;x<n;x++){
cin >> arr[x].first >> arr[x].second;
v.push_back(arr[x].first);
}
v.push_back(0);
v.push_back(LONG_LONG_MAX/3);
sort(v.begin(),v.end());
v.resize(unique(v.begin(),v.end())-v.begin());
unordered_map<int,int>dis;
for(int x=0;x<n;x++){
int index=lower_bound(v.begin(),v.end(),arr[x].first)-v.begin();
dis[arr[x].first]=index+1;
}
dis[0]=1;
dis[LONG_LONG_MAX/3]=v.size();
sort(arr,arr+n,cmp);
node left(0,v.size()+10);
node right(0,v.size()+10);
int counter=0;
for(int x=0;x<n;x++){
//check left (range max)
//check right (range min)
int pos=arr[x].first;
pii hold=left.query(dis[0],dis[pos]);
pii hold2=right.query(dis[pos],dis[LONG_LONG_MAX/3]);
if(hold.first>=arr[x].first+arr[x].second||hold2.second<=arr[x].first-arr[x].second){
continue;
}
counter++;
left.upd(dis[arr[x].first],arr[x].first+arr[x].second);
right.upd(dis[arr[x].first],arr[x].first-arr[x].second);
}
cout << counter;
}
int32_t main(){
ios::sync_with_stdio(0);
cin.tie(0);
//freopen("in.txt", "r", stdin);
int t=1;
//cin >> t;
while(t--){
solve();
}
}
# | 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... |