Submission #394956

#TimeUsernameProblemLanguageResultExecution timeMemory
394956Qw3rTyRabbit Carrot (LMIO19_triusis)C++11
100 / 100
229 ms109880 KiB
#include <bits/stdc++.h> #define int long long #define INF 2e9 using namespace std; const int maxN = 2e5+5; int f[maxN]; //f[i] = length of longest non-increasing subsequence that ends at b[i] int a[maxN]; int b[maxN]; //b[i] = a[i] - M * i 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 = 0; return; } int build(){ tree[++cnt].val = 0; 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(p == 0)return 0; if(a > r || b < l)return 0; 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; } 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; init(); for(int i = 1; i <= N; ++i){ if(b[i] > 0)continue; f[i] = query(1,-INF,0,b[i],INF) + 1; update(1,-INF,0,b[i],b[i],f[i]); } int res = 0; for(int i = 1; i <= N; ++i)res = max(res,f[i]); cout << N - res << '\n'; return 0; }

Compilation message (stderr)

triusis.cpp: In function 'void testIO()':
triusis.cpp:63:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   63 |     freopen("../test.in","r",stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...