Submission #362744

# Submission time Handle Problem Language Result Execution time Memory
362744 2021-02-04T10:02:36 Z bigDuck Divide and conquer (IZhO14_divide) C++14
100 / 100
82 ms 25344 KB
#include<bits/stdc++.h>
using namespace std;
#define INIT  ios_base :: sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define mp make_pair
#define pb push_back
#define ft first
#define sc second
#define ll long long
#define pii pair<int, int>
#define count_bits __builtin_popcount
#define int ll

int n;
int x[100010], g[100010], d[100010];


int sum[100010];
int a[100010];
int e[100010];


int rmq[100010][21];
int lg2[100010];

void RMQ(){
    for(int i=0; i<=n;i++){
        rmq[i][0]=a[i];
    }
    for(int j=1; j<=20; j++){
        for(int i=0; (i+(1ll<<j)-1)<=n; i++){
            rmq[i][j]=min(rmq[i][j-1], rmq[i+(1ll<<(j-1) )][j-1]);
        }
    }

    int lg=0;
    for(int i=1; i<=n; i++){
        if(i>=(1<<(lg+1))){
            lg++;
        }
        lg2[i]=lg;
    }

}


int query(int l, int r){
    int lg=lg2[r-l+1];
    return min(rmq[l][lg], rmq[r-(1ll<<lg)+1][lg]);
}


int32_t main(){
INIT
cin>>n;
for(int i=1; i<=n;i++){
    cin>>x[i]>>g[i]>>d[i];
    sum[i]=sum[i-1]+g[i];
    e[i]=e[i-1]+d[i];
}

for(int i=0; i<n; i++){
    a[i]=e[i]-(x[i+1]-1);
}
a[0]=0;
RMQ();
 //cout<<a[2]<<"\n";
 //cout<<a[1]<<"\n";
int res=0;
for(int i=1; i<=n; i++){
    int l=0, r=i-1, m=(l+r)>>1ll;
    while(l<r){
        m=(l+r)>>1ll;
        if(query(0, m)<=(e[i]-x[i]) ){
            r=m;
        }
        else{
            l=(m+1);
        }
        //cout<<query(1, m)<<" "<<m<<"\n";
        m=(l+r)>>1ll;
    }

    res=max(res, sum[i]-sum[m]);

}
cout<<res;



return 0;
}



# Verdict Execution time Memory Grader output
1 Correct 1 ms 512 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 384 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 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 512 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 384 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 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 492 KB Output is correct
16 Correct 1 ms 492 KB Output is correct
17 Correct 1 ms 620 KB Output is correct
18 Correct 1 ms 620 KB Output is correct
19 Correct 1 ms 620 KB Output is correct
20 Correct 1 ms 620 KB Output is correct
21 Correct 1 ms 748 KB Output is correct
22 Correct 2 ms 876 KB Output is correct
23 Correct 3 ms 1644 KB Output is correct
24 Correct 3 ms 1644 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 512 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 384 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 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 492 KB Output is correct
16 Correct 1 ms 492 KB Output is correct
17 Correct 1 ms 620 KB Output is correct
18 Correct 1 ms 620 KB Output is correct
19 Correct 1 ms 620 KB Output is correct
20 Correct 1 ms 620 KB Output is correct
21 Correct 1 ms 748 KB Output is correct
22 Correct 2 ms 876 KB Output is correct
23 Correct 3 ms 1644 KB Output is correct
24 Correct 3 ms 1644 KB Output is correct
25 Correct 3 ms 1516 KB Output is correct
26 Correct 6 ms 2688 KB Output is correct
27 Correct 6 ms 2796 KB Output is correct
28 Correct 35 ms 12396 KB Output is correct
29 Correct 36 ms 12652 KB Output is correct
30 Correct 82 ms 25344 KB Output is correct
31 Correct 74 ms 24044 KB Output is correct
32 Correct 77 ms 24044 KB Output is correct
33 Correct 73 ms 23916 KB Output is correct
34 Correct 76 ms 23904 KB Output is correct
35 Correct 79 ms 24428 KB Output is correct
36 Correct 82 ms 24556 KB Output is correct