Submission #20789

#TimeUsernameProblemLanguageResultExecution timeMemory
20789jjwdi0Divide and conquer (IZhO14_divide)C++11
100 / 100
73 ms7272 KiB
#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); for(int i=1; i<base*2; i++) tree[i] = INF; }
    void update(int x, int y) {
        x += base - 1;
        if(tree[x] < y) return;
        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);
        ans = max(ans, Gsum[i] - Gsum[min(i - 1, midx)]);
    }
    printf("%lld\n", ans);
}

Compilation message (stderr)

divide.cpp: In function 'int main()':
divide.cpp:43:20: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &N);
                    ^
divide.cpp:45: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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...