답안 #339439

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
339439 2020-12-25T10:04:42 Z Dilshod_Imomov Money (IZhO17_money) C++17
0 / 100
1 ms 620 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 tl, int tr, int l, int r ) {
    if ( l > r ) {
        return;
    }
    if ( tl == l && tr == r ) {
        t[v]++;
        lz[v]++;
        return;
    } 
    int m = (tl + tr) / 2;
    push(v);
    upd( v * 2, tl, m, l, min( m, r ) );
    upd( v * 2 + 1, m + 1, tr, max( m + 1, l ), r );
    t[v] = t[v * 2] + t[v * 2 + 1];
}

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

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[r + 1] - 1 ) - get( 1, 1, N - 1, a[l] ) == 0 ) {
            r++;
        }
        while ( l <= r ) {
            upd( 1, 1, N - 1, a[l++], N - 1 );
        }
        i = r;
        ans++;
    }
    cout << ans;
}
# 결과 실행 시간 메모리 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 620 KB Output is correct
8 Incorrect 1 ms 620 KB Output isn't correct
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 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 620 KB Output is correct
8 Incorrect 1 ms 620 KB Output isn't correct
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 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 620 KB Output is correct
8 Incorrect 1 ms 620 KB Output isn't correct
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 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 620 KB Output is correct
8 Incorrect 1 ms 620 KB Output isn't correct
9 Halted 0 ms 0 KB -