This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define S second
#define F first
#define all(x) (x).begin(),(x).end()
#define sz size()
#define Yes cout << "YES" << endl
#define No cout << "NO" << endl
#define pb(x) push_back(x);
#define endl '\n'
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
const int N=3e5+7;
ll INF=INT_MAX,mod=1e9+7;
int TT=1;
ll power(ll x, unsigned int y)
{
ll res = 1;
x = x; // % mod;
if (x == 0) return 0;
while (y > 0)
{
if (y & 1) res = (res*x) ; // % mod;
y = y>>1;
x = (x*x) ; // % mod;
}
return res;
}
ll n , m;
ll a[N];
map<ll,int> mp;
ll bit[N];
void upd(ll x,ll val)
{
while(x<=n)
{
bit[x] = max(bit[x],val);
x +=(x&(-x));
}
return;
}
ll get(ll x)
{
ll res = 0;
while(x> 0)
{
res = max(res,bit[x]);
x-= (x&(-x));
}
return res;
}
void solve()
{
ll ans = 0;
cin >> n >> m;
for(int i = 1; i <= n; i++) cin >> a[i];
if(a[1]>m) {ans++,a[1] = m;}
for(int i = 1; i <= n ;i++){
a[i] -= (i)*m;
mp[a[i]] = 1;
}
ll cnt = 1;
for(auto it: mp)
mp[it.first] = cnt++;
for(int i = n; i>=2; i--)
{
ll x = mp[a[i]];
//cout << x << endl;
ll y = get(x);
upd(x,y+1);
}
cout << (n-1)-get(mp[a[1]])+ans << endl;
}
int main(){
//freopen("friday.in","r",stdin);
//freopen("friday.out","w",stdout);
fast;
while(TT--)
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... |