Submission #660850

#TimeUsernameProblemLanguageResultExecution timeMemory
660850Danilo21Financial Report (JOI21_financial)C++14
100 / 100
488 ms28364 KiB
#include <bits/stdc++.h> #define ll long long #define ld long double #define pb push_back #define fi first #define se second #define en '\n' #define sp ' ' #define tb '\t' #define ri(n) int n; cin >> n #define rl(n) ll n; cin >> n #define rs(s) string s; cin >> s #define rc(c) char c; cin >> c #define rv(v) for (auto &x : v) cin >> x #define pven(v) for (auto x : v) cout << x << en #define pv(v) for (auto x : v) cout << x << sp; cout << en #define all(v) v.begin(), v.end() #define rall(v) v.rbegin(), v.rend() #define yes cout << "YES" << en #define no cout << "NO" << en #define smin(a, b) a = min(a, b) #define smax(a, b) a = max(a, b) #define ssort(a, b) if (a < b) swap(a, b) #define bitcnt(a) (__builtin_popcountll(a)) #define bithigh(a) (63-__builtin_clzll(a)) #define lg bithigh #define highpow(a) (1LL << (ll)lg(a)) using namespace std; class segtree{ int n; vector<int> tree; int update(int s, int l, int r, int pos, int x){ if (l > pos || r < pos) return tree[s]; if (l == r) return tree[s] = x; int m = (l + r)>>1; int a = update(2*s, l, m, pos, x); int b = update(2*s+1, m+1, r, pos, x); return tree[s] = max(a, b); } int query(int s, int l, int r, int ql, int qr) const { if (l > qr || r < ql) return 0; if (l >= ql && r <= qr) return tree[s]; int m = (l + r)>>1; int a = query(2*s, l, m, ql, qr); int b = query(2*s+1, m+1, r, ql, qr); return max(a, b); } public: void Assign(int s){ n = highpow(s); if (bitcnt(s) > 1) n <<= 1; tree.assign(2*n, 0); } void update(int pos, int x){ update(1, 0, n-1, pos, x); } int query(int l, int r) const { return query(1, 0, n-1, l, r); } }; const ll LINF = 4e18; const int mxN = 1e6+10, INF = 2e9; ll n, m, r[mxN], dp[mxN]; array<ll, 2> a[mxN]; segtree st; void Solve(){ cin >> n >> m; set<int> s; for (int i = 0; i < n; i++){ cin >> a[i][0]; a[i][1] = -i; if (i >= m-1) s.insert(i); } sort(a, a+n); for (int i = 0; i < n; i++){ int j = -a[i][1]; vector<int> v; for (auto it = s.lower_bound(j); it != s.end() && *it < j+m; it++) v.pb(*it); for (int t : v) s.erase(t); auto it = s.lower_bound(j); if (it == s.end()) r[j] = n-1; else r[j] = *it; } reverse(a, a+n); st.Assign(n); int ans = 0; for (int i = 0; i < n; i++){ int j = -a[i][1]; int cur = st.query(j, r[j])+1; smax(ans, cur); st.update(j, cur); } cout << ans << en; } int main(){ ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); cerr.tie(0); cout << setprecision(12) << fixed; cerr << setprecision(12) << fixed; cerr << "Started!" << endl; int t = 1; //cin >> t; while (t--) Solve(); 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...