Submission #885896

# Submission time Handle Problem Language Result Execution time Memory
885896 2023-12-11T02:20:34 Z ByeWorld Studentsko (COCI14_studentsko) C++14
100 / 100
5 ms 2652 KB
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,unroll-loops")
#define bupol __builtin_popcount
#define int long long 
#define ll long long
#define ld long double
#define fi first
#define se second
#define pb push_back
#define lf (id<<1)
#define rg ((id<<1)|1)
#define md ((l+r)>>1)
using namespace std;
const int MAXN = 3e5+20;
const int LOG = 60;
const int MOD = 998244353;
const int SQRT = 520;
const int INF = 1e18;
typedef pair<int,int> pii;
typedef pair<pii,int> ipii;
 
int n, k;
int a[MAXN];

struct seg {
    int st[4*MAXN];
    int que(int id, int l, int r, int x, int y){
        if(x<=l && r<=y) return st[id];
        if(r<x || y<l) return -INF;
        return max(que(lf, l, md, x, y), que(rg, md+1, r, x, y));
    }
    int upd(int id, int l, int r, int x, int y){
        if(x<=l && r<=x) return st[id] = y;
        if(r<x || x<l) return st[id];
        return st[id] = max(upd(lf, l, md, x, y), upd(rg, md+1, r, x, y));
    }
} A;
signed main(){
    //ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    vector <int> vec;
    cin >> n >> k;
    for(int i=1; i<=n; i++){
        cin >> a[i];
        vec.pb(a[i]);
    }
    sort(vec.begin(), vec.end());
    for(int i=1; i<=n; i++){
        a[i] = lower_bound(vec.begin(), vec.end(), a[i]) - vec.begin();
        a[i] /= k; a[i]++;
    }
    for(int i=1; i<=n; i++){
        int qu = A.que(1, 1, n, 1, a[i]);
        A.upd(1, 1, n, a[i], qu+1);
    }
    cout << n-A.que(1, 1, n, 1, n) << '\n';
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2652 KB Output is correct
2 Correct 2 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 2652 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 2648 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 2652 KB Output is correct
2 Correct 3 ms 2652 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 2648 KB Output is correct
2 Correct 5 ms 2652 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 2576 KB Output is correct
2 Correct 3 ms 2652 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 2652 KB Output is correct
2 Correct 3 ms 2556 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 2652 KB Output is correct
2 Correct 3 ms 2652 KB Output is correct