제출 #924487

#제출 시각아이디문제언어결과실행 시간메모리
924487adhityamvAdvertisement 2 (JOI23_ho_t2)C++17
10 / 100
156 ms19652 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; int seg[2*N]; int eminusx[N]; int n; void build(){ for(int i=0;i<n;i++){ seg[i+n]=i; } for(int i=n-1;i>=0;i--){ seg[i]=max(mp(eminusx[seg[2*i]],seg[2*i]),mp(eminusx[seg[2*i+1]],seg[2*i+1])).second; } } int query(int l,int r){ l+=n; r+=n; pii ans=mp(-INF,-INF); while(l<r){ if(l&1){ ans=max(ans,mp(eminusx[seg[l]],seg[l])); l++; } if(r&1){ r--; ans=max(ans,mp(eminusx[seg[r]],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],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...