Submission #959544

#TimeUsernameProblemLanguageResultExecution timeMemory
959544Alkaser_IDFinancial Report (JOI21_financial)C++17
0 / 100
40 ms13092 KiB
#include <iostream> #include <algorithm> #include <vector> #include <map> #include <set> #include <queue> using namespace std; typedef long long ll; // second mod 998244353 const ll N = 3e5 + 5; ll a[N], b[N], dp[N]; struct order { ll i, v; }; bool cmp(order x, order y) { if (x.v == y.v) return x.i > y.i; return x.v < y.v; } ll seg[10 * N]; inline void update(ll node, ll l, ll r, ll ind, ll vl) { if (l == r) return void(seg[node] = vl); ll mid = (l + r) / 2; if (ind <= mid) update(node * 2, l, mid, ind, vl); else update(node * 2 + 1, mid + 1, r, ind, vl); seg[node] = max(seg[node * 2], seg[node * 2 + 1]); } inline void del(ll node, ll l, ll r, ll ind) { if (l == r) return void(seg[node] = 0); ll mid = (l + r) / 2; if (ind <= mid) del(node * 2, l, mid, ind); else del(node * 2 + 1, mid + 1, r, ind); seg[node] = max(seg[node * 2], seg[node * 2 + 1]); } inline ll get(ll node, ll l, ll r, ll lx, ll rx) { if (l >= lx && r <= rx) return seg[node]; if (l > rx || r < lx) return 0; ll mid = (l + r) / 2; ll r1 = get(node * 2, l, mid, lx, rx); ll r2 = get(node * 2 + 1, mid + 1, r, lx, rx); return max(r1, r2); } int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); ll n, d; cin >> n >> d; vector<ll> v; map<ll, ll> cm; for (ll i = 1; i <= n; ++i) { cin >> a[i]; v.push_back(a[i]); } sort(v.begin(), v.end()); ll MX = 2; for (ll i = 1; i < n; ++i) { if (v[i] != v[i - 1]) cm[v[i]] = MX++; } ++MX; for (ll i = 1; i <= n; ++i) a[i] = cm[a[i]]; ll res = 0; for (ll i = n; i > 0; --i) { if (n - i <= d) { ll x = get(1, 1, MX, a[i] + 1, MX); ++x; res = max(res, x); update(1, 1, MX, a[i], x); dp[i] = x; } else { ll k = 0; for (ll j = i + 1, cn = 1; j <= n && cn <= d; ++j, ++cn) { if (a[j] > a[i]) k = max(k, dp[j]); } ll x = k + 1; res = max(res, x); dp[i] = x; } } cout << res; }
#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...