답안 #172763

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
172763 2020-01-02T14:41:12 Z VEGAnn Money (IZhO17_money) C++14
45 / 100
1500 ms 61868 KB
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("-O3")
#pragma GCC optimize("Ofast")
#define sz(x) ((int)x.size())
#define PB push_back
#define all(x) x.begin(),x.end()
using namespace std;
const int N = (1 << 20);
const int oo = 2e9;
int a[N], n, f[N], kol[N], pref[N], vl, sg[2 * 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){
    l += N; r += N;
    int res = oo;
    while (l <= r){
        res = min(res, sg[l]);
        res = min(res, sg[r]);
        l = (l + 1) >> 1;
        r = (r - 1) >> 1;
    }
    return res;
}
 
void update(int ps){
    ps += N;
    sg[ps] = f[ps - N];
    ps >>= 1;
    for (; ps > 0; ps >>= 1)
        sg[ps] = min(sg[ps + ps + 1], sg[ps + ps]);
}
 
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]);
 
    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 376 KB Output is correct
2 Correct 2 ms 504 KB Output is correct
3 Correct 2 ms 380 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 1 ms 504 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 504 KB Output is correct
11 Correct 2 ms 504 KB Output is correct
12 Correct 2 ms 504 KB Output is correct
13 Correct 2 ms 380 KB Output is correct
14 Correct 2 ms 504 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 504 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 504 KB Output is correct
3 Correct 2 ms 380 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 1 ms 504 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 504 KB Output is correct
11 Correct 2 ms 504 KB Output is correct
12 Correct 2 ms 504 KB Output is correct
13 Correct 2 ms 380 KB Output is correct
14 Correct 2 ms 504 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 504 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 504 KB Output is correct
19 Correct 2 ms 504 KB Output is correct
20 Correct 2 ms 504 KB Output is correct
21 Correct 2 ms 504 KB Output is correct
22 Correct 2 ms 504 KB Output is correct
23 Correct 2 ms 504 KB Output is correct
24 Correct 2 ms 376 KB Output is correct
25 Correct 2 ms 504 KB Output is correct
26 Correct 3 ms 504 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 504 KB Output is correct
3 Correct 2 ms 380 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 1 ms 504 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 504 KB Output is correct
11 Correct 2 ms 504 KB Output is correct
12 Correct 2 ms 504 KB Output is correct
13 Correct 2 ms 380 KB Output is correct
14 Correct 2 ms 504 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 504 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 504 KB Output is correct
19 Correct 2 ms 504 KB Output is correct
20 Correct 2 ms 504 KB Output is correct
21 Correct 2 ms 504 KB Output is correct
22 Correct 2 ms 504 KB Output is correct
23 Correct 2 ms 504 KB Output is correct
24 Correct 2 ms 376 KB Output is correct
25 Correct 2 ms 504 KB Output is correct
26 Correct 3 ms 504 KB Output is correct
27 Correct 2 ms 380 KB Output is correct
28 Correct 2 ms 504 KB Output is correct
29 Correct 2 ms 504 KB Output is correct
30 Correct 2 ms 376 KB Output is correct
31 Correct 2 ms 504 KB Output is correct
32 Correct 2 ms 504 KB Output is correct
33 Correct 2 ms 380 KB Output is correct
34 Correct 2 ms 504 KB Output is correct
35 Correct 3 ms 376 KB Output is correct
36 Correct 2 ms 504 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 376 KB Output is correct
2 Correct 2 ms 504 KB Output is correct
3 Correct 2 ms 380 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 1 ms 504 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 504 KB Output is correct
11 Correct 2 ms 504 KB Output is correct
12 Correct 2 ms 504 KB Output is correct
13 Correct 2 ms 380 KB Output is correct
14 Correct 2 ms 504 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 504 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 504 KB Output is correct
19 Correct 2 ms 504 KB Output is correct
20 Correct 2 ms 504 KB Output is correct
21 Correct 2 ms 504 KB Output is correct
22 Correct 2 ms 504 KB Output is correct
23 Correct 2 ms 504 KB Output is correct
24 Correct 2 ms 376 KB Output is correct
25 Correct 2 ms 504 KB Output is correct
26 Correct 3 ms 504 KB Output is correct
27 Correct 2 ms 380 KB Output is correct
28 Correct 2 ms 504 KB Output is correct
29 Correct 2 ms 504 KB Output is correct
30 Correct 2 ms 376 KB Output is correct
31 Correct 2 ms 504 KB Output is correct
32 Correct 2 ms 504 KB Output is correct
33 Correct 2 ms 380 KB Output is correct
34 Correct 2 ms 504 KB Output is correct
35 Correct 3 ms 376 KB Output is correct
36 Correct 2 ms 504 KB Output is correct
37 Correct 3 ms 1016 KB Output is correct
38 Correct 3 ms 1016 KB Output is correct
39 Correct 126 ms 9848 KB Output is correct
40 Correct 211 ms 15992 KB Output is correct
41 Correct 102 ms 8056 KB Output is correct
42 Correct 95 ms 7192 KB Output is correct
43 Correct 68 ms 5268 KB Output is correct
44 Correct 262 ms 19988 KB Output is correct
45 Correct 257 ms 20088 KB Output is correct
46 Correct 265 ms 20088 KB Output is correct
47 Correct 246 ms 19920 KB Output is correct
48 Correct 246 ms 19956 KB Output is correct
49 Correct 1142 ms 42616 KB Output is correct
50 Correct 1130 ms 42488 KB Output is correct
51 Correct 1133 ms 42616 KB Output is correct
52 Correct 1142 ms 42524 KB Output is correct
53 Correct 1142 ms 42540 KB Output is correct
54 Correct 1166 ms 42436 KB Output is correct
55 Execution timed out 1577 ms 61868 KB Time limit exceeded
56 Halted 0 ms 0 KB -