답안 #913898

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
913898 2024-01-20T12:52:02 Z Pragmatism Rabbit Carrot (LMIO19_triusis) C++17
0 / 100
2 ms 4596 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];
void f() {
    vector <int> v;
    for (int i = 1;i <= n;i++)v.pb(a[i]);
    sort(all(v));
    map <int, int> id;
    int last = 0, pos = 0;
    for (auto x : v) {
        if (x == last)skip;
        id[x] = ++pos, last = x;
    }
    for (int i = 1;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 = 1;i <= n;i++) {
        dp[i] = get(1, 1, n, a[i], n) + 1;
        update(1, 1, n, a[i], dp[i]);
    }
    cout << n - get(1, 1, n, 1, n);
}
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;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Incorrect 2 ms 4596 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Incorrect 2 ms 4596 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Incorrect 2 ms 4596 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Incorrect 2 ms 4596 KB Output isn't correct
3 Halted 0 ms 0 KB -