Submission #68434

# Submission time Handle Problem Language Result Execution time Memory
68434 2018-08-17T06:56:18 Z yusufake Divide and conquer (IZhO14_divide) C++
100 / 100
88 ms 19820 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 2e5;

ll F[N+N],X[N],G[N],D[N],T[N+N],t,n,i,j,ans;

ll qry(int x){
    ll t = 1LL << 55;
    for(; x ; x -= x&-x)
        t = min(t , F[x]);
    return t;
}           
                        
void up(int x, ll a){
    for(; x <= t ; x += x&-x)
        F[x] = min(F[x] , a);
}    
        
int main(){         
    scanf("%lld",&n);
    for(i=1;i<=n;i++){
        scanf("%lld%lld%lld",&X[i],&G[i],&D[i]);
        G[i] += G[i-1];
        D[i] += D[i-1];
        T[++t] = D[i]-X[i];
        T[++t] = D[i-1]-X[i];   
    }                                   
    sort(T+1 , T+t+1);                          
    memset(F , 127 , sizeof F);                         
    for(i=1;i<=n;i++){                                      
        j = lower_bound(T+1 , T+t+1 , D[i-1]-X[i]) - T;
        up(j,G[i-1]);
        j = lower_bound(T+1 , T+t+1 , D[i]-X[i]) - T;
        ans = max(ans , G[i] - qry(j)); 
    }                                       
                                                    
    printf("%lld", ans);                                    
    return 0;                                                   
}

Compilation message

divide.cpp: In function 'int main()':
divide.cpp:21:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%lld",&n);
     ~~~~~^~~~~~~~~~~
divide.cpp:23:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%lld%lld%lld",&X[i],&G[i],&D[i]);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 4 ms 3448 KB Output is correct
2 Correct 5 ms 3684 KB Output is correct
3 Correct 6 ms 3684 KB Output is correct
4 Correct 5 ms 3684 KB Output is correct
5 Correct 5 ms 3684 KB Output is correct
6 Correct 5 ms 3684 KB Output is correct
7 Correct 5 ms 3684 KB Output is correct
8 Correct 5 ms 3684 KB Output is correct
9 Correct 6 ms 3684 KB Output is correct
10 Correct 5 ms 3684 KB Output is correct
11 Correct 5 ms 3684 KB Output is correct
12 Correct 5 ms 3684 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 3768 KB Output is correct
2 Correct 4 ms 3768 KB Output is correct
3 Correct 6 ms 3812 KB Output is correct
4 Correct 5 ms 3812 KB Output is correct
5 Correct 6 ms 3812 KB Output is correct
6 Correct 5 ms 3812 KB Output is correct
7 Correct 6 ms 3812 KB Output is correct
8 Correct 6 ms 3812 KB Output is correct
9 Correct 6 ms 3820 KB Output is correct
10 Correct 6 ms 3820 KB Output is correct
11 Correct 9 ms 3948 KB Output is correct
12 Correct 10 ms 3948 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 3948 KB Output is correct
2 Correct 11 ms 4076 KB Output is correct
3 Correct 16 ms 4076 KB Output is correct
4 Correct 55 ms 5740 KB Output is correct
5 Correct 40 ms 5740 KB Output is correct
6 Correct 85 ms 7660 KB Output is correct
7 Correct 79 ms 9452 KB Output is correct
8 Correct 88 ms 11616 KB Output is correct
9 Correct 77 ms 13248 KB Output is correct
10 Correct 77 ms 14996 KB Output is correct
11 Correct 83 ms 17248 KB Output is correct
12 Correct 85 ms 19820 KB Output is correct