Submission #20787

# Submission time Handle Problem Language Result Execution time Memory
20787 2017-02-16T04:13:00 Z jjwdi0 Divide and conquer (IZhO14_divide) C++11
0 / 100
73 ms 7272 KB
#include <bits/stdc++.h>
#define INF 987654321
using namespace std;
typedef long long ll;

struct Mine {
    int x, g, d;
}A[100005];

struct seg_tree {
    int tree[444444], base;
    void init(int x) { for(base = 1; base < x; base <<= 1); }
    void update(int x, int y) {
        x += base - 1;
        tree[x] = y;
        x >>= 1;
        while(x) {
            tree[x] = min(tree[x*2], tree[x*2+1]);
            x >>= 1;
        }
    }
    int RMQ(int s, int e) {
        s += base - 1, e += base - 1;
        int res = INF;
        while(s < e) {
            if(s & 1) res = min(res, tree[s++]);
            if(!(e & 1)) res = min(res, tree[e--]);
            s >>= 1, e >>= 1;
        }
        if(s == e) res = min(res, tree[s]);
        return res;
    }
}S;

int N;
ll ans, Gsum[100005], Dsum[100005];
ll idx[100005];

int find_idx(ll x) { return lower_bound(idx + 1, idx + N + 1, x) - idx; }

int main() {
    scanf("%d", &N);
    S.init(N);
    for(int i=1; i<=N; i++) scanf("%d %d %d", &A[i].x, &A[i].g, &A[i].d);
    for(int i=1; i<=N; i++) {
        Gsum[i] += Gsum[i-1] + (ll)A[i].g;
        Dsum[i] += Dsum[i-1] + (ll)A[i].d;
    }
    for(int i=1; i<=N; i++) idx[i] = (ll)A[i].x - Dsum[i-1];
    sort(idx + 1, idx + N + 1);
    ans = A[1].g;
    for(int i=1; i<=N; i++) {
        S.update(find_idx(A[i].x - Dsum[i-1]), i - 1);
        int midx = find_idx(A[i].x - Dsum[i]);
        midx = S.RMQ(midx, N);
        if(midx == INF) ans = max(ans, Gsum[i] - Gsum[i - 1]);
        else ans = max(ans, Gsum[i] - Gsum[midx]);
    }
    printf("%lld\n", ans);
}

Compilation message

divide.cpp: In function 'int main()':
divide.cpp:42:20: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &N);
                    ^
divide.cpp:44:73: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     for(int i=1; i<=N; i++) scanf("%d %d %d", &A[i].x, &A[i].g, &A[i].d);
                                                                         ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 7272 KB Output is correct
2 Incorrect 0 ms 7272 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 7272 KB Output is correct
2 Correct 0 ms 7272 KB Output is correct
3 Incorrect 0 ms 7272 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 7272 KB Output is correct
2 Correct 0 ms 7272 KB Output is correct
3 Correct 6 ms 7272 KB Output is correct
4 Correct 33 ms 7272 KB Output is correct
5 Correct 29 ms 7272 KB Output is correct
6 Correct 73 ms 7272 KB Output is correct
7 Correct 49 ms 7272 KB Output is correct
8 Correct 59 ms 7272 KB Output is correct
9 Correct 53 ms 7272 KB Output is correct
10 Incorrect 59 ms 7272 KB Output isn't correct
11 Halted 0 ms 0 KB -