Submission #37020

#TimeUsernameProblemLanguageResultExecution timeMemory
37020nickyrioDivide and conquer (IZhO14_divide)C++14
100 / 100
73 ms42740 KiB
#include <bits/stdc++.h> #define FOR(i, a, b) for (int i = a; i<= b; ++i) #define FORD(i, a, b) for (int i = a; i>=b; --i) #define REP(i, a) for (int i = 0; i<a; ++i) #define N 1001000 #define pp pair<int, int> #define bit(S, i) (((S) >> i) & 1) #define IO cin.tie(NULL);cout.tie(NULL); #define taskname "Test" #define all(s) s.begin(), s.end() using namespace std; long long g[N], dp[N], d[N], x[N], BIT[N]; vector<long long> ranking; int n; void UpBIT(int u, long long val) { for(; u > 0; u -= u & -u) BIT[u] = max(BIT[u], val); } long long GetBIT(int u) { long long ans = -1e18; for(; u <= n; u += u & -u) ans = max(ans, BIT[u]); return ans; } int main() { //freopen(taskname".inp","r",stdin); //freopen(taskname".out","w",stdout); IO; scanf("%d", &n); FOR(i, 1, n) scanf("%lld %lld %lld", &x[i], &g[i], &d[i]); FOR(i, 1, n) { g[i] += g[i - 1]; d[i] += d[i - 1]; ranking.push_back(x[i] - d[i - 1]); } sort(all(ranking)); ranking.resize(distance(ranking.begin(), unique(all(ranking)))); // for (long long x : ranking) printf("%lld ", x ); putchar('\n'); FOR(i, 1, n) BIT[i] = -1e18; int pos = lower_bound(all(ranking), x[1]) - ranking.begin() + 1; UpBIT(pos, 0); FOR(i, 1, n) { int pos = lower_bound(all(ranking), x[i] - d[i]) - ranking.begin() + 1; // printf("%lld ", x[i] - d[i] + 1); dp[i] = max(dp[i - 1], GetBIT(pos) + g[i]); // printf("%lld ", dp[i]); if (i == n) break; pos = upper_bound(all(ranking), x[i + 1] - d[i]) - ranking.begin(); UpBIT(pos, - g[i]); } printf("%lld", dp[n]); }

Compilation message (stderr)

divide.cpp: In function 'int main()':
divide.cpp:31:20: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &n);
                    ^
divide.cpp:32:62: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     FOR(i, 1, n) scanf("%lld %lld %lld", &x[i], &g[i], &d[i]);
                                                              ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...