제출 #742759

#제출 시각아이디문제언어결과실행 시간메모리
742759ToniBFinancial Report (JOI21_financial)C++17
53 / 100
655 ms36280 KiB
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e6; const int OFF = 1 << 21; int n, d, a[MAXN], ans, dp[7005]; bool ok[7005]; int tour[OFF]; priority_queue<int, vector<int>, greater<int> > pq; multiset<int> ms; vector<int> cmp; map<int, int> um; int f(int x, int l, int r, int ql, int qr){ if(ql <= l && r <= qr) return tour[x]; if(ql > r || l > qr) return 0; int mid = (l + r) >> 1; return max(f(x * 2 + 1, l, mid, ql, qr), f(x * 2 + 2, mid + 1, r, ql, qr)); } void upd(int x, int l, int r, int i, int val){ if(l > i || r < i) return ; if(l == r){ tour[x] = val; return ; } int mid = (l + r) >> 1; upd(x * 2 + 1, l, mid, i, val); upd(x * 2 + 2, mid + 1, r, i, val); tour[x] = max(tour[x * 2 + 1], tour[x * 2 + 2]); } int main(){ cin >> n >> d; for(int i = 0; i < n; ++i){ cin >> a[i]; cmp.push_back(a[i]); } sort(cmp.begin(), cmp.end()); cmp.erase(unique(cmp.begin(), cmp.end()), cmp.end()); for(int i = 0; i < (int)cmp.size(); ++i) um[cmp[i]] = i; for(int i = 0; i < n; ++i) a[i] = um[a[i]]; if(n < 7005){ for(int i = 0; i < n; ++i){ dp[i] = 0; for(int j = i - 1; j >= 0; --j){ if(a[j] < a[i]) dp[i] = max(dp[i], dp[j]); } ms.insert(a[i]); pq.push(a[i]); ++dp[i]; // assume [i - d + 1..i] blocks j <= i - d if(i - d >= 0){ ms.erase(ms.find(a[i - d])); int mini = *ms.begin(); for(int j = i; j >= 0; --j){ if(a[j] < mini) dp[j] = 0; } while(pq.top() < mini){ for(int j = 0; j < i; ++j){ if(a[j] == pq.top()) dp[j] = 0; } pq.pop(); } } ans = max(ans, dp[i]); } cout << ans << "\n"; return 0; } for(int i = 0; i < n; ++i){ int x = 0; if(a[i]) x = f(0, 0, n - 1, 0, a[i] - 1); upd(0, 0, n - 1, a[i], x + 1); ans = max(ans, x + 1); ms.insert(a[i]); pq.push(a[i]); if(i >= d){ ms.erase(ms.find(a[i - d])); int mini = *ms.begin(); while(!pq.empty() && pq.top() < mini){ int idx = pq.top(); upd(0, 0, n - 1, idx, 0); pq.pop(); } } } cout << ans; 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...