Submission #337919

# Submission time Handle Problem Language Result Execution time Memory
337919 2020-12-22T05:58:43 Z Dilshod_Imomov Divide and conquer (IZhO14_divide) C++17
100 / 100
209 ms 60524 KB
# include <bits/stdc++.h>
# define speed ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
# define int long long
# define fi first
# define se second

using namespace std;

const int N = 1e6 + 7;
const int mod = 1e9 + 7;

int x[N], g[N], d[N], psg[N], psd[N], t[4 * N];

void upd( int v, int l, int r, int pos, int val ) {
    if ( l == r ) {
        t[v] = min( t[v], val );
        return;
    }
    int m = (l + r) / 2;
    if ( pos <= m ) {
        upd( v * 2, l, m, pos, val );
    }
    else {
        upd( v * 2 + 1, m + 1, r, pos, val );
    }
    t[v] = min( t[v * 2], t[v * 2 + 1] );
}

int get( int v, int l, int r, int tl, int tr ) {
    if ( tl > tr ) {
        return 1e18;
    }
    if ( tl == l && tr == r ) {
        return t[v];
    }
    int m = (l + r) / 2;
    int mn = get( v * 2, l, m, tl, min( tr, m ) );
    mn = min( mn, get( v * 2 + 1, m + 1, r, max( m + 1, tl ), tr ) );
    return mn;
}

int32_t main() {
    speed;
    for ( int i = 0; i < 4 * N; i++ ) {
        t[i] = 1e18;
    }
    int n;
    cin >> n;
    for ( int i = 1; i <= n; i++ ) {
        cin >> x[i] >> g[i] >> d[i];
        psg[i] = psg[i - 1] + g[i];
        psd[i] = psd[i - 1] + d[i];
    }
    int ans = 0, cnt = 1;
    set < int > st;
    map < int, int > mp, mp1;
    for ( int i = 1; i <= n; i++ ) {
        st.insert( x[i] - psd[i] );
        st.insert( x[i] - psd[i - 1] );
    }
    for ( auto i: st ) {
        // cout << i << ' ' << cnt << endl;
        mp[i] = cnt++;
    }
    for ( int i = 1; i <= n; i++ ) {
        int a = mp[x[i] - psd[i]];
        upd( 1, 1, cnt, mp[x[i] - psd[i - 1]], psg[i - 1] );
        // cout << "-> " << x[i] - psd[i - 1] << ' ' << mp[ x[i] - psd[i - 1] ] << ' ' << psg[i] << endl;
        // cout << i << ' ' << a << ' ' << get( 1, 1, cnt, a, cnt ) << endl;
        ans = max( ans, psg[i] - get( 1, 1, cnt, a, cnt ) );
    }
    cout << ans;
}
# Verdict Execution time Memory Grader output
1 Correct 19 ms 31724 KB Output is correct
2 Correct 19 ms 31724 KB Output is correct
3 Correct 19 ms 31724 KB Output is correct
4 Correct 19 ms 31724 KB Output is correct
5 Correct 19 ms 31724 KB Output is correct
6 Correct 19 ms 31724 KB Output is correct
7 Correct 19 ms 31724 KB Output is correct
8 Correct 19 ms 31724 KB Output is correct
9 Correct 19 ms 31724 KB Output is correct
10 Correct 18 ms 31724 KB Output is correct
11 Correct 19 ms 31724 KB Output is correct
12 Correct 19 ms 31724 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 19 ms 31724 KB Output is correct
2 Correct 19 ms 31724 KB Output is correct
3 Correct 19 ms 31724 KB Output is correct
4 Correct 19 ms 31724 KB Output is correct
5 Correct 19 ms 31724 KB Output is correct
6 Correct 19 ms 31724 KB Output is correct
7 Correct 19 ms 31724 KB Output is correct
8 Correct 19 ms 31724 KB Output is correct
9 Correct 19 ms 31724 KB Output is correct
10 Correct 18 ms 31724 KB Output is correct
11 Correct 19 ms 31724 KB Output is correct
12 Correct 19 ms 31724 KB Output is correct
13 Correct 19 ms 31724 KB Output is correct
14 Correct 19 ms 31724 KB Output is correct
15 Correct 19 ms 31852 KB Output is correct
16 Correct 20 ms 31852 KB Output is correct
17 Correct 20 ms 31980 KB Output is correct
18 Correct 21 ms 31980 KB Output is correct
19 Correct 20 ms 31980 KB Output is correct
20 Correct 22 ms 31980 KB Output is correct
21 Correct 21 ms 32108 KB Output is correct
22 Correct 25 ms 32236 KB Output is correct
23 Correct 26 ms 33132 KB Output is correct
24 Correct 26 ms 33132 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 19 ms 31724 KB Output is correct
2 Correct 19 ms 31724 KB Output is correct
3 Correct 19 ms 31724 KB Output is correct
4 Correct 19 ms 31724 KB Output is correct
5 Correct 19 ms 31724 KB Output is correct
6 Correct 19 ms 31724 KB Output is correct
7 Correct 19 ms 31724 KB Output is correct
8 Correct 19 ms 31724 KB Output is correct
9 Correct 19 ms 31724 KB Output is correct
10 Correct 18 ms 31724 KB Output is correct
11 Correct 19 ms 31724 KB Output is correct
12 Correct 19 ms 31724 KB Output is correct
13 Correct 19 ms 31724 KB Output is correct
14 Correct 19 ms 31724 KB Output is correct
15 Correct 19 ms 31852 KB Output is correct
16 Correct 20 ms 31852 KB Output is correct
17 Correct 20 ms 31980 KB Output is correct
18 Correct 21 ms 31980 KB Output is correct
19 Correct 20 ms 31980 KB Output is correct
20 Correct 22 ms 31980 KB Output is correct
21 Correct 21 ms 32108 KB Output is correct
22 Correct 25 ms 32236 KB Output is correct
23 Correct 26 ms 33132 KB Output is correct
24 Correct 26 ms 33132 KB Output is correct
25 Correct 28 ms 33132 KB Output is correct
26 Correct 33 ms 34412 KB Output is correct
27 Correct 34 ms 34540 KB Output is correct
28 Correct 102 ms 45548 KB Output is correct
29 Correct 105 ms 45932 KB Output is correct
30 Correct 209 ms 60524 KB Output is correct
31 Correct 202 ms 59244 KB Output is correct
32 Correct 196 ms 59372 KB Output is correct
33 Correct 197 ms 59116 KB Output is correct
34 Correct 197 ms 58476 KB Output is correct
35 Correct 199 ms 59660 KB Output is correct
36 Correct 197 ms 59884 KB Output is correct