Submission #394931

# Submission time Handle Problem Language Result Execution time Memory
394931 2021-04-27T13:57:16 Z Qw3rTy Rabbit Carrot (LMIO19_triusis) C++11
0 / 100
1 ms 332 KB
#include <bits/stdc++.h>
#define INF 2e9
using namespace std;

const int maxN = 2e5+5;

int f[maxN];
int a[maxN];
int b[maxN];
int N,M;

struct node{
    int val,lc,rc;
    node(){};
}tree[maxN*100];

int cnt;

void init(){
    cnt = 1;
    tree[cnt].lc = tree[cnt].rc = 0;
    tree[cnt].val = -INF;
    return;
}

int build(){
    tree[++cnt].val = -INF;
    tree[cnt].lc = 0;
    tree[cnt].rc = 0;
    return cnt;
}

void pushup(int p){
    tree[p].val = max(tree[tree[p].lc].val,tree[tree[p].rc].val);
    return;
}

void update(int p, int l, int r, int a, int b, int val){
    if(a > r || b < l)return;
    if(a <= l && r <= b){
        tree[p].val = max(tree[p].val,val);
        return;
    }
    int mid = (l+r)>>1;
    if(tree[p].lc == 0)tree[p].lc = build();
    if(tree[p].rc == 0)tree[p].rc = build();
    update(tree[p].lc,l,mid,a,b,val);
    update(tree[p].rc,mid+1,r,a,b,val);
    pushup(p);
    return;
}

int query(int p, int l, int r, int a, int b){
    if(a > r || b < l)return -INF;
    if(a <= l && r <= b)return tree[p].val;
    int mid = (l+r)>>1;
    return max(query(tree[p].lc,l,mid,a,b),query(tree[p].rc,mid+1,r,a,b));
}

void testIO(){
    freopen("../test.in","r",stdin);
    return;
}

int find_lis(vector<int> a) {
    vector<int> dp;
    for (int i : a) {
        int pos = lower_bound(dp.begin(), dp.end(), i) - dp.begin();
        if (pos == dp.size())  // we can have a new, longer increasing subsequence!
            dp.push_back(i);
        else  // oh ok, at least we can make the ending element smaller
            dp[pos] = i;
    }
    return dp.size();
}

int LIS(){
    vector<int> dp;
    for(int i = 1; i <= N; ++i){
        int pos = lower_bound(dp.begin(),dp.end(),a[i]) - dp.begin();
        if(pos == 0)dp.push_back(a[i]);
        else dp[pos] = a[i];
    }
    return dp.size();
}

signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    //testIO();
    cin >> N >> M;
    for(int i = 1; i <= N; ++i)cin >> a[i];
    a[0] = 0;
    f[0] = 0;
    //O(NlogN)
    //find LIS on b[i], where b[i] = a[i] - M*i
    for(int i = 1; i <= N; ++i)b[i] = a[i] - M*i;
//    for(int i = 1; i <= N; ++i){
//        if(a[i] > M*i)continue;
//        f[i] = max(f[i], query(1,-INF,INF,a[i]-M*i,INF) +1);
//        update(1,-INF,INF,a[i]-M*i,a[i]-M*i,f[i]);
//    }
    int res = LIS();
    cout << N - res << '\n';
    return 0;
}

Compilation message

triusis.cpp: In function 'int find_lis(std::vector<int>)':
triusis.cpp:69:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   69 |         if (pos == dp.size())  // we can have a new, longer increasing subsequence!
      |             ~~~~^~~~~~~~~~~~
triusis.cpp: In function 'void testIO()':
triusis.cpp:61:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   61 |     freopen("../test.in","r",stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Incorrect 1 ms 332 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Incorrect 1 ms 332 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Incorrect 1 ms 332 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Incorrect 1 ms 332 KB Output isn't correct
3 Halted 0 ms 0 KB -