답안 #172767

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
172767 2020-01-02T14:45:53 Z VEGAnn Money (IZhO17_money) C++14
100 / 100
608 ms 112900 KB
#include <bits/stdc++.h>
#define sz(x) ((int)x.size())
#define PB push_back
#define all(x) x.begin(),x.end()
using namespace std;
const int N = 1000100;
const int PW = 20;
const int oo = 2e9;
int a[N], n, f[N], kol[N], pref[N], vl, sp[N][PW], prec[N], pr[N], nt[N];
vector<int> vc;

bool ok(int l, int r){
    int kl = pref[r] - pref[l];
    if (kl > 0) return 0;
    return (a[r] <= vl);
}

int Min(int l, int r){
    int len = r - l + 1;
    return min(sp[l][prec[len]], sp[r - (1 << prec[len]) + 1][prec[len]]);
}

void update(int ps){
    sp[ps][0] = f[ps];
    for (int po = 1; po < PW; po++){
        if (ps + (1 << po) - 1 >= n) break;
        sp[ps][po] = min(sp[ps][po - 1], sp[ps + (1 << (po - 1))][po - 1]);
    }
}

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
//    freopen("in.txt","r",stdin);
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        kol[a[i]]++;
    }

    int pre = 0;
    for (int i = 1; i < N; i++){
        pr[i] = pre;
        if (kol[i] > 0)
            pre = i;
    }
    pre = N - 1;
    for (int i = pre - 1; i > 0; i--){
        nt[i] = pre;
        if (kol[i] > 0)
            pre = i;
    }

    pref[0] = 0;
    for (int i = 1; i < n; i++)
        pref[i] = pref[i - 1] + bool(a[i] < a[i - 1]);

    prec[0] = -1;
    for (int i = 1; i <= n; i++)
        prec[i] = prec[i >> 1] + 1;

    f[n] = 0;
    for (int it = n - 1; it >= 0; it--){
        kol[a[it]]--;
        if (kol[a[it]] == 0){
            pr[nt[a[it]]] = pr[a[it]];
            nt[pr[a[it]]] = nt[a[it]];
        }
        vl = nt[a[it]];

        int l = it, r = n - 1;
        while (l < r){
            int md = (l + r + 1) >> 1;
            if (ok(l, md))
                l = md;
            else r = md - 1;
        }
        f[it] = Min(it + 1, l + 1) + 1;
        update(it);
    }
    cout << f[0];
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 8184 KB Output is correct
2 Correct 11 ms 8184 KB Output is correct
3 Correct 11 ms 8184 KB Output is correct
4 Correct 11 ms 8184 KB Output is correct
5 Correct 10 ms 8184 KB Output is correct
6 Correct 11 ms 8184 KB Output is correct
7 Correct 10 ms 8184 KB Output is correct
8 Correct 10 ms 8312 KB Output is correct
9 Correct 10 ms 8184 KB Output is correct
10 Correct 10 ms 8184 KB Output is correct
11 Correct 10 ms 8184 KB Output is correct
12 Correct 10 ms 8184 KB Output is correct
13 Correct 10 ms 8184 KB Output is correct
14 Correct 10 ms 8184 KB Output is correct
15 Correct 10 ms 8360 KB Output is correct
16 Correct 10 ms 8284 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 8184 KB Output is correct
2 Correct 11 ms 8184 KB Output is correct
3 Correct 11 ms 8184 KB Output is correct
4 Correct 11 ms 8184 KB Output is correct
5 Correct 10 ms 8184 KB Output is correct
6 Correct 11 ms 8184 KB Output is correct
7 Correct 10 ms 8184 KB Output is correct
8 Correct 10 ms 8312 KB Output is correct
9 Correct 10 ms 8184 KB Output is correct
10 Correct 10 ms 8184 KB Output is correct
11 Correct 10 ms 8184 KB Output is correct
12 Correct 10 ms 8184 KB Output is correct
13 Correct 10 ms 8184 KB Output is correct
14 Correct 10 ms 8184 KB Output is correct
15 Correct 10 ms 8360 KB Output is correct
16 Correct 10 ms 8284 KB Output is correct
17 Correct 11 ms 8312 KB Output is correct
18 Correct 11 ms 8312 KB Output is correct
19 Correct 10 ms 8312 KB Output is correct
20 Correct 10 ms 8184 KB Output is correct
21 Correct 11 ms 8312 KB Output is correct
22 Correct 11 ms 8312 KB Output is correct
23 Correct 11 ms 8184 KB Output is correct
24 Correct 10 ms 8184 KB Output is correct
25 Correct 11 ms 8228 KB Output is correct
26 Correct 10 ms 8184 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 8184 KB Output is correct
2 Correct 11 ms 8184 KB Output is correct
3 Correct 11 ms 8184 KB Output is correct
4 Correct 11 ms 8184 KB Output is correct
5 Correct 10 ms 8184 KB Output is correct
6 Correct 11 ms 8184 KB Output is correct
7 Correct 10 ms 8184 KB Output is correct
8 Correct 10 ms 8312 KB Output is correct
9 Correct 10 ms 8184 KB Output is correct
10 Correct 10 ms 8184 KB Output is correct
11 Correct 10 ms 8184 KB Output is correct
12 Correct 10 ms 8184 KB Output is correct
13 Correct 10 ms 8184 KB Output is correct
14 Correct 10 ms 8184 KB Output is correct
15 Correct 10 ms 8360 KB Output is correct
16 Correct 10 ms 8284 KB Output is correct
17 Correct 11 ms 8312 KB Output is correct
18 Correct 11 ms 8312 KB Output is correct
19 Correct 10 ms 8312 KB Output is correct
20 Correct 10 ms 8184 KB Output is correct
21 Correct 11 ms 8312 KB Output is correct
22 Correct 11 ms 8312 KB Output is correct
23 Correct 11 ms 8184 KB Output is correct
24 Correct 10 ms 8184 KB Output is correct
25 Correct 11 ms 8228 KB Output is correct
26 Correct 10 ms 8184 KB Output is correct
27 Correct 11 ms 8184 KB Output is correct
28 Correct 10 ms 8184 KB Output is correct
29 Correct 10 ms 8184 KB Output is correct
30 Correct 11 ms 8184 KB Output is correct
31 Correct 11 ms 8184 KB Output is correct
32 Correct 11 ms 8312 KB Output is correct
33 Correct 11 ms 8312 KB Output is correct
34 Correct 11 ms 8312 KB Output is correct
35 Correct 11 ms 8312 KB Output is correct
36 Correct 10 ms 8184 KB Output is correct
37 Correct 11 ms 8824 KB Output is correct
38 Correct 11 ms 8824 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 8184 KB Output is correct
2 Correct 11 ms 8184 KB Output is correct
3 Correct 11 ms 8184 KB Output is correct
4 Correct 11 ms 8184 KB Output is correct
5 Correct 10 ms 8184 KB Output is correct
6 Correct 11 ms 8184 KB Output is correct
7 Correct 10 ms 8184 KB Output is correct
8 Correct 10 ms 8312 KB Output is correct
9 Correct 10 ms 8184 KB Output is correct
10 Correct 10 ms 8184 KB Output is correct
11 Correct 10 ms 8184 KB Output is correct
12 Correct 10 ms 8184 KB Output is correct
13 Correct 10 ms 8184 KB Output is correct
14 Correct 10 ms 8184 KB Output is correct
15 Correct 10 ms 8360 KB Output is correct
16 Correct 10 ms 8284 KB Output is correct
17 Correct 11 ms 8312 KB Output is correct
18 Correct 11 ms 8312 KB Output is correct
19 Correct 10 ms 8312 KB Output is correct
20 Correct 10 ms 8184 KB Output is correct
21 Correct 11 ms 8312 KB Output is correct
22 Correct 11 ms 8312 KB Output is correct
23 Correct 11 ms 8184 KB Output is correct
24 Correct 10 ms 8184 KB Output is correct
25 Correct 11 ms 8228 KB Output is correct
26 Correct 10 ms 8184 KB Output is correct
27 Correct 11 ms 8184 KB Output is correct
28 Correct 10 ms 8184 KB Output is correct
29 Correct 10 ms 8184 KB Output is correct
30 Correct 11 ms 8184 KB Output is correct
31 Correct 11 ms 8184 KB Output is correct
32 Correct 11 ms 8312 KB Output is correct
33 Correct 11 ms 8312 KB Output is correct
34 Correct 11 ms 8312 KB Output is correct
35 Correct 11 ms 8312 KB Output is correct
36 Correct 10 ms 8184 KB Output is correct
37 Correct 11 ms 8824 KB Output is correct
38 Correct 11 ms 8824 KB Output is correct
39 Correct 158 ms 53624 KB Output is correct
40 Correct 256 ms 82552 KB Output is correct
41 Correct 131 ms 44924 KB Output is correct
42 Correct 114 ms 40920 KB Output is correct
43 Correct 82 ms 31352 KB Output is correct
44 Correct 327 ms 102468 KB Output is correct
45 Correct 330 ms 102352 KB Output is correct
46 Correct 327 ms 102392 KB Output is correct
47 Correct 325 ms 102652 KB Output is correct
48 Correct 328 ms 102520 KB Output is correct
49 Correct 456 ms 106356 KB Output is correct
50 Correct 478 ms 106480 KB Output is correct
51 Correct 448 ms 106364 KB Output is correct
52 Correct 450 ms 106388 KB Output is correct
53 Correct 520 ms 106360 KB Output is correct
54 Correct 452 ms 106360 KB Output is correct
55 Correct 589 ms 106360 KB Output is correct
56 Correct 562 ms 112880 KB Output is correct
57 Correct 561 ms 112816 KB Output is correct
58 Correct 566 ms 112704 KB Output is correct
59 Correct 584 ms 112860 KB Output is correct
60 Correct 572 ms 112816 KB Output is correct
61 Correct 608 ms 112888 KB Output is correct
62 Correct 567 ms 112900 KB Output is correct