Submission #924491

#TimeUsernameProblemLanguageResultExecution timeMemory
924491adhityamvAdvertisement 2 (JOI23_ho_t2)C++17
0 / 100
40 ms10960 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; pair<pii,int> seg[2*N]; int eminusx[N]; int x[N]; int n; void build(){ for(int i=0;i<n;i++){ seg[i+n]=mp(mp(eminusx[i],x[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; pair<pii,int> ans=mp(mp(-INF,-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 e[n]; for(int i=0;i<n;i++){ cin >> x[i] >> e[i]; } vector<pair<pii,int>> tosort; for(int i=0;i<n;i++) tosort.push_back(mp(mp(e[i]+x[i],x[i]),i)); sort(tosort.begin(),tosort.end()); for(int i=0;i<n;i++) eminusx[i]=e[tosort[i].second]-x[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...