Submission #339441

# Submission time Handle Problem Language Result Execution time Memory
339441 2020-12-25T10:13:01 Z Dilshod_Imomov Money (IZhO17_money) C++17
100 / 100
1012 ms 48108 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 = 2e6 + 7;
const int mod = 1e9 + 7;

int a[N], t[4 * N], lz[4 * N];

void push( int v ) {
    lz[v * 2] += lz[v];
    lz[v * 2 + 1] += lz[v];
    t[v * 2] += lz[v];
    t[v * 2 + 1] += lz[v];
    lz[v] = 0;
}

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

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

int32_t main() {
    speed;
    int n;
    cin >> n;
    for ( int i = 1; i <= n; i++ ) {
        cin >> a[i];
    }
    int ans = 0;
    for ( int i = 1; i <= n; i++ ) {
        int l = i, r = i;
        while ( a[r + 1] >= a[r] && get( 1, 1, N - 1, a[l] + 1, a[r + 1] - 1 ) == 0 ) {
            r++;
        }
        while ( l <= r ) {
            upd( 1, 1, N - 1, a[l++] );
        }
        i = r;
        ans++;
    }
    cout << ans;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 492 KB Output is correct
2 Correct 1 ms 492 KB Output is correct
3 Correct 1 ms 492 KB Output is correct
4 Correct 1 ms 492 KB Output is correct
5 Correct 1 ms 492 KB Output is correct
6 Correct 1 ms 492 KB Output is correct
7 Correct 1 ms 748 KB Output is correct
8 Correct 1 ms 640 KB Output is correct
9 Correct 1 ms 748 KB Output is correct
10 Correct 1 ms 768 KB Output is correct
11 Correct 1 ms 748 KB Output is correct
12 Correct 1 ms 748 KB Output is correct
13 Correct 1 ms 620 KB Output is correct
14 Correct 1 ms 620 KB Output is correct
15 Correct 1 ms 876 KB Output is correct
16 Correct 1 ms 876 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 492 KB Output is correct
2 Correct 1 ms 492 KB Output is correct
3 Correct 1 ms 492 KB Output is correct
4 Correct 1 ms 492 KB Output is correct
5 Correct 1 ms 492 KB Output is correct
6 Correct 1 ms 492 KB Output is correct
7 Correct 1 ms 748 KB Output is correct
8 Correct 1 ms 640 KB Output is correct
9 Correct 1 ms 748 KB Output is correct
10 Correct 1 ms 768 KB Output is correct
11 Correct 1 ms 748 KB Output is correct
12 Correct 1 ms 748 KB Output is correct
13 Correct 1 ms 620 KB Output is correct
14 Correct 1 ms 620 KB Output is correct
15 Correct 1 ms 876 KB Output is correct
16 Correct 1 ms 876 KB Output is correct
17 Correct 1 ms 876 KB Output is correct
18 Correct 1 ms 876 KB Output is correct
19 Correct 1 ms 876 KB Output is correct
20 Correct 1 ms 748 KB Output is correct
21 Correct 1 ms 876 KB Output is correct
22 Correct 1 ms 620 KB Output is correct
23 Correct 1 ms 620 KB Output is correct
24 Correct 1 ms 640 KB Output is correct
25 Correct 1 ms 1388 KB Output is correct
26 Correct 1 ms 1260 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 492 KB Output is correct
2 Correct 1 ms 492 KB Output is correct
3 Correct 1 ms 492 KB Output is correct
4 Correct 1 ms 492 KB Output is correct
5 Correct 1 ms 492 KB Output is correct
6 Correct 1 ms 492 KB Output is correct
7 Correct 1 ms 748 KB Output is correct
8 Correct 1 ms 640 KB Output is correct
9 Correct 1 ms 748 KB Output is correct
10 Correct 1 ms 768 KB Output is correct
11 Correct 1 ms 748 KB Output is correct
12 Correct 1 ms 748 KB Output is correct
13 Correct 1 ms 620 KB Output is correct
14 Correct 1 ms 620 KB Output is correct
15 Correct 1 ms 876 KB Output is correct
16 Correct 1 ms 876 KB Output is correct
17 Correct 1 ms 876 KB Output is correct
18 Correct 1 ms 876 KB Output is correct
19 Correct 1 ms 876 KB Output is correct
20 Correct 1 ms 748 KB Output is correct
21 Correct 1 ms 876 KB Output is correct
22 Correct 1 ms 620 KB Output is correct
23 Correct 1 ms 620 KB Output is correct
24 Correct 1 ms 640 KB Output is correct
25 Correct 1 ms 1388 KB Output is correct
26 Correct 1 ms 1260 KB Output is correct
27 Correct 1 ms 492 KB Output is correct
28 Correct 1 ms 492 KB Output is correct
29 Correct 1 ms 512 KB Output is correct
30 Correct 1 ms 492 KB Output is correct
31 Correct 1 ms 492 KB Output is correct
32 Correct 2 ms 876 KB Output is correct
33 Correct 1 ms 748 KB Output is correct
34 Correct 1 ms 1024 KB Output is correct
35 Correct 1 ms 620 KB Output is correct
36 Correct 1 ms 748 KB Output is correct
37 Correct 4 ms 6508 KB Output is correct
38 Correct 4 ms 6508 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 492 KB Output is correct
2 Correct 1 ms 492 KB Output is correct
3 Correct 1 ms 492 KB Output is correct
4 Correct 1 ms 492 KB Output is correct
5 Correct 1 ms 492 KB Output is correct
6 Correct 1 ms 492 KB Output is correct
7 Correct 1 ms 748 KB Output is correct
8 Correct 1 ms 640 KB Output is correct
9 Correct 1 ms 748 KB Output is correct
10 Correct 1 ms 768 KB Output is correct
11 Correct 1 ms 748 KB Output is correct
12 Correct 1 ms 748 KB Output is correct
13 Correct 1 ms 620 KB Output is correct
14 Correct 1 ms 620 KB Output is correct
15 Correct 1 ms 876 KB Output is correct
16 Correct 1 ms 876 KB Output is correct
17 Correct 1 ms 876 KB Output is correct
18 Correct 1 ms 876 KB Output is correct
19 Correct 1 ms 876 KB Output is correct
20 Correct 1 ms 748 KB Output is correct
21 Correct 1 ms 876 KB Output is correct
22 Correct 1 ms 620 KB Output is correct
23 Correct 1 ms 620 KB Output is correct
24 Correct 1 ms 640 KB Output is correct
25 Correct 1 ms 1388 KB Output is correct
26 Correct 1 ms 1260 KB Output is correct
27 Correct 1 ms 492 KB Output is correct
28 Correct 1 ms 492 KB Output is correct
29 Correct 1 ms 512 KB Output is correct
30 Correct 1 ms 492 KB Output is correct
31 Correct 1 ms 492 KB Output is correct
32 Correct 2 ms 876 KB Output is correct
33 Correct 1 ms 748 KB Output is correct
34 Correct 1 ms 1024 KB Output is correct
35 Correct 1 ms 620 KB Output is correct
36 Correct 1 ms 748 KB Output is correct
37 Correct 4 ms 6508 KB Output is correct
38 Correct 4 ms 6508 KB Output is correct
39 Correct 267 ms 7916 KB Output is correct
40 Correct 496 ms 12780 KB Output is correct
41 Correct 221 ms 6380 KB Output is correct
42 Correct 210 ms 6656 KB Output is correct
43 Correct 149 ms 4972 KB Output is correct
44 Correct 569 ms 15724 KB Output is correct
45 Correct 547 ms 15468 KB Output is correct
46 Correct 588 ms 15724 KB Output is correct
47 Correct 547 ms 15340 KB Output is correct
48 Correct 510 ms 15468 KB Output is correct
49 Correct 808 ms 47980 KB Output is correct
50 Correct 786 ms 47980 KB Output is correct
51 Correct 808 ms 47852 KB Output is correct
52 Correct 793 ms 48108 KB Output is correct
53 Correct 787 ms 48060 KB Output is correct
54 Correct 779 ms 47852 KB Output is correct
55 Correct 989 ms 47980 KB Output is correct
56 Correct 989 ms 47980 KB Output is correct
57 Correct 987 ms 47980 KB Output is correct
58 Correct 972 ms 47980 KB Output is correct
59 Correct 982 ms 47980 KB Output is correct
60 Correct 975 ms 47980 KB Output is correct
61 Correct 993 ms 47980 KB Output is correct
62 Correct 1012 ms 47980 KB Output is correct