제출 #895559

#제출 시각아이디문제언어결과실행 시간메모리
895559winter0101Advertisement 2 (JOI23_ho_t2)C++14
100 / 100
465 ms31828 KiB
#include<bits/stdc++.h> using namespace std; #define all(fl) fl.begin(),fl.end() #define pb push_back #define fi first #define se second #define for1(i,j,k) for(int i=j;i<=k;i++) #define for2(i,j,k) for(int i=j;i>=k;i--) #define for3(i,j,k,l) for(int i=j;i<=k;i+=l) #define lb lower_bound #define ub upper_bound #define sz(a) (int)a.size() #define pii pair<int,int> #define pli pair<long long,int> #define gcd __gcd #define lcm(x,y) x*y/__gcd(x,y) #define pil pair<int,long long> const int maxn=5e5+9; pii a[maxn]; struct IT{ vector<int>st; void resz(int n){ st.resize(4*n+9); for1(i,1,4*n)st[i]=-2e9; } void update(int id,int l,int r,int u,int val){ if (l>u||r<u)return; if (l==r){ st[id]=val; return; } int mid=(l+r)/2; update(id*2,l,mid,u,val); update(id*2+1,mid+1,r,u,val); st[id]=max(st[id*2],st[id*2+1]); } int get(int id,int l,int r,int u,int v){ if (l>v||r<u||u>v)return -2e9; if (u<=l&&r<=v)return st[id]; int mid=(l+r)/2; return max(get(id*2,l,mid,u,v),get(id*2+1,mid+1,r,u,v)); } }; int id[maxn]; IT st1,st2;//st1 low st2 high int n; bool check(int id){ if (st1.get(1,1,n,1,id-1)>=a[id].fi+a[id].se)return 1; if (st2.get(1,1,n,id+1,n)>=a[id].se-a[id].fi)return 1; return 0; } signed main(){ ios_base::sync_with_stdio(0); cin.tie(0); //freopen("temp.INP","r",stdin); //freopen("temp.OUT","w",stdout); cin>>n; for1(i,1,n)cin>>a[i].fi>>a[i].se; sort(a+1,a+1+n); for1(i,1,n)id[i]=i; sort(id+1,id+1+n,[](int i,int j){ if (a[i].se==a[j].se)return a[i].fi>a[j].fi; return a[i].se>a[j].se; }); st1.resz(n),st2.resz(n); int ans=0; for1(i,1,n){ ans+=(check(id[i])==0); st1.update(1,1,n,id[i],a[id[i]].fi+a[id[i]].se); st2.update(1,1,n,id[i],a[id[i]].se-a[id[i]].fi); } cout<<ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...