Submission #1173370

#TimeUsernameProblemLanguageResultExecution timeMemory
1173370iamhereforfunDivide and conquer (IZhO14_divide)C++20
100 / 100
45 ms6648 KiB
// IamHereForFun // #include <bits/stdc++.h> using namespace std; #define LSOne(S) ((S) & -(S)) const int N = 1e5 + 5; const int Q = 2e5 + 5; const int M = 1e6 + 5; const int LG = 18; const int P = 31; const long long INF = 4e18; const int MOD = 1e9; class Fenwick { private: vector<long long> ft; int n; public: Fenwick(int len) { n = len; ft.assign(n + 1, INF); } void updFt(int pos, long long val) { while(pos <= n) { ft[pos] = min(ft[pos], val); pos += LSOne(pos); } } long long getMin(int pos) { long long ans = INF; while(pos > 0) { ans = min(ans, ft[pos]); pos -= LSOne(pos); } return ans; } }; int n; long long pref[N], ans = 0; array<long long, 3> mine[N]; vector<long long> vec; int getIdx(long long a) { return lower_bound(vec.begin(), vec.end(), a) - vec.begin() + 1; } void prtSolve() { cin >> n; for (int x = 0; x < n; x++) { cin >> mine[x][0] >> mine[x][1] >> mine[x][2]; if(mine[x][2] >= 1) ans = max(ans, mine[x][1]); } sort(mine, mine + n); pref[0] = mine[0][2]; for (int x = 1; x < n; x++) { pref[x] = pref[x - 1] + mine[x][2]; } for(int x = 0; x < n - 1; x++) { vec.push_back(pref[x] - mine[x + 1][0]); vec.push_back(pref[x + 1] - mine[x + 1][0]); // cout << vec.back() << "\n"; } vec.push_back(mine[0][0]); sort(vec.begin(), vec.end()); vec.erase(unique(vec.begin(), vec.end()), vec.end()); Fenwick ft(vec.size()); long long sum = 0; ft.updFt(getIdx(mine[0][0]), 0); sum = mine[0][1]; for(int x = 0; x < n - 1; x++) { sum += mine[x + 1][1]; // cout << sum << " " << ft.getMin(getIdx(pref[x + 1] - mine[x + 1][0])) << " " << pref[x] - mine[x + 1][0] << "\n"; ans = max(ans, sum - ft.getMin(getIdx(pref[x + 1] - mine[x + 1][0]))); ft.updFt(getIdx(pref[x] - mine[x + 1][0]), sum - mine[x + 1][1]); } cout << ans; } signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t = 1; // cin >> t; for (int x = 1; x <= t; x++) { prtSolve(); } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...