Submission #1035928

#TimeUsernameProblemLanguageResultExecution timeMemory
1035928peraDivide and conquer (IZhO14_divide)C++17
17 / 100
3 ms5980 KiB
#include<bits/stdc++.h> #define int long long using namespace std; const int N = 1e5 + 1; int n , ans = 0 , SZ; vector<int> x(N) , g(N) , e(N) , sum_e(N) , sum_g(N) , h(N) , t(N); void upd(int u , int x){ assert(u <= SZ); while(u <= SZ){ t[u] = min(t[u] , x); u += u&-u; } } int GET(int u){ assert(u <= SZ); int val = 1e18; while(u > 0){ val = min(val , t[u]); u -= u&-u; } return val; } void solve(int l , int r){ if(l > r){ return; } SZ = r - l + 1; int m = (l + r) / 2; for(int i = l;i <= r;i ++){ sum_e[i] = sum_e[i - 1] + e[i]; sum_g[i] = sum_g[i - 1] + g[i]; } vector<pair<int , int>> v , u; for(int i = l;i <= r;i ++){ if(i < m){ v.push_back({x[i - 1] - sum_e[i - 1] , i}); u.push_back({sum_e[i - 1] - x[i] , i}); }else{ v.push_back({x[i + 1] - sum_e[i] , i}); u.push_back({sum_e[i] - x[i] , i}); } } sort(v.begin() , v.end()); sort(u.begin() , u.end()); for(int i = 0;i < (int)u.size();i ++){ h[u[i].second] = (i == 0 ? 1 : h[u[i - 1].second] + (u[i].first != u[i - 1].first)); } int mx = 0; for(auto [_value , id] : v){ //cout << id << " " << h[id] << " " << sum_g[id - 1] << endl; if(id < m){ upd(h[id] , sum_g[id - 1]); }else{ ans = max(ans , sum_g[id] - GET(h[id])); if(x[id + 1] - x[m - 1] >= sum_e[id] - sum_e[m - 1] && sum_e[id] - sum_e[m - 1] > x[id] - x[m]){ ans = max(ans , sum_g[id] - sum_g[m - 1]); } } } // cout << endl; for(int i = l;i <= r;i ++){ sum_e[i] = sum_g[i] = h[i] = 0; } for(int i = 1;i <= r - l + 1;i ++){ t[i] = 1e18; } //cout << l << " " << m << " " << r << " " << mx << endl; solve(l , m - 1); solve(m + 1 , r); } main(){ cin >> n; for(int i = 1;i <= n;i ++){ cin >> x[i] >> g[i] >> e[i]; t[i] = 1e18; } x[n + 1] = 1e10; x[0] = -1e9; solve(1 , n); /*for(int L = 1;L <= n;L ++){ for(int R = L;R <= n;R ++){ int s = 0 , se = 0; for(int i = L;i <= R;i ++){ se += e[i]; s += g[i]; } if(x[R + 1] - x[L - 1] >= se && se > x[R] - x[L]){ ans = max(ans , s); } } }*/ cout << ans << endl; }

Compilation message (stderr)

divide.cpp: In function 'void solve(long long int, long long int)':
divide.cpp:48:8: warning: unused variable 'mx' [-Wunused-variable]
   48 |    int mx = 0;
      |        ^~
divide.cpp: At global scope:
divide.cpp:71:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   71 | main(){
      | ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...