Submission #888124

#TimeUsernameProblemLanguageResultExecution timeMemory
888124sleepntsheepFinancial Report (JOI21_financial)C++17
0 / 100
3095 ms1048576 KiB
#include <iostream> #include <stack> #include <fstream> #include <iomanip> #include <cmath> #include <cassert> #include <cstring> #include <vector> #include <algorithm> #include <deque> #include <set> #include <utility> #include <array> #include <complex> using i64 = long long; using u64 = unsigned long long; using f64 = double; using f80 = long double; using namespace std; using pt = complex<f80>; #define ALL(x) begin(x), end(x) #define ShinLena cin.tie(nullptr)->sync_with_stdio(false); #define N 200005 struct segment_tree { int n; vector<int> t; segment_tree(int n0) : n(n0), t(n0<<1) {} stack<pair<int, int>> save; stack<unsigned> savepoint; void __set(int p, int k) { save.emplace(p, t[p]); t[p] = k; } void chmax(int p, int k) { savepoint.push(save.size()); for (p += n, __set(p, max(t[p], k)); p >>= 1;) __set(p, max(t[p<<1], t[p<<1|1])); } int query(int l, int r) { int z{0}; for (l += n, r += n; l < r; l >>= 1, r >>= 1) { if (l&1) z = max(z, t[l++]); if (r&1) z = max(t[--r], z); } return z; } void rollback() { while (save.size() > savepoint.top()) { auto [p, tp] = save.top(); t[p] = tp; save.pop(); } savepoint.pop(); } }; class queue_segment_tree { public: segment_tree t; struct update { char type; int p, k; }; unsigned bottom = 0; vector<update> S; queue_segment_tree(int n) : t(n) {} void chmax(int p, int k) { S.emplace_back(update{'B', p, k}); t.chmax(p, k); } int query(int l, int r) { return t.query(l, r); } void pop() { bottomify(); if (bottom == S.size()) new_phase(); fix(); t.rollback(); S.pop_back(); } private: void bottomify() { while (bottom < S.size() && S[bottom].type == 'B') ++bottom; } void fix() { if (S.back().type == 'A') return; bottomify(); vector<update> s[2]; while (S.size() > bottom && (s[0].empty() || s[0].size() != s[1].size())) { s[S.back().type == 'B'].emplace_back(S.back()); t.rollback(); S.pop_back(); } for (auto j : {1, 0}) for (auto it = rbegin(s[j]); it != rend(s[j]); ++it) S.push_back(*it), t.chmax(it->p, it->k); bottomify(); } void new_phase() { for (const auto &_ : S) t.rollback(), (void)_; reverse(ALL(S)); for (auto &x : S) t.chmax(x.p, x.k), x.type = 'A'; bottom = 0; } }; int main() { ShinLena; int n, d; cin >> n >> d; vector<int> a(n), c; for (auto &x : a) cin >> x; c = a; sort(ALL(c)); for (auto &x : a) x = lower_bound(ALL(c), x) - c.begin(); queue_segment_tree t(c.size()); int z = 0; for (int i = 0; i < n; ++i) { if (i > d) t.pop(); int r0 = t.query(0, a[i]) + 1; z = max({z, r0}); if (i == n - 1) return cout << z , 0; t.chmax(a[i], r0); for (int j = a[i]; j < c.size(); ++j) { t.chmax(j, t.query(0, j+1)); } } return 0; }

Compilation message (stderr)

Main.cpp: In function 'int main()':
Main.cpp:150:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  150 |         for (int j = a[i]; j < c.size(); ++j)
      |                            ~~^~~~~~~~~~
#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...