Submission #744645

# Submission time Handle Problem Language Result Execution time Memory
744645 2023-05-18T22:06:50 Z vjudge1 Rabbit Carrot (LMIO19_triusis) C++17
0 / 100
1 ms 336 KB
#include "bits/stdc++.h"


using namespace std;

#define int long long
const int inf = 1e9;
const int ms = 2e5 + 5;

int seg[4*ms], n;

void upd(int pos, int val, int l=0, int r=n-1, int idx=0){
  if(l == r){
    seg[idx] = val;
    return;
  }
  int m = (l+r)/2;
  if(pos <=m ) upd(pos, val, l, m, 2*idx + 1);
  else upd(pos, val, m+1, r, 2*idx + 2);

  seg[idx] = max(seg[2*idx + 1], seg[2*idx +2]); 
}

int qry(int L, int R, int l=0, int r=n-1 ,int idx=0){
  if(l > R || r < L) return 0;
  if(r <= R && l >= L) return seg[idx];
  int m = (l + r)/2;

  return max(qry(L, R, l, m, 2*idx + 1), qry(L, R, m+1, r, 2*idx + 2));
}



signed main() {
  cin.tie(0);
  ios::sync_with_stdio(0);
  int m;
  cin >> n >> m;

  vector<int> ord, v(n);
  for(int i=0; i<n; i++) cin >> v[i];
  ord = v;
  ord.push_back(0);
  sort(ord.begin(), ord.end());
  ord.erase(unique(ord.begin(), ord.end()), ord.end());

  upd(0, 1);
  int ans = 1;

  for(int i=0; i<n; i++){
    int l = lower_bound(ord.begin(), ord.end(), v[i] -m) - ord.begin();

    int q = qry(l, n-1);
    if(!q) continue;
    ans = max(ans, q+1);
    
    int id = lower_bound(ord.begin(), ord.end(), v[i]) - ord.begin();
    upd(id, q+1);
  }
  cout << n - (ans -1) << endl;
  return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 328 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Incorrect 0 ms 212 KB Output isn't correct
13 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 328 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Incorrect 0 ms 212 KB Output isn't correct
13 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 328 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Incorrect 0 ms 212 KB Output isn't correct
13 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 328 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Incorrect 0 ms 212 KB Output isn't correct
13 Halted 0 ms 0 KB -