제출 #530859

#제출 시각아이디문제언어결과실행 시간메모리
530859chaoyueFinancial Report (JOI21_financial)C++17
48 / 100
4072 ms37848 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long struct node{ int s, e, m, idx, val, lazyidx; bool removed; node *l, *r; node(int S, int E){ s = S; e = E; m = (s+e)/2; idx = INT_MAX; if(s == 0){ val = -1; } else{ val = INT_MAX; } removed = 0; lazyidx = 0; if(s != e){ l = new node(s, m); r = new node(m+1, e); } } void propagate(){ if(removed){ idx = INT_MAX; val = INT_MAX; if(s != e){ l->removed = 1; r->removed = 1; } removed = 0; } if(lazyidx){ idx = lazyidx; if(s != e){ l->lazyidx = lazyidx; r->lazyidx = lazyidx; } lazyidx = 0; } } void remove(int lim){ //might take O(n^2), maybe need introduce minidx propagate(); if(idx < lim){ removed = 1; propagate(); return; } if(s != e){ l->remove(lim); r->remove(lim); idx = max(l->idx, r->idx); val = min(l->val, r->val); } } void setidx(int i, int x){ propagate(); if(val >= x){ lazyidx = i; propagate(); return; } if(s != e){ l->setidx(i, x); r->setidx(i, x); idx = max(l->idx, r->idx); } } void extend(int pos, int i, int x){ propagate(); if(s > pos || e < pos) return; if(s == pos && e == pos){ val = x; idx = i; } if(s != e){ l->extend(pos, i, x); r->extend(pos, i, x); idx = max(l->idx, r->idx); val = min(l->val, r->val); } } int walk(int x){ propagate(); if(s == e) return s; if(r->val < x) return r->walk(x); return l->walk(x); } } *root; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); int n, d, x, pos; cin>>n>>d; root = new node(0, n); for(int i=0; i<n; i++){ cin>>x; root->remove(i-d); pos = root->walk(x); root->extend(pos + 1, i, x); root->setidx(i, x); } pos = root->walk(INT_MAX-1); cout<<pos; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...