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 MAXN 500001
int n;
vector<pair<int,int>> vec;
map<int,int> kompresija;
int seg[MAXN*4][2];
void update(int pos,int node,int l,int r,int poz,int val)
{
if (l==r) seg[node][pos]=val;
else
{
int mid=(l+r)/2;
if (poz<=mid) update(pos,2*node,l,mid,poz,val);
else update(pos,2*node+1,mid+1,r,poz,val);
seg[node][pos]=max(seg[2*node][pos],seg[2*node+1][pos]);
}
}
int query(int pos,int node,int l,int r,int a,int b)
{
if (a>b) return -INT_MAX;
if (l==a and r==b) return seg[node][pos];
int mid=(l+r)/2;
return max(query(pos,2*node,l,mid,a,min(b,mid)),query(pos,2*node+1,mid+1,r,max(a,mid+1),b));
}
int main()
{
for (int i=0;i<4*MAXN;i++) seg[i][0]=seg[i][1]=-INT_MAX;
cin>>n;
for (int i=1;i<=n;i++)
{
int x,e;cin>>x>>e;
vec.push_back({e,x});
kompresija[x]=1;
}
sort(vec.rbegin(),vec.rend());
int idx=0;
for (auto&p:kompresija) {idx++;p.second=idx;}
int ans=0;
for (int i=0;i<n;i++)
{
int poz=kompresija[vec[i].second];
if (query(0,1,1,idx,poz,idx)>=vec[i].first-vec[i].second) continue;
if (query(1,1,1,idx,1,poz)>=vec[i].first+vec[i].second) continue;
ans++;
update(0,1,1,idx,poz,vec[i].first-vec[i].second);
update(1,1,1,idx,poz,vec[i].first+vec[i].second);
}
cout<<ans<<endl;
}
# | 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... |