이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
//#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
//#pragma GCC optimize("O3,unroll-loops")
#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define pb push_back
#define ss second
#define ff first
#define vt vector
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int inf = 1e9;
const int mod = 1e9+7;
const int maxn = 2e5 + 12;
int tr[maxn * 4], it, x;
void upd(int v, int l, int r){
if(l + 1 == r){
tr[v] = x;
return;
}
if((l + r) / 2 <= it)upd(v * 2 + 2, (l + r) / 2, r);
else upd(v * 2 + 1, l, (l + r) / 2);
tr[v] = max(tr[v * 2 + 1], tr[v * 2 + 2]);
}
int get(int v, int l, int r){
if(r - 1 <= it)return tr[v];
if(it < l)return 0;
return max(get(v * 2 + 1, l, (l + r) / 2), get(v * 2 + 2, (l + r) / 2, r));
}
void solve() {
int n, k, cnt = 0;
cin >> n >> k;
int a[n];
set<int> s;
map<int, int> m;
s.insert(0);
for(int i = 0; i < n; i++){
cin >> a[i];
a[i] = a[i] - (i + 1) * k;
s.insert(a[i]);
}
for(auto i : s)m[i] = cnt++;
for(int i = n - 1; i >= 0; i--){
a[i] = m[a[i]];
it = a[i];
x = get(0, 0, cnt) + 1;
upd(0, 0, cnt);
}
it = m[0];
cout << n - get(0, 0, cnt);
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int times = 1;
//cin >> times;
for(int i = 1; i <= times; i++) {
solve();
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |