이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
using pii=pair<int,int>;
#define f first
#define s second
#define pb push_back
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define FILL(n,x) memset(n,x,sizeof(n))
#define ALL(_a) _a.begin(),_a.end()
#define sz(x) (int)x.size()
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()),c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
const ll maxn=5e5+5;
const ll maxlg=__lg(maxn)+2;
const ll INF64=4e18;
const int INF=0x3f3f3f3f;
const int MOD=1e9+7;
const ld PI=acos(-1);
const ld eps=1e-4;
#define lowb(x) x&(-x)
#define MNTO(x,y) x=min(x,(__typeof__(x))y)
#define MXTO(x,y) x=max(x,(__typeof__(x))y)
pii arr[maxn];
map<int,int> mp;
struct seg{
int seg[4*maxn];
void upd(int idx,int l,int r,int p,int x){
if(r<p or l>p) return;
int mid=(l+r)/2;
MXTO(seg[idx],x);
if(l==r) return;
upd(idx*2,l,mid,p,x);
upd(idx*2+1,mid+1,r,p,x);
}
int query(int idx,int l,int r,int ql,int qr){
int mid=(l+r)/2;
if(r<ql or l>qr) return -INF;
if(ql<=l and r<=qr) return seg[idx];
return max(query(idx*2,l,mid,ql,qr),query(idx*2+1,mid+1,r,ql,qr));
}
}seg,seg2;
int main(){
int n;
cin>>n;
vector<int> dsc;
REP(i,n){
cin>>arr[i].s>>arr[i].f;
dsc.pb(arr[i].s);
}
SORT_UNIQUE(dsc);
REP(i,sz(dsc)) mp[dsc[i]]=i;
sort(arr,arr+n);
reverse(arr,arr+n);
multiset<int> ms;
int ans=0;
REP(i,n){
int p=mp[arr[i].s];
//cout<<seg.query(1,0,n-1,0,p)<<' ';
if(seg.query(1,0,n-1,0,p)>=arr[i].s+arr[i].f or seg2.query(1,0,n-1,p,n-1)>=arr[i].f-arr[i].s+INF) continue;
seg.upd(1,0,n-1,p,arr[i].s+arr[i].f);
seg2.upd(1,0,n-1,p,arr[i].f-arr[i].s+INF);
++ans;
}
cout<<ans<<'\n';
}
# | 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... |