Submission #357740

# Submission time Handle Problem Language Result Execution time Memory
357740 2021-01-24T15:04:02 Z nicolaalexandra Divide and conquer (IZhO14_divide) C++14
100 / 100
150 ms 6892 KB
#include <bits/stdc++.h>
#define DIM 100010
#define INF 2000000000000000000LL
using namespace std;

long long aint[DIM*5],sp[DIM],sp_g[DIM];
int n,i,x,sol;

void build (int nod, int st, int dr){
    if (st == dr){
        aint[nod] = INF;
        return;
    }
    int mid = (st+dr)>>1;
    build (nod<<1,st,mid);
    build ((nod<<1)|1,mid+1,dr);
    aint[nod] = INF;
}

void update (int nod, int st, int dr, int poz, long long val){
    if (st == dr){
        aint[nod] = val;
        return;
    }
    int mid = (st+dr)>>1;
    if (poz <= mid)
        update (nod<<1,st,mid,poz,val);
    else update ((nod<<1)|1,mid+1,dr,poz,val);

    aint[nod] = min (aint[nod<<1],aint[(nod<<1)|1]);
}

void query (int nod, int st, int dr, int x, int y, long long val){
    if (sol)
        return;
    if (x <= st && dr <= y){

        if (aint[nod] <= val){

            if (st == dr)
                sol = st;
            else {
                int mid = (st+dr)>>1;
                if (aint[nod<<1] <= val)
                    query (nod<<1,st,mid,x,y,val);
                else query ((nod<<1)|1,mid+1,dr,x,y,val);
            }

        }

        return;
    }

    int mid = (st+dr)>>1;
    if (x <= mid)
        query (nod<<1,st,mid,x,y,val);
    if (y > mid)
        query ((nod<<1)|1,mid+1,dr,x,y,val);
}

int main (){

    //ifstream cin ("date.in");
    //ofstream cout ("date.out");

    cin>>n;

    build (1,1,n);

    long long ans = 0;
    for (i=1;i<=n;i++){
        cin>>x>>sp_g[i]>>sp[i];
        sp[i] += sp[i-1];
        sp_g[i] += sp_g[i-1];

        update (1,1,n,i,sp[i-1] - x);

        sol = 0;
        query (1,1,n,1,i,sp[i] - x);
        if (sol)
            ans = max (ans,sp_g[i] - sp_g[sol-1]);
    }

    cout<<ans;

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 376 KB Output is correct
13 Correct 1 ms 380 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 2 ms 364 KB Output is correct
18 Correct 2 ms 364 KB Output is correct
19 Correct 2 ms 364 KB Output is correct
20 Correct 2 ms 364 KB Output is correct
21 Correct 2 ms 364 KB Output is correct
22 Correct 3 ms 492 KB Output is correct
23 Correct 8 ms 748 KB Output is correct
24 Correct 9 ms 748 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 376 KB Output is correct
13 Correct 1 ms 380 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 2 ms 364 KB Output is correct
18 Correct 2 ms 364 KB Output is correct
19 Correct 2 ms 364 KB Output is correct
20 Correct 2 ms 364 KB Output is correct
21 Correct 2 ms 364 KB Output is correct
22 Correct 3 ms 492 KB Output is correct
23 Correct 8 ms 748 KB Output is correct
24 Correct 9 ms 748 KB Output is correct
25 Correct 5 ms 620 KB Output is correct
26 Correct 9 ms 876 KB Output is correct
27 Correct 11 ms 876 KB Output is correct
28 Correct 63 ms 3180 KB Output is correct
29 Correct 70 ms 3436 KB Output is correct
30 Correct 150 ms 6892 KB Output is correct
31 Correct 133 ms 5740 KB Output is correct
32 Correct 114 ms 5740 KB Output is correct
33 Correct 109 ms 5600 KB Output is correct
34 Correct 115 ms 5748 KB Output is correct
35 Correct 133 ms 6124 KB Output is correct
36 Correct 141 ms 6252 KB Output is correct