Submission #913936

# Submission time Handle Problem Language Result Execution time Memory
913936 2024-01-20T15:06:21 Z Pragmatism Rabbit Carrot (LMIO19_triusis) C++17
100 / 100
375 ms 36628 KB
//Bismillahir-Rahmanir-Rahim

#include <bits/stdc++.h>
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("O1,O2,O3,Ofast,unroll-loops")
//#pragma GCC target("sse,sse2,sse3,sse4,sse4.1,sse4.2,popcnt,avx,avx2")

#define pb push_back
#define pii pair <int, int>
#define pll pair <long long, long long>
#define pld pair <long double, long double>
#define ll long long
#define ld long double
#define x first
#define y second
#define all(v) v.begin(),v.end()
#define sz(s) (int)s.size()
#define skip continue
#define bpop(x) (ll)__builtin_popcountll(x)

using namespace std;

const int N = 2e5 + 7;
const int K = 400;
const int maxA = 1e7 + 7;
const int inf = 1e9 + 7;
const ll INF = 1e18 + 7;
const ll MOD = 1e9 + 7;
const ld eps = 1e-9;

pii dir[] = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}};

//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

#define int long long

int n, M, a[N], dp[N];
map <int, int> val;
void f() {
    vector <int> v;
    for (int i = 0;i <= n;i++)v.pb(a[i]);
    sort(all(v));
    map <int, int> id;
    int last = -INF, pos = 0;
    for (auto x : v) {
        if (x == last)skip;
        id[x] = ++pos, last = x;
        val[pos] = x;
    }
    for (int i = 0;i <= n;i++)a[i] = id[a[i]];
}
int t[4 * N];
void update(int v, int tl, int tr, int pos, int x) {
    if (tl == tr) {
        t[v] = x;
        return;
    }
    int mid = (tl + tr) / 2;
    if (pos <= mid)update(v * 2, tl, mid, pos, x);
    else update(v * 2 + 1, mid + 1, tr, pos, x);
    t[v] = max(t[v * 2], t[v * 2 + 1]);
}
int get(int v, int tl, int tr, int l, int r) {
    if (r < l || tr < l || tl > r)return 0;
    if (tl >= l && tr <= r)return t[v];
    int mid = (tl + tr) / 2;
    return max(get(v * 2, tl, mid, l, r), get(v * 2 + 1, mid + 1, tr, l, r));
}
void solve() {
    cin >> n >> M;
    for (int i = 1;i <= n;i++)cin >> a[i], a[i] -= i * M;
    f();
    for (int i = n;i >= 0;i--) {
        dp[i] = get(1, 1, n + 1, 1, a[i]) + 1;
        update(1, 1, n + 1, a[i], dp[i]);
        //cout << dp[i] << ' ';
    }
    cout << n + 1 - dp[0];
}
signed main() {
    //srand(time(NULL));
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    //freopen("tests.in", "r", stdin);
    //freopen("milkorder.out", "w", stdout);
    int test = 1;
    //cin >> test;
    for (int t = 1;t <= test;t++) {
        //cout << "Case " << t << ": ";
        solve();
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 2 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4568 KB Output is correct
6 Correct 1 ms 4440 KB Output is correct
7 Correct 2 ms 4560 KB Output is correct
8 Correct 2 ms 4440 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 1 ms 4440 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 1 ms 4444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 2 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4568 KB Output is correct
6 Correct 1 ms 4440 KB Output is correct
7 Correct 2 ms 4560 KB Output is correct
8 Correct 2 ms 4440 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 1 ms 4440 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 1 ms 4444 KB Output is correct
17 Correct 1 ms 4444 KB Output is correct
18 Correct 2 ms 4444 KB Output is correct
19 Correct 1 ms 4444 KB Output is correct
20 Correct 3 ms 5084 KB Output is correct
21 Correct 4 ms 5212 KB Output is correct
22 Correct 4 ms 5072 KB Output is correct
23 Correct 4 ms 5360 KB Output is correct
24 Correct 3 ms 5208 KB Output is correct
25 Correct 4 ms 5212 KB Output is correct
26 Correct 3 ms 5304 KB Output is correct
27 Correct 2 ms 4700 KB Output is correct
28 Correct 2 ms 4572 KB Output is correct
29 Correct 4 ms 5212 KB Output is correct
30 Correct 4 ms 5212 KB Output is correct
31 Correct 3 ms 4832 KB Output is correct
32 Correct 4 ms 5212 KB Output is correct
33 Correct 4 ms 5212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 2 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 3 ms 5084 KB Output is correct
5 Correct 4 ms 5212 KB Output is correct
6 Correct 4 ms 5072 KB Output is correct
7 Correct 4 ms 5360 KB Output is correct
8 Correct 3 ms 5208 KB Output is correct
9 Correct 4 ms 5212 KB Output is correct
10 Correct 3 ms 5304 KB Output is correct
11 Correct 2 ms 4700 KB Output is correct
12 Correct 2 ms 4572 KB Output is correct
13 Correct 4 ms 5212 KB Output is correct
14 Correct 4 ms 5212 KB Output is correct
15 Correct 3 ms 4832 KB Output is correct
16 Correct 4 ms 5212 KB Output is correct
17 Correct 4 ms 5212 KB Output is correct
18 Correct 1 ms 4440 KB Output is correct
19 Correct 2 ms 4444 KB Output is correct
20 Correct 1 ms 4444 KB Output is correct
21 Correct 1 ms 4444 KB Output is correct
22 Correct 1 ms 4568 KB Output is correct
23 Correct 1 ms 4440 KB Output is correct
24 Correct 2 ms 4560 KB Output is correct
25 Correct 2 ms 4440 KB Output is correct
26 Correct 1 ms 4444 KB Output is correct
27 Correct 1 ms 4444 KB Output is correct
28 Correct 1 ms 4444 KB Output is correct
29 Correct 1 ms 4444 KB Output is correct
30 Correct 1 ms 4440 KB Output is correct
31 Correct 1 ms 4444 KB Output is correct
32 Correct 1 ms 4444 KB Output is correct
33 Correct 1 ms 4444 KB Output is correct
34 Correct 5 ms 5212 KB Output is correct
35 Correct 5 ms 5212 KB Output is correct
36 Correct 5 ms 5208 KB Output is correct
37 Correct 4 ms 5212 KB Output is correct
38 Correct 2 ms 4700 KB Output is correct
39 Correct 2 ms 4700 KB Output is correct
40 Correct 3 ms 4956 KB Output is correct
41 Correct 2 ms 4700 KB Output is correct
42 Correct 4 ms 5212 KB Output is correct
43 Correct 4 ms 5208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 5212 KB Output is correct
2 Correct 5 ms 5212 KB Output is correct
3 Correct 5 ms 5208 KB Output is correct
4 Correct 4 ms 5212 KB Output is correct
5 Correct 2 ms 4700 KB Output is correct
6 Correct 2 ms 4700 KB Output is correct
7 Correct 3 ms 4956 KB Output is correct
8 Correct 2 ms 4700 KB Output is correct
9 Correct 4 ms 5212 KB Output is correct
10 Correct 4 ms 5208 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 2 ms 4444 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 3 ms 5084 KB Output is correct
15 Correct 4 ms 5212 KB Output is correct
16 Correct 4 ms 5072 KB Output is correct
17 Correct 4 ms 5360 KB Output is correct
18 Correct 3 ms 5208 KB Output is correct
19 Correct 4 ms 5212 KB Output is correct
20 Correct 3 ms 5304 KB Output is correct
21 Correct 2 ms 4700 KB Output is correct
22 Correct 2 ms 4572 KB Output is correct
23 Correct 4 ms 5212 KB Output is correct
24 Correct 4 ms 5212 KB Output is correct
25 Correct 3 ms 4832 KB Output is correct
26 Correct 4 ms 5212 KB Output is correct
27 Correct 4 ms 5212 KB Output is correct
28 Correct 1 ms 4440 KB Output is correct
29 Correct 2 ms 4444 KB Output is correct
30 Correct 1 ms 4444 KB Output is correct
31 Correct 1 ms 4444 KB Output is correct
32 Correct 1 ms 4568 KB Output is correct
33 Correct 1 ms 4440 KB Output is correct
34 Correct 2 ms 4560 KB Output is correct
35 Correct 2 ms 4440 KB Output is correct
36 Correct 1 ms 4444 KB Output is correct
37 Correct 1 ms 4444 KB Output is correct
38 Correct 1 ms 4444 KB Output is correct
39 Correct 1 ms 4444 KB Output is correct
40 Correct 1 ms 4440 KB Output is correct
41 Correct 1 ms 4444 KB Output is correct
42 Correct 1 ms 4444 KB Output is correct
43 Correct 1 ms 4444 KB Output is correct
44 Correct 173 ms 35092 KB Output is correct
45 Correct 369 ms 36524 KB Output is correct
46 Correct 375 ms 36628 KB Output is correct
47 Correct 283 ms 36500 KB Output is correct
48 Correct 172 ms 35176 KB Output is correct
49 Correct 184 ms 35776 KB Output is correct
50 Correct 56 ms 9688 KB Output is correct
51 Correct 53 ms 9688 KB Output is correct
52 Correct 105 ms 22172 KB Output is correct
53 Correct 54 ms 8980 KB Output is correct
54 Correct 172 ms 35480 KB Output is correct
55 Correct 165 ms 35224 KB Output is correct