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>
#define int long long
#define mp make_pair
#define pb push_back
#define ld long double
#define pii pair<int,int>
#define sz(x) (int)x.size()
#define piii pair<pii,pii>
#define precise cout<<fixed<<setprecision(10)
#define st first
#define nd second
#define ins insert
#define vi vector<int>
#define BOOST ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
using namespace std;
const int inf=(int)1e18+9;
const int MAX=1<<18;
pii t[MAX*2][2];
pii merguj(pii x,pii y){
if (x.st<=y.st)return x;
return y;
}
int x[MAX],e[MAX];
bool cmp(int i,int j){
if (e[i]!=e[j])return e[i]>e[j];
return x[i]<x[j];
}
void update(int u,int c,int pos,int id){
u+=MAX;
t[u][id]=mp(c,pos);
for (;u>1;u>>=1)t[u>>1][id]=merguj(t[u][id],t[u^1][id]);
}
pii query(int u,int v,int id){
pii wyn=mp(inf,inf);
for (u+=MAX,v+=MAX+1;u<v;u>>=1,v>>=1){
if (u&1)wyn=merguj(wyn,t[u++][id]);
if (v&1)wyn=merguj(wyn,t[--v][id]);
}
return wyn;
}
bool O[MAX];
bool check(int i,int j){
return e[i]-e[j]>=abs(x[i]-x[j]);
}
int beka[MAX];
bool cmp2(int i,int j){
if (x[i]!=x[j])return x[i]<x[j];
return e[i]<e[j];
}
int idx[MAX];
int re[MAX];
int32_t main()
{
BOOST;
int n;
cin>>n;
vi pom;
for (int i=1;i<=n;i++)pom.pb(i);
for (int i=1;i<=n;i++)cin>>x[i]>>e[i];
for (int i=1;i<=n;i++)beka[i]=i;
sort(beka+1,beka+n+1,cmp2);
for (int i=1;i<=n;i++)idx[beka[i]]=i,re[i]=beka[i];
for (int i=1;i<=n;i++){
update(idx[i],e[i]-x[i],idx[i],0);
update(idx[i],e[i]+x[i],idx[i],1);
}
sort(pom.begin(),pom.end(),cmp);
int ans=0;
for (auto it:pom){
if (O[idx[it]])continue;
// cout<<"TERAZ "<<idx[it]<<"\n";
O[idx[it]]=true;
update(idx[it],inf,inf,0);
update(idx[it],inf,inf,1);
ans++;
int l=idx[it]+1,r=n;
if (l<=r){
while (true){
pii ask=query(l,r,1);
if (ask.st>e[it]+x[it])break;
int id=ask.nd;
/* cout<<"TERAZ "<<it<<" "<<ask.st<<" "<<re[id]<<" "<<idx[it]<<" "<<id<<"\n";
if (!check(it,re[id])){
cout<<"KONIEC\n";
return 0LL;
}*/
O[id]=true;
update(id,inf,inf,0);
update(id,inf,inf,1);
}
}
l=1,r=idx[it]-1;
if (l<=r){
while (true){
pii ask=query(l,r,0);
if (ask.st>e[it]-x[it])break;
int id=ask.nd;
O[id]=true;
/*
cout<<"TERAZ "<<it<<" "<<re[id]<<" "<<idx[it]<<" "<<id<<"\n";
if (!check(it,re[id])){
cout<<"KONIEC\n";
return 0LL;
}*/
update(id,inf,inf,0);
update(id,inf,inf,1);
}
}
}
cout<<ans;
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... |