제출 #763200

#제출 시각아이디문제언어결과실행 시간메모리
763200huutuanFinancial Report (JOI21_financial)C++14
0 / 100
184 ms50576 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 ST_node{ int x; ST_node (int a=0): x(a){} friend ST_node sus(const ST_node& a, const ST_node& b){ return ST_node(max(a.x, b.x)); } }; struct SegmentTree{ int n; vector<ST_node> t; void init(int _n){ n=_n; t.assign(4*n+1, ST_node()); } void build(int k, int l, int r, int* a){ if (l==r){ t[k]=ST_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 pos, int val){ if (l==r){ t[k]=ST_node(val); return; } int mid=(l+r)>>1; if (pos<=mid) update(k<<1, l, mid, pos, val); else update(k<<1|1, mid+1, r, pos, val); t[k]=sus(t[k<<1], t[k<<1|1]); } ST_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]; 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 pos, int val){ update(1, 1, n, pos, 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]; set<pair<int, int>> val[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; st.init(N); for (int i=1; i<=n; ++i){ int g=1; g=max(g, st.get(1, a[i]-1)+1); g=max(g, st.get(a[i], N)); val[a[i]].emplace(g, i); f[i]=g; if (i>d){ val[a[i-d]].erase({f[i], i}); st.update(a[i-d], val[a[i-d]].empty()?0:val[a[i-d]].rbegin()->first); } } 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...