Submission #1229693

#TimeUsernameProblemLanguageResultExecution timeMemory
1229693SpyrosAlivFinancial Report (JOI21_financial)C++20
5 / 100
115 ms10552 KiB
#include <bits/stdc++.h> using namespace std; int n, d; vector<int> arr; class segTree { private: vector<int> seg; int query(int node, int start, int end, int l, int r) { if (start > r || end < l) return 0; else if (start >= l && end <= r) return seg[node]; else { int mid = (start + end) / 2; return max(query(node*2, start, mid, l, r), query(node*2+1, mid+1, end, l, r)); } } void update(int node, int start, int end, int idx, int v) { if (start == end) { seg[node] = v; } else { int mid = (start + end) / 2; if (idx <= mid) update(node*2, start, mid, idx, v); else update(node*2+1, mid+1, end, idx, v); seg[node] = max(seg[node*2], seg[node*2+1]); } } public: segTree(int nn) { n = nn; seg.assign(n*4+10, 0); } int query(int l, int r) { l = max(0, l); return query(1, 0, n-1, l, r); } void update(int idx, int v) { update(1, 0, n-1, idx, v); } }; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> n >> d; for (int i = 0; i < n; i++) { int x; cin >> x; arr.push_back(x); } segTree dp(n); vector<pair<int, int>> vals; for (int i = 0; i < n; i++) { vals.push_back({arr[i], i}); } sort(vals.begin(), vals.end(), [&](pair<int, int> a, pair<int, int> b) { if (a.first != b.first) return a.first < b.first; else return a.second > b.second; }); int ans = 0; for (auto [foo, idx]: vals) { int dp2 = dp.query(idx - d, idx) + 1; ans = max(ans, dp2); dp.update(idx, dp2); } cout << ans << "\n"; }
#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...