이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "bits/stdc++.h"
#include "ext/pb_ds/assoc_container.hpp"
using namespace std;
using namespace __gnu_pbds;
#define ll long long
#define open(g) string _name_ = g; freopen((_name_ + ".in").c_str(), "r", stdin); freopen((_name_ + ".out").c_str(), "w", stdout)
#define printArr(a, len) for(int asdf = 0; asdf < (len); ++asdf) cout << (a)[asdf] << ' '; cout << '\n';
#define boost() cin.sync_with_stdio(0); cin.tie(0)
#define forR(i, x) for(int i = 0; i < x; ++i)
#define REP(i, a, b) for(int i = (a); i < (b); ++i)
#define all(i) i.begin(), i.end()
#define pii pair<int, int>
#define vi vector<int>
#define si set<int>
#define usi unordered_set<int>
#define mii map<int, int>
#define umii unordered_map<int, int>
template <class K, class V> using ht = gp_hash_table<K, V, hash<K>, equal_to<K>, direct_mask_range_hashing<>,
linear_probe_fn<>, hash_standard_resize_policy<hash_exponential_size_policy<>, hash_load_check_resize_trigger<>, true>>;
const int MN = 2e5 + 300, MAX = 3 * MN;
int bit[MAX];
int& get(int i){
return bit[i];
}
void upd(ll i, int diff){
i = MN - i;
assert(0 < i && i < MAX);
for(; 0 < i && i < MAX; i += i&-i) get(i) = min(get((int) i), diff);
}
int qu(int i){
i = MN - i;
assert(0 < i && i < MAX);
int ma = MAX;
for(; i > 0; i -= i&-i) ma = min(ma, get(i));
return ma;
}
int dp[MN], arr[MN], a[MN];
signed main() {
boost();
int n, m;
cin >> n >> m;
REP(i, 1, n + 1) cin >> arr[i];
for(int& i : bit) i = MAX;
forR(i, n + 1) a[i] = arr[i] - i * m;
set<int> sv;
forR(i, n + 1) sv.insert(a[i]);
vector<int> val;
for(int i : sv) val.push_back(i);
forR(i, n + 1) a[i] = lower_bound(all(val), a[i]) - val.begin() + 1;
upd(a[0], 0);
REP(i, 1, n + 1){
dp[i] = qu(a[i]) + i - 1;
upd(a[i], dp[i] - i);
}
int mi = n;
REP(i, 1, n + 1) {
mi = min(mi, dp[i] + n - i);
}
cout << mi << '\n';
}
# | 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... |