Submission #498495

#TimeUsernameProblemLanguageResultExecution timeMemory
498495khoabrightFinancial Report (JOI21_financial)C++17
5 / 100
266 ms9996 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define pii pair<int, int> #define ff first #define ss second #define pb push_back #define rep(i, a, b) for (int i = (int)a; i <= (int)b; ++i) #define rep1(i, a, b) for (int i = (int)a; i >= (int)b; --i) #define all(x) x.begin(), x.end() struct segtree { int sz = 1; vector<int> maxi; void init(int SIZE) { while (sz < SIZE) sz *= 2; maxi.resize(2 * sz); } void update(int i, int v, int x, int lx, int rx) { if (rx - lx == 1) { maxi[x] = v; return; } int m = (lx + rx) >> 1; if (i < m) update(i, v, 2 * x + 1, lx, m); else update(i, v, 2 * x + 2, m, rx); maxi[x] = max(maxi[2 * x + 1], maxi[2 * x + 2]); } void update(int i, int v) {update(i, v, 0, 0, sz);} int query(int l, int r, int x, int lx, int rx) { if (rx <= l || r <= lx) return 0; if (l <= lx && rx <= r) return maxi[x]; int m = (lx + rx) >> 1; return max(query(l, r, 2 * x + 1, lx, m), query(l, r, 2 * x + 2, m, rx)); } int query(int l, int r) {return query(l, r, 0, 0, sz);} }; bool cmp(pii x, pii y) { return make_pair(x.ff, -x.ss) < make_pair(y.ff, -y.ss); } void solve() { int n, d; cin >> n >> d; vector<pii> a(n + 1); rep(i, 1, n) cin >> a[i].ff, a[i].ss = i; sort(a.begin() + 1, a.end(), cmp); segtree st; st.init(n + 1); st.update(0, 5); int ans = 0; rep(i, 1, n) { int l = max(1, a[i].ss - d); int tmp = st.query(l, a[i].ss) + 1; st.update(a[i].ss, tmp); ans = max(ans, tmp); } cout << ans; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); solve(); }
#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...