답안 #172761

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
172761 2020-01-02T14:36:45 Z VEGAnn Money (IZhO17_money) C++14
45 / 100
1500 ms 116880 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];
vector<int> vc;
set<int> st;
set<int>::iterator IT;

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];
        st.insert(a[i]);
        kol[a[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)
            st.erase(a[it]);
        vl = oo;
        if (sz(st)){
            IT = st.upper_bound(a[it]);
            if (IT != st.end())
                vl = *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 2 ms 380 KB Output is correct
2 Correct 2 ms 380 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 380 KB Output is correct
13 Correct 2 ms 380 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 380 KB Output is correct
2 Correct 2 ms 380 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 380 KB Output is correct
13 Correct 2 ms 380 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 0 ms 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
22 Correct 2 ms 376 KB Output is correct
23 Correct 2 ms 376 KB Output is correct
24 Correct 2 ms 376 KB Output is correct
25 Correct 2 ms 376 KB Output is correct
26 Correct 2 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 380 KB Output is correct
2 Correct 2 ms 380 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 380 KB Output is correct
13 Correct 2 ms 380 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 0 ms 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
22 Correct 2 ms 376 KB Output is correct
23 Correct 2 ms 376 KB Output is correct
24 Correct 2 ms 376 KB Output is correct
25 Correct 2 ms 376 KB Output is correct
26 Correct 2 ms 376 KB Output is correct
27 Correct 2 ms 376 KB Output is correct
28 Correct 2 ms 376 KB Output is correct
29 Correct 2 ms 376 KB Output is correct
30 Correct 2 ms 376 KB Output is correct
31 Correct 2 ms 376 KB Output is correct
32 Correct 2 ms 504 KB Output is correct
33 Correct 2 ms 504 KB Output is correct
34 Correct 2 ms 376 KB Output is correct
35 Correct 2 ms 476 KB Output is correct
36 Correct 2 ms 376 KB Output is correct
37 Correct 3 ms 1016 KB Output is correct
38 Correct 3 ms 1016 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 380 KB Output is correct
2 Correct 2 ms 380 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 380 KB Output is correct
13 Correct 2 ms 380 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 0 ms 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
22 Correct 2 ms 376 KB Output is correct
23 Correct 2 ms 376 KB Output is correct
24 Correct 2 ms 376 KB Output is correct
25 Correct 2 ms 376 KB Output is correct
26 Correct 2 ms 376 KB Output is correct
27 Correct 2 ms 376 KB Output is correct
28 Correct 2 ms 376 KB Output is correct
29 Correct 2 ms 376 KB Output is correct
30 Correct 2 ms 376 KB Output is correct
31 Correct 2 ms 376 KB Output is correct
32 Correct 2 ms 504 KB Output is correct
33 Correct 2 ms 504 KB Output is correct
34 Correct 2 ms 376 KB Output is correct
35 Correct 2 ms 476 KB Output is correct
36 Correct 2 ms 376 KB Output is correct
37 Correct 3 ms 1016 KB Output is correct
38 Correct 3 ms 1016 KB Output is correct
39 Correct 164 ms 45688 KB Output is correct
40 Correct 288 ms 74716 KB Output is correct
41 Correct 133 ms 37004 KB Output is correct
42 Correct 126 ms 32892 KB Output is correct
43 Correct 88 ms 23288 KB Output is correct
44 Correct 360 ms 94588 KB Output is correct
45 Correct 354 ms 94456 KB Output is correct
46 Correct 360 ms 94456 KB Output is correct
47 Correct 329 ms 94536 KB Output is correct
48 Correct 340 ms 94384 KB Output is correct
49 Correct 1283 ms 116880 KB Output is correct
50 Correct 1235 ms 116836 KB Output is correct
51 Correct 1296 ms 116856 KB Output is correct
52 Correct 1313 ms 116740 KB Output is correct
53 Correct 1263 ms 116804 KB Output is correct
54 Correct 1312 ms 116844 KB Output is correct
55 Execution timed out 1573 ms 78712 KB Time limit exceeded
56 Halted 0 ms 0 KB -