제출 #892277

#제출 시각아이디문제언어결과실행 시간메모리
892277LCJLYAdvertisement 2 (JOI23_ho_t2)C++14
59 / 100
1701 ms1048576 KiB
#include <bits/stdc++.h> using namespace std; #define int long long #define ld long double #define show(x,y) cout << y << " " << #x << endl; #define show2(x,y,i,j) cout << y << " " << #x << " " << j << " " << #i << endl; #define show3(x,y,i,j,p,q) cout << y << " " << #x << " " << j << " " << #i << " " << q << " " << #p << endl; #define show4(x,y) for(auto it:x) cout << it << " "; cout << #y << endl; typedef pair<int,int>pii; //typedef pair<pii,pii>pi2; typedef array<int,4>pi2; inline pii combine(pii a, pii b){ //max min return {max(a.first,b.first),min(a.second,b.second)}; } struct node{ int s,e,m; node *l,*r; pii v; node(int ss, int ee):s(ss),e(ee),m((s+e)>>1),l(NULL),r(NULL){ v={LONG_LONG_MIN,LONG_LONG_MAX}; } inline void inst(){ if(l==NULL)l=new node(s,m); if(r==NULL)r=new node(m+1,e); } void upd(int x, int y){ if(s==e){ v.first=max(v.first,y); v.second=min(v.second,y); return; } inst(); if(x<=m)l->upd(x,y); else r->upd(x,y); v=combine(l->v,r->v); } pii query(int x, int y){ if(x<=s&&y>=e) return v; inst(); if(y<=m)return l->query(x,y); if(x>m)return r->query(x,y); return combine(l->query(x,m),r->query(m+1,y)); } }; bool cmp(const pii a, const pii b){ return a.second>b.second; } void solve(){ int n; cin >> n; pii arr[n]; for(int x=0;x<n;x++){ cin >> arr[x].first >> arr[x].second; } sort(arr,arr+n,cmp); int maxn=1000000005; node left(0,maxn); node right(0,maxn); int counter=0; for(int x=0;x<n;x++){ //check left (range max) //check right (range min) int pos=arr[x].first; pii hold=left.query(0,pos); pii hold2=right.query(pos,maxn); if(hold.first>=arr[x].first+arr[x].second||hold2.second<=arr[x].first-arr[x].second){ continue; } counter++; left.upd(arr[x].first,arr[x].first+arr[x].second); right.upd(arr[x].first,arr[x].first-arr[x].second); } cout << counter; } int32_t main(){ ios::sync_with_stdio(0); cin.tie(0); //freopen("in.txt", "r", stdin); int t=1; //cin >> t; while(t--){ solve(); } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...