Submission #170484

# Submission time Handle Problem Language Result Execution time Memory
170484 2019-12-25T12:03:36 Z mcdx9524 Money (IZhO17_money) C++14
100 / 100
218 ms 15024 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int N = 1e6 + 7;

int t[N];

int upd(int p, int x) {
    for (; p < N; p = (p | (p + 1))) {
        t[p] += x;
    }
}

int sum(int p) {
    int res = 0;
    for (; p >= 0; p = (p & (p + 1)) - 1) {
        res += t[p];
    }
    return res;
}

int sum(int l, int r) {
    if (l > r) {
        return 0;
    }
    if (l == 0) {
        return sum(r);
    } else {
        return sum(r) - sum(l - 1);
    }
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    vector <int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    int ans = 0;
    int prv = 0;
    for (int i = 1; i < n; i++) {
        if (a[i] < a[i - 1] || sum(a[prv] + 1, a[i] - 1)) {
            for (int j = i - 1; j >= prv; j--) {
                upd(a[j], 1);
            }
            prv = i;
            ans++;
        }
    }
    cout << ans + 1 << '\n';
    return 0;
}

Compilation message

money.cpp: In function 'int upd(int, int)':
money.cpp:15:1: warning: no return statement in function returning non-void [-Wreturn-type]
 }
 ^
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 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 380 KB Output is correct
10 Correct 2 ms 504 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 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 380 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 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 380 KB Output is correct
10 Correct 2 ms 504 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 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 380 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 376 KB Output is correct
21 Correct 2 ms 504 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 504 KB Output is correct
26 Correct 2 ms 632 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 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 380 KB Output is correct
10 Correct 2 ms 504 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 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 380 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 376 KB Output is correct
21 Correct 2 ms 504 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 504 KB Output is correct
26 Correct 2 ms 632 KB Output is correct
27 Correct 2 ms 376 KB Output is correct
28 Correct 2 ms 504 KB Output is correct
29 Correct 2 ms 380 KB Output is correct
30 Correct 3 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 5 ms 380 KB Output is correct
34 Correct 2 ms 552 KB Output is correct
35 Correct 2 ms 376 KB Output is correct
36 Correct 2 ms 376 KB Output is correct
37 Correct 4 ms 1528 KB Output is correct
38 Correct 4 ms 1656 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 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 380 KB Output is correct
10 Correct 2 ms 504 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 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 380 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 376 KB Output is correct
21 Correct 2 ms 504 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 504 KB Output is correct
26 Correct 2 ms 632 KB Output is correct
27 Correct 2 ms 376 KB Output is correct
28 Correct 2 ms 504 KB Output is correct
29 Correct 2 ms 380 KB Output is correct
30 Correct 3 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 5 ms 380 KB Output is correct
34 Correct 2 ms 552 KB Output is correct
35 Correct 2 ms 376 KB Output is correct
36 Correct 2 ms 376 KB Output is correct
37 Correct 4 ms 1528 KB Output is correct
38 Correct 4 ms 1656 KB Output is correct
39 Correct 80 ms 5468 KB Output is correct
40 Correct 135 ms 9016 KB Output is correct
41 Correct 67 ms 4472 KB Output is correct
42 Correct 60 ms 4328 KB Output is correct
43 Correct 43 ms 3192 KB Output is correct
44 Correct 171 ms 11128 KB Output is correct
45 Correct 165 ms 11000 KB Output is correct
46 Correct 165 ms 11256 KB Output is correct
47 Correct 151 ms 11080 KB Output is correct
48 Correct 161 ms 11256 KB Output is correct
49 Correct 179 ms 15024 KB Output is correct
50 Correct 179 ms 14920 KB Output is correct
51 Correct 181 ms 14824 KB Output is correct
52 Correct 183 ms 14968 KB Output is correct
53 Correct 190 ms 14952 KB Output is correct
54 Correct 196 ms 14840 KB Output is correct
55 Correct 209 ms 14952 KB Output is correct
56 Correct 213 ms 14968 KB Output is correct
57 Correct 218 ms 14840 KB Output is correct
58 Correct 199 ms 14840 KB Output is correct
59 Correct 196 ms 14968 KB Output is correct
60 Correct 191 ms 14940 KB Output is correct
61 Correct 201 ms 14840 KB Output is correct
62 Correct 209 ms 14840 KB Output is correct