Submission #442648

#TimeUsernameProblemLanguageResultExecution timeMemory
442648leakedDivide and conquer (IZhO14_divide)C++14
100 / 100
57 ms8716 KiB
#include <bits/stdc++.h> //#pragma GCC optimize("unroll-loops") //#pragma GCC optimize("Ofast") //#pragma GCC optimize("-O3") //#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") #define vec vector #define sz(x) ( int)x.size() #define m_p make_pair #define f first #define s second #define pb push_back #define all(x) x.begin(),x.end() #define rall(x) x.rbegin(),x.rend() #define int long long using namespace std; typedef long long ll; typedef pair<ll, int> pli; typedef pair<int,ll> pil; typedef pair<int,int> pii; typedef unsigned long long ull; auto rng=bind(uniform_int_distribution<int>(1,1000),mt19937(time(0))); template<class T> bool umax(T &a,const T &b){return (a<b?a=b,1:0);} template<class T> bool umin(T &a,const T &b){return (a>b?a=b,1:0);} vec<ll>kek; const int N=1e5+1; ll f[N]; void upd(int id,ll x){ id++; while(id<N){ umax(f[id],x); id+=id&-id; } } int get(int id){ id++; ll ans=-2e9; while(id>0){ umax(ans,f[id]); id-=id&-id; } return ans; } signed main(){ ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); int n; cin>>n; vec<int>x(n),g(n),d(n); vec<ll>pref(n,0); vec<ll>pg(n,0); for(int i=0;i<n;i++){ cin>>x[i]>>g[i]>>d[i]; pref[i]=(i?pref[i-1]:0)+d[i]; pg[i]=(i?pg[i-1]:0)+g[i]; } for(int i=0;i<n;i++){ kek.pb(x[i]-pref[i]); } sort(all(kek));kek.erase(unique(all(kek)),kek.end()); ll ans=0; for(int i=n-1;i>=0;i--){ int w=lower_bound(all(kek),x[i]-pref[i])-kek.begin(); upd(w,pg[i]); w=upper_bound(all(kek),x[i]-(i?pref[i-1]:0))-kek.begin()-1; umax(ans,get(w)-(i?pg[i-1]:0)); } cout<<ans; return 0; } /* 1 5 8 4 2 5 1 3 2 4 4 5 2 2 1 4 */
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...