Submission #580481

#TimeUsernameProblemLanguageResultExecution timeMemory
580481FatihSolakDivide and conquer (IZhO14_divide)C++17
100 / 100
75 ms10256 KiB
#include <bits/stdc++.h> #define N 200005 using namespace std; long long preg[N]; long long pree[N]; int x[N]; struct SegTree{ vector<long long> t; int n; SegTree(int size){ n = size; t.assign(4*n,1e18); } void upd(int v,int tl,int tr,int pos,long long val){ if(tl == tr){ t[v] = min(t[v],val); return; } int tm = (tl + tr)/2; if(pos <= tm) upd(v*2,tl,tm,pos,val); else upd(v*2+1,tm+1,tr,pos,val); t[v] = min(t[v*2],t[v*2+1]); } long long get(int v,int tl,int tr,int l,int r){ if(tr < l || r < tl) return 1e18; if(l <= tl && tr <= r) return t[v]; int tm = (tl + tr)/2; return min(get(v*2,tl,tm,l,r),get(v*2+1,tm+1,tr,l,r)); } void upd(int pos,long long val){ upd(1,1,n,pos,val); } long long get(int l,int r){ return get(1,1,n,l,r); } }; void solve(){ int n; cin >> n; vector<long long> compress; for(int i = 1;i<=n;i++){ cin >> x[i]; int g,e; cin >> g >> e; preg[i] = preg[i-1] + g; pree[i] = pree[i-1] + e; compress.push_back(x[i] - pree[i]); compress.push_back(x[i] - pree[i-1]); } sort(compress.begin(),compress.end()); compress.resize(unique(compress.begin(),compress.end())-compress.begin()); SegTree t(compress.size()); long long ans = 0; for(int i = 1;i<=n;i++){ t.upd(lower_bound(compress.begin(),compress.end(),x[i]-pree[i-1]) - compress.begin()+1 ,preg[i-1]); ans = max(ans,preg[i] - t.get(lower_bound(compress.begin(),compress.end(),x[i]-pree[i]) - compress.begin()+1 ,compress.size())); } cout << ans; } int main(){ ios_base::sync_with_stdio(false); cin.tie(nullptr); #ifdef Local freopen("in.txt","r",stdin); freopen("out.txt","w",stdout); #endif int t = 1; //cin >> t; while(t--){ solve(); } #ifdef Local cout << endl << fixed << setprecision(2) << 1000.0*clock()/CLOCKS_PER_SEC << " milliseconds."; #endif }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...