제출 #1311602

#제출 시각아이디문제언어결과실행 시간메모리
1311602anteknneFinancial Report (JOI21_financial)C++20
100 / 100
436 ms26236 KiB
#include<bits/stdc++.h> #include<ext/pb_ds/assoc_container.hpp> #include<ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; typedef long long ll; typedef long double ld; #define pb push_back #define pii pair<int, int> #define pll pair<ll, ll> #define st first #define nd second #define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> #define debug false const int MAXN = 300 * 1000 + 17; int a[MAXN]; vector<int> v; int st[4 * MAXN]; int lazy[4 * MAXN]; int dp[MAXN]; multiset<int> akt; void szykuj(int i) { if (lazy[i] != -1) { lazy[2 * i] = lazy[i]; st[2 * i] = lazy[i]; lazy[2 * i + 1] = lazy[i]; st[2 * i + 1] = lazy[i]; lazy[i] = -1; } } void aktualizuj (int p, int k, int a, int b, ll x, int i) { if (b < p || a > k) { return; } if (a <= p && k <= b) { lazy[i] = x; st[i] = x; return; } szykuj(i); int sr = (p + k)/2; aktualizuj(p, sr, a, b, x, i * 2); aktualizuj(sr + 1, k, a, b, x, i * 2 + 1); st[i] = max(st[i * 2], st[i * 2 + 1]); } int odczytaj (int p, int k, int a, int b, int i) { if (b < p || a > k) { return 0; } if (a <= p && k <= b) { return st[i]; } szykuj(i); int sr = (p + k)/2; ll akt = max(odczytaj(p, sr, a, b, i * 2), odczytaj(sr + 1, k, a, b, i * 2 + 1)); st[i] = max(st[i * 2], st[i * 2 + 1]); return akt; } int main () { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, d; cin >> n >> d; for (int i = 0; i < n; i ++) { cin >> a[i]; } for (int i = 0; i < n; i ++) { v.pb(a[i]); } sort(v.begin(), v.end()); v.erase(unique(v.begin(), v.end()), v.end()); int m = int(v.size()); for (int i = 0; i < n; i ++) { a[i] = lower_bound(v.begin(), v.end(), a[i]) - v.begin() + 1; } int wyn = 0; for (int i = 0; i < n; i ++) { int x = a[i]; dp[i] = odczytaj(0, m, 0, x - 1, 1) + 1; int w = odczytaj(0, m, x, x, 1); aktualizuj(0, m, x, x, max(dp[i], w), 1); wyn = max(wyn, dp[i]); akt.insert(a[i]); if (i - d >= 0) { akt.erase(akt.find(a[i - d])); int x = *akt.begin(); aktualizuj(0, m, 0, x - 1, 0, 1); } } cout << wyn << "\n"; 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...