Submission #742918

#TimeUsernameProblemLanguageResultExecution timeMemory
742918zaneyuAdvertisement 2 (JOI23_ho_t2)C++14
100 / 100
1096 ms42328 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...