Submission #499911

# Submission time Handle Problem Language Result Execution time Memory
499911 2021-12-30T01:05:42 Z RandomLB Rabbit Carrot (LMIO19_triusis) C++17
0 / 100
1 ms 332 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pi;
typedef pair<ll, ll> pll;
typedef pair<double, double> point;
typedef tuple<int, int, int> tp;  //-------LL
typedef unordered_set<ll> uset;
typedef priority_queue<pll, vector<pll>, greater<pll>> djk;
typedef long long C;
typedef complex<C> P;
#define pb push_back
#define ms(a,b) memset(a,b,sizeof(a))
#define maxE(a) *max_element(a, a+sizeof(a)/sizeof(a[0]))
#define minE(a) *min_element(a, a+sizeof(a)/sizeof(a[0]))
#define F first
#define S second
#define siz(a) (int)a.size()
#define len(a) (int)a.length()
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define bits(x) __builtin_popcount(x)
#define vvll vector<vector<ll>>
#define FOR(a, n) for (int a = 0; a < n; a++)
#define fin(s) {cout << s << "\n"; return;}
#define finm(s) {cout << s << "\n"; return 0;}
#define X real()
#define Y imag()
#define deb(...) logger(#__VA_ARGS__, __VA_ARGS__)
template<typename ...Args>
void logger(string vars, Args&&... values) {
    cout << vars << " = ";
    string delim = "";
    (..., (cout << delim << values, delim = ", "));
    cout << endl;
}
template<class T>
istream& operator >> (istream& is, complex<T>& p) {
  T value;
  is >> value; p.real(value);
  is >> value; p.imag(value);
  return is;
}
const int INF = 0x3f3f3f3f;
const ll LLINF = 0x3f3f3f3f3f3f3f3f;
const ll MOD = 1e9+7;
const double pie = 2*acos(0.0);
//------------------------------------------------------------
const int MAX = 2e5+5;
const int MAX2 = 8e5+5;
int arr[MAX], range[MAX], st[MAX2], mx;
vector<int> v;
unordered_map<int, int> f;

void update(int i, int l, int r, int k, int val){
    if (l == r){
        st[i] = max(st[i], val);
        return;
    }
    int mid = l+(r-l)/2;
    if (k <= mid) update(2*i, l, mid, k, val);
    else update(2*i+1, mid+1, r, k, val);
    st[i] = max(st[2*i], st[2*i+1]);
}

int query(int i, int l, int r, int tl, int tr){
    if (l > tr || r < tl) return 0;
    if (tl <= l && r <= tr) return st[i];
    int mid = l+(r-l)/2;
    return max(query(2*i, l, mid, tl, tr), query(2*i+1, mid+1, r, tl, tr));
}

int main(){
    cin.tie(0)->sync_with_stdio(0);
    //freopen("test.txt", "r", stdin);
    int n, m; cin >> n >> m;
    v.pb(0);
    for (int i = 1; i <= n; i++){
        cin >> arr[i];
        v.pb(arr[i]);
    }
    sort(all(v));
    int l = 0, curr = 0;
    for (int i = 0; i <= n; i++){
        if (i == 0 || v[i] != v[i-1]) curr++;
        f[v[i]] = curr;
        while (v[i] - v[l] > m) l++;
        range[curr] = f[v[l]];
    }
    for (int i = 1; i <= n; i++){
        //deb(arr[i], f[arr[i]], range[f[arr[i]]]);
    }
    for (int i = 1; i <= n; i++){
        int dp = query(1, 1, curr, range[f[arr[i]]], curr);
        if (arr[i] <= m*i) dp++;
        //deb(range[f[arr[i]]], f[arr[i]], dp);
        mx = max(mx, dp);
        update(1, 1, curr, f[arr[i]], dp);
    }
    cout << n-mx << "\n";
}

/* stuff you should look for
	* int overflow, array bounds
	* test case inputs don't carry over (DON'T RETURN EARLY)
	* special cases (n=1?)
	* do smth instead of nothing and stay organized
	* WRITE STUFF DOWN
	* DON'T GET STUCK ON ONE APPROACH
*/
# Verdict Execution time Memory Grader output
1 Correct 0 ms 320 KB Output is correct
2 Correct 0 ms 320 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 1 ms 252 KB Output is correct
7 Correct 0 ms 324 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 0 ms 332 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 0 ms 332 KB Output is correct
12 Incorrect 0 ms 332 KB Output isn't correct
13 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 320 KB Output is correct
2 Correct 0 ms 320 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 1 ms 252 KB Output is correct
7 Correct 0 ms 324 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 0 ms 332 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 0 ms 332 KB Output is correct
12 Incorrect 0 ms 332 KB Output isn't correct
13 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 320 KB Output is correct
2 Correct 0 ms 320 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 1 ms 252 KB Output is correct
7 Correct 0 ms 324 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 0 ms 332 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 0 ms 332 KB Output is correct
12 Incorrect 0 ms 332 KB Output isn't correct
13 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 320 KB Output is correct
2 Correct 0 ms 320 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 1 ms 252 KB Output is correct
7 Correct 0 ms 324 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 0 ms 332 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 0 ms 332 KB Output is correct
12 Incorrect 0 ms 332 KB Output isn't correct
13 Halted 0 ms 0 KB -