제출 #763244

#제출 시각아이디문제언어결과실행 시간메모리
763244huutuanFinancial Report (JOI21_financial)C++14
100 / 100
344 ms31656 KiB
#include<bits/stdc++.h> using namespace std; #define int long long #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() #define sz(x) ((int)x.size()) #define sumof(x) accumulate(all(x), 0ll) struct LZST_node{ int x, lz; LZST_node (int a=0, int b=-1): x(a), lz(b){} friend LZST_node sus(const LZST_node& a, const LZST_node& b){ return LZST_node(max(a.x, b.x)); } }; struct LazySegmentTree{ int n; vector<LZST_node> t; void init(int _n){ n=_n; t.assign(4*n+1, LZST_node()); } void down(int k, int l, int r){ int cc=t[k].lz; if (cc==-1) return; t[k<<1].x=cc; t[k<<1|1].x=cc; t[k<<1].lz=cc; t[k<<1|1].lz=cc; t[k].lz=-1; } void build(int k, int l, int r, int* a){ if (l==r){ t[k]=LZST_node(a[l]); return; } int mid=(l+r)>>1; build(k<<1, l, mid, a); build(k<<1|1, mid+1, r, a); t[k]=sus(t[k<<1], t[k<<1|1]); } void init(int _n, int* a){ init(_n); build(1, 1, n, a); } void update(int k, int l, int r, int L, int R, int val){ if (r<L || R<l) return; if (L<=l && r<=R){ t[k].x=val; t[k].lz=val; return; } down(k, l, r); int mid=(l+r)>>1; update(k<<1, l, mid, L, R, val); update(k<<1|1, mid+1, r, L, R, val); t[k]=sus(t[k<<1], t[k<<1|1]); } LZST_node get(int k, int l, int r, int L, int R){ if (r<L || R<l) return t[0]; if (L<=l && r<=R) return t[k]; down(k, l, r); int mid=(l+r)>>1; return sus(get(k<<1, l, mid, L, R), get(k<<1|1, mid+1, r, L, R)); } void update(int L, int R, int val){ update(1, 1, n, L, R, val); } int get(int l, int r){ return get(1, 1, n, l, r).x; } } st; const int N=3e5+1; int n, d, a[N], f[N], min_d[N]; void solve(int tc){ // cout << "Case #" << tc << ": "; cin >> n >> d; vector<int> v; for (int i=1; i<=n; ++i) cin >> a[i], v.push_back(a[i]); sort(all(v)); v.resize(unique(all(v))-v.begin()); for (int i=1; i<=n; ++i) a[i]=lower_bound(all(v), a[i])-v.begin()+1; deque<int> dq; for (int i=1; i<=n; ++i){ while (dq.size() && a[i]<=a[dq.back()]) dq.pop_back(); while (dq.size() && i-dq.front()>=d) dq.pop_front(); dq.push_back(i); if (i>=d) min_d[i]=a[dq.front()]; } st.init(N); for (int i=1; i<=n; ++i){ f[i]=1; f[i]=max(f[i], st.get(1, a[i]-1)+1); st.update(a[i], a[i], max(st.get(a[i], a[i]), f[i])); f[i]=max(f[i], st.get(a[i], N)); if (i>=d) st.update(1, min_d[i]-1, 0); } cout << f[n]; } int32_t main(){ ios_base::sync_with_stdio(false); cin.tie(nullptr); int ntests=1; // cin >> ntests; for (int i=1; i<=ntests; ++i) solve(i); 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...