// #pragma GCC target( "sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
// #pragma GCC optimize("Ofast,unroll-loops,fast-math,O3")
#include<bits/stdc++.h>
#define f first
#define s second
#define pb push_back
#define sz(x) (int)x.size()
#define bit(a, i) ((a>>i)&1)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int P = 18;
const int K = 800;
const ll INF = 2e18;
const int inf = 1e9;
const int mod = 1e9+7;
const int maxm = 5e2+10;
const int maxn = 2e5+10;
const int dx[] = {0, 0, -1, 1};
const int dy[] = {1, -1, 0, 0};
ll a[maxn];
ll b[maxn];
int n, m, sz;
int dp[maxn];
int t[4*maxn];
map<int, int>cnt;
void build(int v=1, int tl=1, int tr=sz){
if(tl == tr) t[v] = inf;
else{
int tm = tl+tr>>1;
build(v<<1, tl, tm);
build(v<<1|1, tm+1, tr);
t[v] = min(t[v<<1], t[v<<1|1]);
}
}
int get(int l, int v=1, int tl=1, int tr=sz){
if(l > tr) return inf;
if(l <= tl) return t[v];
int tm = tl+tr>>1;
return min(get(l, v<<1, tl, tm), get(l, v<<1|1, tm+1, tr));
}
void upd(int i, int x, int v=1, int tl=1, int tr=sz){
if(tl == tr) t[v] = min(t[v], x);
else{
int tm = tl+tr>>1;
if(i <= tm) upd(i, x, v<<1, tl, tm);
else upd(i, x, v<<1|1, tm+1, tr);
t[v] = min(t[v<<1], t[v<<1|1]);
}
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
cin >> n >> m;
int ans = n;
set<int>st;
st.insert(0);
for(int i=1; i<=n; i++){
cin >> a[i];
b[i] = a[i]-i*1ll*m;
st.insert(b[i]);
} for(auto to: st) cnt[to] = ++sz;
build();
upd(1, 0);
for(int i=1; i<=n; i++){
dp[i] = get(cnt[b[i]])+1;
upd(cnt[b[i]], dp[i]);
ans = min(ans, dp[i]+n-i);
} cout << ans;
}
Compilation message
triusis.cpp: In function 'void build(int, int, int)':
triusis.cpp:34:20: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
34 | int tm = tl+tr>>1;
| ~~^~~
triusis.cpp: In function 'int get(int, int, int, int)':
triusis.cpp:44:16: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
44 | int tm = tl+tr>>1;
| ~~^~~
triusis.cpp: In function 'void upd(int, int, int, int, int)':
triusis.cpp:51:20: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
51 | int tm = tl+tr>>1;
| ~~^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
4444 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
4444 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
4444 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
4444 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |