Submission #744633

# Submission time Handle Problem Language Result Execution time Memory
744633 2023-05-18T21:03:22 Z vjudge1 Rabbit Carrot (LMIO19_triusis) C++17
0 / 100
1 ms 328 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;
  sort(ord.begin(), ord.end());
  ord.erase(unique(ord.begin(), ord.end()), ord.end());

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

    int mx = qry(l, n-1) + 1;
    ans = max(ans, mx);

    int id = lower_bound(ord.begin(), ord.end(), v[i]) -ord.begin();
    upd(id, mx);
  }
  cout << n - ans << 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 1 ms 328 KB Output is correct
4 Correct 1 ms 324 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 328 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Incorrect 1 ms 328 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 1 ms 328 KB Output is correct
4 Correct 1 ms 324 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 328 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Incorrect 1 ms 328 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 1 ms 328 KB Output is correct
4 Correct 1 ms 324 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 328 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Incorrect 1 ms 328 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 1 ms 328 KB Output is correct
4 Correct 1 ms 324 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 328 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Incorrect 1 ms 328 KB Output isn't correct
13 Halted 0 ms 0 KB -