Submission #524017

# Submission time Handle Problem Language Result Execution time Memory
524017 2022-02-08T14:29:23 Z Nursik Money (IZhO17_money) C++14
100 / 100
185 ms 8636 KB
#include <bits/stdc++.h>

#define pb push_back
#define ll long long
#define ld long double
#define f first
#define s second
#define mp make_pair

const ll maxn = 1e6 + 100, maxm = 3e5 + 1,  maxk = 61;
const ll inf = 1000000000, mod = inf + 7, mod2 = 998244353;
const ll pa = 31, block = 400;

using namespace std;

int n;
int a[maxn], f[maxn];
void upd(int pos, int val){
    for (int i = pos; i <= 1e6; i |= (i + 1)){
        f[i] += val;
    }
}
int get(int pos){
    int res = 0;
    for (int i = pos; i >= 1; i = (i & (i + 1)) - 1){
        res += f[i];
    }
    return res;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    cin >> n;
    for (int i = 1; i <= n; ++i){
        cin >> a[i];
    }
    int pos = 1, ans = 0;
    vector<int> v;
    v.pb(0), v.pb(inf);
    while (pos <= n){
        int mx = 0, mn = inf, answ = pos;;
        for (int j = pos; j <= n; ++j){
            if ((j == pos) || (j - 1 >= pos && a[j] >= a[j - 1])){
                mx = max(mx, a[j]);
                mn = min(mn, a[j]);
                int range = get(mx - 1) - get(mn);
                range = max(range, 0);
                if (range == 0){
                    answ = j;
                }
                else{
                    break;
                }
            }
            else{
                break;
            }
        }
        ans++;
      //  cout << pos << " " << answ << '\n';
        for (int j = pos; j <= answ; ++j){
            upd(a[j], 1);
        }
        pos = answ + 1;
    }
    cout << ans;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 324 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 320 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 320 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 452 KB Output is correct
16 Correct 1 ms 460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 324 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 320 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 320 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 452 KB Output is correct
16 Correct 1 ms 460 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 460 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 0 ms 332 KB Output is correct
21 Correct 1 ms 460 KB Output is correct
22 Correct 0 ms 320 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 460 KB Output is correct
26 Correct 1 ms 460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 324 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 320 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 320 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 452 KB Output is correct
16 Correct 1 ms 460 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 460 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 0 ms 332 KB Output is correct
21 Correct 1 ms 460 KB Output is correct
22 Correct 0 ms 320 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 460 KB Output is correct
26 Correct 1 ms 460 KB Output is correct
27 Correct 1 ms 292 KB Output is correct
28 Correct 1 ms 332 KB Output is correct
29 Correct 1 ms 332 KB Output is correct
30 Correct 1 ms 332 KB Output is correct
31 Correct 1 ms 332 KB Output is correct
32 Correct 1 ms 332 KB Output is correct
33 Correct 1 ms 332 KB Output is correct
34 Correct 1 ms 460 KB Output is correct
35 Correct 1 ms 324 KB Output is correct
36 Correct 1 ms 332 KB Output is correct
37 Correct 1 ms 1612 KB Output is correct
38 Correct 1 ms 1740 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 324 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 320 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 320 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 452 KB Output is correct
16 Correct 1 ms 460 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 460 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 0 ms 332 KB Output is correct
21 Correct 1 ms 460 KB Output is correct
22 Correct 0 ms 320 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 460 KB Output is correct
26 Correct 1 ms 460 KB Output is correct
27 Correct 1 ms 292 KB Output is correct
28 Correct 1 ms 332 KB Output is correct
29 Correct 1 ms 332 KB Output is correct
30 Correct 1 ms 332 KB Output is correct
31 Correct 1 ms 332 KB Output is correct
32 Correct 1 ms 332 KB Output is correct
33 Correct 1 ms 332 KB Output is correct
34 Correct 1 ms 460 KB Output is correct
35 Correct 1 ms 324 KB Output is correct
36 Correct 1 ms 332 KB Output is correct
37 Correct 1 ms 1612 KB Output is correct
38 Correct 1 ms 1740 KB Output is correct
39 Correct 67 ms 2800 KB Output is correct
40 Correct 117 ms 4112 KB Output is correct
41 Correct 66 ms 2440 KB Output is correct
42 Correct 51 ms 2276 KB Output is correct
43 Correct 47 ms 1892 KB Output is correct
44 Correct 131 ms 4760 KB Output is correct
45 Correct 135 ms 4676 KB Output is correct
46 Correct 150 ms 4724 KB Output is correct
47 Correct 132 ms 4548 KB Output is correct
48 Correct 139 ms 4548 KB Output is correct
49 Correct 160 ms 8412 KB Output is correct
50 Correct 157 ms 8508 KB Output is correct
51 Correct 180 ms 8436 KB Output is correct
52 Correct 158 ms 8428 KB Output is correct
53 Correct 166 ms 8516 KB Output is correct
54 Correct 147 ms 8524 KB Output is correct
55 Correct 172 ms 8636 KB Output is correct
56 Correct 163 ms 8632 KB Output is correct
57 Correct 185 ms 8520 KB Output is correct
58 Correct 157 ms 8528 KB Output is correct
59 Correct 159 ms 8632 KB Output is correct
60 Correct 168 ms 8632 KB Output is correct
61 Correct 165 ms 8636 KB Output is correct
62 Correct 155 ms 8624 KB Output is correct