Submission #206820

#TimeUsernameProblemLanguageResultExecution timeMemory
206820mat_vDivide and conquer (IZhO14_divide)C++14
0 / 100
294 ms6888 KiB
#include <bits/stdc++.h> #define mod 1000000007 #define pb push_back #define mid(l, r) ((l)+(r))/2 #define len(a) (a).length() #define sz(a) (a).size() #define xx first #define yy second #define inf int(2e9) #define ff(i, a, b) for(int (i) = (a); (i) <= (b); ++(i)) #define fb(i, a, b) for(int (i) = (a); (i) >= (b); --(i)) #define maxn 100005 using namespace std; typedef long long ll; typedef pair<ll,ll> pii; template<class T> void print(const T niz[], const int siz) { for(int i=0;i<siz;i++) cout << niz[i] << " "; cout << endl; } int n; ll x[maxn], d[maxn], g[maxn]; vector<pii> v; ll res; pii seg[4 * maxn]; void update(int node, int l, int r, int poz, ll val){ if(l == r){ seg[node] = {val, l}; return; } int mid = (l + r) / 2; if(poz <= mid)update(node * 2, l, mid, poz, val); else update(node * 2 + 1, mid + 1, r, poz, val); seg[node] = min(seg[node * 2], seg[node * 2 + 1]); } pii query(int node, int l, int r, int levo, int desno){ if(r < levo || l > desno)return {1e15, 0}; if(l >= levo && r <= desno)return seg[node]; int mid = (l + r) / 2; pii p1 = query(node * 2, l, mid, levo, desno); pii p2 = query(node * 2 + 1, mid + 1, r, levo, desno); if(p1.xx < p2.xx)return p1; else return p2; } int main() { ios_base::sync_with_stdio(false); cin >> n; v.pb({0,0}); ff(i,0,n - 1){ cin >> x[i] >> g[i] >> d[i]; res = max(res, g[i]); if(i)d[i] += d[i - 1]; if(i)g[i] += g[i - 1]; v.pb({d[i] - x[i], g[i]}); } int m = v.size() - 1; update(1,0,n,0,0); ff(i,1,m){ ll kolko = v[i].xx; int l = 0; int r = (i-1); if(query(1,0,n,l,r).xx > kolko){ update(1,0,n,kolko,i); continue; } while(l < r){ int mid = (l + r) / 2; ll pom = query(1,0,n,0,mid).xx; if(pom <= kolko)r = mid; else l = mid + 1; } int koji = query(1,0,n,0,l).yy; res = max(res, v[i].yy - v[koji].yy); //if(koji)res = max(res, v[i].yy - v[koji-1].yy); update(1,0,n,kolko,i); } cout << res << endl; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...