Submission #37020

# Submission time Handle Problem Language Result Execution time Memory
37020 2017-12-20T13:38:45 Z nickyrio Divide and conquer (IZhO14_divide) C++14
100 / 100
73 ms 42740 KB
#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

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 time Memory Grader output
1 Correct 0 ms 41120 KB Output is correct
2 Correct 0 ms 41120 KB Output is correct
3 Correct 0 ms 41120 KB Output is correct
4 Correct 0 ms 41120 KB Output is correct
5 Correct 0 ms 41120 KB Output is correct
6 Correct 0 ms 41120 KB Output is correct
7 Correct 0 ms 41120 KB Output is correct
8 Correct 0 ms 41120 KB Output is correct
9 Correct 0 ms 41120 KB Output is correct
10 Correct 0 ms 41120 KB Output is correct
11 Correct 0 ms 41120 KB Output is correct
12 Correct 0 ms 41120 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 41120 KB Output is correct
2 Correct 0 ms 41120 KB Output is correct
3 Correct 0 ms 41120 KB Output is correct
4 Correct 0 ms 41120 KB Output is correct
5 Correct 0 ms 41120 KB Output is correct
6 Correct 0 ms 41120 KB Output is correct
7 Correct 0 ms 41120 KB Output is correct
8 Correct 0 ms 41120 KB Output is correct
9 Correct 0 ms 41120 KB Output is correct
10 Correct 0 ms 41120 KB Output is correct
11 Correct 3 ms 41260 KB Output is correct
12 Correct 3 ms 41260 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 41260 KB Output is correct
2 Correct 6 ms 41392 KB Output is correct
3 Correct 6 ms 41392 KB Output is correct
4 Correct 36 ms 41972 KB Output is correct
5 Correct 29 ms 41972 KB Output is correct
6 Correct 66 ms 42740 KB Output is correct
7 Correct 63 ms 42740 KB Output is correct
8 Correct 73 ms 42740 KB Output is correct
9 Correct 56 ms 42740 KB Output is correct
10 Correct 69 ms 42740 KB Output is correct
11 Correct 66 ms 42740 KB Output is correct
12 Correct 66 ms 42740 KB Output is correct