Submission #156196

# Submission time Handle Problem Language Result Execution time Memory
156196 2019-10-04T11:22:31 Z theboatman Money (IZhO17_money) C++17
45 / 100
1500 ms 77012 KB
#include <bits/stdc++.h>

#define y1 theboatman
#define make_struct(args...) {args}

using namespace std;

const int inf = 1e9 + 10;
const int N = 1e6 + 10;

struct tree {
    int n;
    vector <int> t, f;

    void init(int temp) {
        n = temp;
        t.resize(n * 4);
        f.resize(n * 4);
    }

    void inc(int pos) {
        if(f[pos])return;
        f[pos] = 1;
        for(int i = pos; i <= n; i += i & -i) {
            t[i] += 1;
        }
    }

    int get(int pos) {
        int res = 0;
        for(int i = pos; i > 0; i -= i & -i) {
            res += t[i];
        }

        return res;
    }

    int get(int l, int r) {
        return get(r) - get(l - 1);
    }
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);

    int n;
    cin >> n;

    vector <int> a(n);
    for(int i = 0; i < n; i++) {
        cin >> a[i];
    }

    int now = 0, x = 0;
    while(now < n && x <= a[now]) {
        x = a[now];
        now++;
    }

    tree bank;
    bank.init(N);

    set <int> s;
    for(int i = 0; i < now; i++) {
        bank.inc(a[i]);

        s.insert(a[i]);
    }

    int ans = 0;
    for(int i = now; i < n; i++) {
        ans++;

        int l = *s.begin(), r = *--s.end();
        //cout << a[i] << " " << l << " " << r << endl;
        if (a[i] >= r) {
            int x = 0;
            while(i < n && x <= a[i]) {
                x = a[i];

                bank.inc(x);
                s.insert(x);

                i++;
            }
            i--;
        }
        else {
            vector <int> lazy;
            if (a[i] < l) {
                int x = 0;
                while(i < n && x <= a[i] && a[i] <= l) {
                    x = a[i];
                    lazy.push_back(x);
                    i++;
                }
                i--;
            }
            else {
                int x = 0;
                int les = *--s.upper_bound(a[i]);

                while(i < n && x <= a[i]) {
                    auto more = s.lower_bound(a[i]);
                    if (more == s.end()) {
                        break;
                    }

                    int pos = bank.get(1, les);
                    int pos1 = bank.get(1, *more);

                    //cout << les << " " << *more << " " << pos << " " << pos1 << " " << i << endl;

                    if (pos1 - pos <= 1) {
                        x = a[i];
                        lazy.push_back(x);
                        i++;
                    }
                    else {
                        break;
                    }
                }

                i--;
            }

            for(auto it : lazy) {
                bank.inc(it);
                s.insert(it);
            }
        }
    }

    cout << ans + 1 << "\n";
    return 0;
}

/*
find_by_order(X) k -> элемент, нумерация с нуля
order_of_key(X) кол-во < чем X
*/
# Verdict Execution time Memory Grader output
1 Correct 30 ms 31608 KB Output is correct
2 Correct 30 ms 31608 KB Output is correct
3 Correct 34 ms 31692 KB Output is correct
4 Correct 35 ms 31736 KB Output is correct
5 Correct 30 ms 31612 KB Output is correct
6 Correct 29 ms 31608 KB Output is correct
7 Correct 39 ms 31608 KB Output is correct
8 Correct 35 ms 31608 KB Output is correct
9 Correct 34 ms 31604 KB Output is correct
10 Correct 37 ms 31608 KB Output is correct
11 Correct 30 ms 31608 KB Output is correct
12 Correct 30 ms 31664 KB Output is correct
13 Correct 29 ms 31608 KB Output is correct
14 Correct 30 ms 31776 KB Output is correct
15 Correct 31 ms 31608 KB Output is correct
16 Correct 30 ms 31608 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 30 ms 31608 KB Output is correct
2 Correct 30 ms 31608 KB Output is correct
3 Correct 34 ms 31692 KB Output is correct
4 Correct 35 ms 31736 KB Output is correct
5 Correct 30 ms 31612 KB Output is correct
6 Correct 29 ms 31608 KB Output is correct
7 Correct 39 ms 31608 KB Output is correct
8 Correct 35 ms 31608 KB Output is correct
9 Correct 34 ms 31604 KB Output is correct
10 Correct 37 ms 31608 KB Output is correct
11 Correct 30 ms 31608 KB Output is correct
12 Correct 30 ms 31664 KB Output is correct
13 Correct 29 ms 31608 KB Output is correct
14 Correct 30 ms 31776 KB Output is correct
15 Correct 31 ms 31608 KB Output is correct
16 Correct 30 ms 31608 KB Output is correct
17 Correct 30 ms 31608 KB Output is correct
18 Correct 29 ms 31608 KB Output is correct
19 Correct 29 ms 31736 KB Output is correct
20 Correct 30 ms 31608 KB Output is correct
21 Correct 30 ms 31736 KB Output is correct
22 Correct 30 ms 31612 KB Output is correct
23 Correct 30 ms 31608 KB Output is correct
24 Correct 30 ms 31612 KB Output is correct
25 Correct 30 ms 31656 KB Output is correct
26 Correct 30 ms 31612 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 30 ms 31608 KB Output is correct
2 Correct 30 ms 31608 KB Output is correct
3 Correct 34 ms 31692 KB Output is correct
4 Correct 35 ms 31736 KB Output is correct
5 Correct 30 ms 31612 KB Output is correct
6 Correct 29 ms 31608 KB Output is correct
7 Correct 39 ms 31608 KB Output is correct
8 Correct 35 ms 31608 KB Output is correct
9 Correct 34 ms 31604 KB Output is correct
10 Correct 37 ms 31608 KB Output is correct
11 Correct 30 ms 31608 KB Output is correct
12 Correct 30 ms 31664 KB Output is correct
13 Correct 29 ms 31608 KB Output is correct
14 Correct 30 ms 31776 KB Output is correct
15 Correct 31 ms 31608 KB Output is correct
16 Correct 30 ms 31608 KB Output is correct
17 Correct 30 ms 31608 KB Output is correct
18 Correct 29 ms 31608 KB Output is correct
19 Correct 29 ms 31736 KB Output is correct
20 Correct 30 ms 31608 KB Output is correct
21 Correct 30 ms 31736 KB Output is correct
22 Correct 30 ms 31612 KB Output is correct
23 Correct 30 ms 31608 KB Output is correct
24 Correct 30 ms 31612 KB Output is correct
25 Correct 30 ms 31656 KB Output is correct
26 Correct 30 ms 31612 KB Output is correct
27 Correct 31 ms 31668 KB Output is correct
28 Correct 29 ms 31608 KB Output is correct
29 Correct 29 ms 31608 KB Output is correct
30 Correct 30 ms 31608 KB Output is correct
31 Correct 30 ms 31608 KB Output is correct
32 Correct 30 ms 31608 KB Output is correct
33 Correct 38 ms 31608 KB Output is correct
34 Correct 31 ms 31700 KB Output is correct
35 Correct 30 ms 31608 KB Output is correct
36 Correct 32 ms 31768 KB Output is correct
37 Correct 30 ms 31608 KB Output is correct
38 Correct 30 ms 31608 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 30 ms 31608 KB Output is correct
2 Correct 30 ms 31608 KB Output is correct
3 Correct 34 ms 31692 KB Output is correct
4 Correct 35 ms 31736 KB Output is correct
5 Correct 30 ms 31612 KB Output is correct
6 Correct 29 ms 31608 KB Output is correct
7 Correct 39 ms 31608 KB Output is correct
8 Correct 35 ms 31608 KB Output is correct
9 Correct 34 ms 31604 KB Output is correct
10 Correct 37 ms 31608 KB Output is correct
11 Correct 30 ms 31608 KB Output is correct
12 Correct 30 ms 31664 KB Output is correct
13 Correct 29 ms 31608 KB Output is correct
14 Correct 30 ms 31776 KB Output is correct
15 Correct 31 ms 31608 KB Output is correct
16 Correct 30 ms 31608 KB Output is correct
17 Correct 30 ms 31608 KB Output is correct
18 Correct 29 ms 31608 KB Output is correct
19 Correct 29 ms 31736 KB Output is correct
20 Correct 30 ms 31608 KB Output is correct
21 Correct 30 ms 31736 KB Output is correct
22 Correct 30 ms 31612 KB Output is correct
23 Correct 30 ms 31608 KB Output is correct
24 Correct 30 ms 31612 KB Output is correct
25 Correct 30 ms 31656 KB Output is correct
26 Correct 30 ms 31612 KB Output is correct
27 Correct 31 ms 31668 KB Output is correct
28 Correct 29 ms 31608 KB Output is correct
29 Correct 29 ms 31608 KB Output is correct
30 Correct 30 ms 31608 KB Output is correct
31 Correct 30 ms 31608 KB Output is correct
32 Correct 30 ms 31608 KB Output is correct
33 Correct 38 ms 31608 KB Output is correct
34 Correct 31 ms 31700 KB Output is correct
35 Correct 30 ms 31608 KB Output is correct
36 Correct 32 ms 31768 KB Output is correct
37 Correct 30 ms 31608 KB Output is correct
38 Correct 30 ms 31608 KB Output is correct
39 Correct 135 ms 33508 KB Output is correct
40 Correct 220 ms 34800 KB Output is correct
41 Correct 112 ms 33272 KB Output is correct
42 Correct 122 ms 33060 KB Output is correct
43 Correct 93 ms 32588 KB Output is correct
44 Correct 253 ms 35540 KB Output is correct
45 Correct 254 ms 35576 KB Output is correct
46 Correct 271 ms 35676 KB Output is correct
47 Correct 229 ms 35540 KB Output is correct
48 Correct 231 ms 35544 KB Output is correct
49 Correct 1135 ms 54136 KB Output is correct
50 Correct 1111 ms 54428 KB Output is correct
51 Correct 1006 ms 54352 KB Output is correct
52 Correct 1048 ms 54340 KB Output is correct
53 Correct 997 ms 54360 KB Output is correct
54 Correct 951 ms 54548 KB Output is correct
55 Execution timed out 1573 ms 77012 KB Time limit exceeded
56 Halted 0 ms 0 KB -