Submission #770989

# Submission time Handle Problem Language Result Execution time Memory
770989 2023-07-02T09:37:55 Z The_Samurai Rabbit Carrot (LMIO19_triusis) C++17
100 / 100
200 ms 15304 KB
#include "bits/stdc++.h"

using namespace std;
using ll = long long;
const int inf = 1e9;

struct segtree {
    int size, neutral_element = -inf;
    vector<int> tree;

    void init(int n) {
        size = 1;
        while (size < n) size *= 2;
        tree.assign(2 * size - 1, neutral_element);
    }

    int get(int l, int r, int x, int lx, int rx) {
        if (l >= rx or lx >= r) {
            return neutral_element;
        }
        if (l <= lx and rx <= r) {
            return tree[x];
        }
        int m = (lx + rx) >> 1;
        return max(get(l, r, 2 * x + 1, lx, m), get(l, r, 2 * x + 2, m, rx));
    }

    int get(int l, int r) {
        return get(l, r + 1, 0, 0, size);
    }

    void set(int i, int v, int x, int lx, int rx) {
        if (rx - lx == 1) {
            tree[x] = max(tree[x], v);
            return;
        }
        int m = (lx + rx) >> 1;
        if (m > i) {
            set(i, v, 2 * x + 1, lx, m);
        } else {
            set(i, v, 2 * x + 2, m, rx);
        }
        tree[x] = max(tree[2 * x + 1], tree[2 * x + 2]);
    }

    void set(int i, int v) {
        set(i, v, 0, 0, size);
    }
};

void solve() {
    int n, m;
    cin >> n >> m;
    vector<int> a(n + 1), dp(n + 1, -inf);
    map<int, int> mp;
    mp[0];
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        a[i] = -(a[i] - m * i);
        mp[a[i]];
    }
    int z = 0;
    for (auto &it: mp) {
        it.second = z++;
    }
    segtree sg;
    sg.init(mp.size());
    sg.set(mp[0], 0);
    for (int i = 1; i <= n; i++) {
        a[i] = mp[a[i]];
        sg.set(a[i], sg.get(0, a[i]) + 1);
    }
    cout << n - sg.tree[0];
}

int main() {
    ios_base::sync_with_stdio(false);
    cout.tie(nullptr);
    cin.tie(nullptr);

    int queries = 1;
#ifdef test_cases
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    cin >> queries;
#else
    //    cin >> queries;
#endif

    for (int test_case = 1; test_case <= queries; test_case++) {
        solve();
        cout << '\n';
    }
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 324 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 320 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 320 KB Output is correct
14 Correct 1 ms 320 KB Output is correct
15 Correct 0 ms 320 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 324 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 320 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 320 KB Output is correct
14 Correct 1 ms 320 KB Output is correct
15 Correct 0 ms 320 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 316 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 2 ms 468 KB Output is correct
21 Correct 2 ms 596 KB Output is correct
22 Correct 2 ms 468 KB Output is correct
23 Correct 2 ms 584 KB Output is correct
24 Correct 2 ms 596 KB Output is correct
25 Correct 2 ms 596 KB Output is correct
26 Correct 2 ms 596 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 336 KB Output is correct
29 Correct 2 ms 596 KB Output is correct
30 Correct 2 ms 588 KB Output is correct
31 Correct 2 ms 468 KB Output is correct
32 Correct 3 ms 596 KB Output is correct
33 Correct 2 ms 592 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 316 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 2 ms 468 KB Output is correct
5 Correct 2 ms 596 KB Output is correct
6 Correct 2 ms 468 KB Output is correct
7 Correct 2 ms 584 KB Output is correct
8 Correct 2 ms 596 KB Output is correct
9 Correct 2 ms 596 KB Output is correct
10 Correct 2 ms 596 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 2 ms 596 KB Output is correct
14 Correct 2 ms 588 KB Output is correct
15 Correct 2 ms 468 KB Output is correct
16 Correct 3 ms 596 KB Output is correct
17 Correct 2 ms 592 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 0 ms 324 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
26 Correct 0 ms 212 KB Output is correct
27 Correct 0 ms 212 KB Output is correct
28 Correct 0 ms 320 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 1 ms 320 KB Output is correct
31 Correct 1 ms 320 KB Output is correct
32 Correct 0 ms 320 KB Output is correct
33 Correct 0 ms 212 KB Output is correct
34 Correct 4 ms 640 KB Output is correct
35 Correct 3 ms 700 KB Output is correct
36 Correct 3 ms 596 KB Output is correct
37 Correct 2 ms 596 KB Output is correct
38 Correct 1 ms 340 KB Output is correct
39 Correct 1 ms 340 KB Output is correct
40 Correct 2 ms 468 KB Output is correct
41 Correct 1 ms 340 KB Output is correct
42 Correct 2 ms 596 KB Output is correct
43 Correct 2 ms 596 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 640 KB Output is correct
2 Correct 3 ms 700 KB Output is correct
3 Correct 3 ms 596 KB Output is correct
4 Correct 2 ms 596 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 2 ms 468 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 2 ms 596 KB Output is correct
10 Correct 2 ms 596 KB Output is correct
11 Correct 0 ms 316 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 2 ms 468 KB Output is correct
15 Correct 2 ms 596 KB Output is correct
16 Correct 2 ms 468 KB Output is correct
17 Correct 2 ms 584 KB Output is correct
18 Correct 2 ms 596 KB Output is correct
19 Correct 2 ms 596 KB Output is correct
20 Correct 2 ms 596 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 336 KB Output is correct
23 Correct 2 ms 596 KB Output is correct
24 Correct 2 ms 588 KB Output is correct
25 Correct 2 ms 468 KB Output is correct
26 Correct 3 ms 596 KB Output is correct
27 Correct 2 ms 592 KB Output is correct
28 Correct 1 ms 212 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 0 ms 212 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Correct 0 ms 324 KB Output is correct
33 Correct 1 ms 212 KB Output is correct
34 Correct 1 ms 212 KB Output is correct
35 Correct 1 ms 212 KB Output is correct
36 Correct 0 ms 212 KB Output is correct
37 Correct 0 ms 212 KB Output is correct
38 Correct 0 ms 320 KB Output is correct
39 Correct 1 ms 212 KB Output is correct
40 Correct 1 ms 320 KB Output is correct
41 Correct 1 ms 320 KB Output is correct
42 Correct 0 ms 320 KB Output is correct
43 Correct 0 ms 212 KB Output is correct
44 Correct 91 ms 13668 KB Output is correct
45 Correct 200 ms 15304 KB Output is correct
46 Correct 176 ms 15264 KB Output is correct
47 Correct 178 ms 15268 KB Output is correct
48 Correct 79 ms 14028 KB Output is correct
49 Correct 78 ms 14540 KB Output is correct
50 Correct 20 ms 3792 KB Output is correct
51 Correct 18 ms 3796 KB Output is correct
52 Correct 66 ms 8368 KB Output is correct
53 Correct 14 ms 3040 KB Output is correct
54 Correct 79 ms 14272 KB Output is correct
55 Correct 80 ms 14284 KB Output is correct