Submission #924506

#TimeUsernameProblemLanguageResultExecution timeMemory
924506adhityamvAdvertisement 2 (JOI23_ho_t2)C++17
100 / 100
162 ms25500 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define mp make_pair #define pii pair<int,int> #define fi first #define se second int INF=1000000000; const int N=500000; pii seg[2*N]; int eminusx[N]; int nx[N]; int n; void build(){ for(int i=0;i<n;i++){ seg[i+n]=mp(eminusx[i],i); } for(int i=n-1;i>0;i--){ seg[i]=max(seg[2*i],seg[2*i+1]); } } int query(int l,int r){ l+=n; r+=n; pii ans=mp(-INF,-INF); while(l<r){ if(l&1){ ans=max(ans,seg[l]); l++; } if(r&1){ r--; ans=max(ans,seg[r]); } l>>=1; r>>=1; } return ans.second; } void solve(){ cin >>n; int x[n]; int e[n]; for(int i=0;i<n;i++){ cin >> x[i] >> e[i]; } vector<pii> tosort; for(int i=0;i<n;i++) tosort.push_back(mp(e[i]+x[i],e[i]-x[i])); sort(tosort.begin(),tosort.end()); for(int i=0;i<n;i++) eminusx[i]=tosort[i].second; build(); int cnt=0; int ind=-1; while(ind!=n-1){ ind=query(ind+1,n); cnt++; } cout << cnt << "\n"; } signed main(){ auto begin = std::chrono::high_resolution_clock::now(); ios_base::sync_with_stdio(false); cin.tie(NULL); int t; t=1; //cin >> t; while(t--) solve(); auto end = std::chrono::high_resolution_clock::now(); auto elapsed = std::chrono::duration_cast<std::chrono::nanoseconds>(end - begin); cerr << "Time measured: " << elapsed.count() * 1e-9 << " seconds.\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...