Submission #634365

#TimeUsernameProblemLanguageResultExecution timeMemory
634365ForestedArcade (NOI20_arcade)C++17
85 / 100
1091 ms25624 KiB
#ifndef LOCAL #define FAST_IO #endif // ===== template.hpp ===== #include <algorithm> #include <array> #include <bitset> #include <cassert> #include <cmath> #include <iomanip> #include <iostream> #include <list> #include <map> #include <numeric> #include <queue> #include <random> #include <set> #include <stack> #include <string> #include <tuple> #include <unordered_map> #include <unordered_set> #include <utility> #include <vector> #define OVERRIDE(a, b, c, d, ...) d #define REP2(i, n) for (i32 i = 0; i < (i32) (n); ++i) #define REP3(i, m, n) for (i32 i = (i32) (m); i < (i32) (n); ++i) #define REP(...) OVERRIDE(__VA_ARGS__, REP3, REP2)(__VA_ARGS__) #define PER(i, n) for (i32 i = (i32) (n) - 1; i >= 0; --i) #define ALL(x) begin(x), end(x) using namespace std; using u32 = unsigned int; using u64 = unsigned long long; using u128 = __uint128_t; using i32 = signed int; using i64 = signed long long; using i128 = __int128_t; using f64 = double; using f80 = long double; template <typename T> using Vec = vector<T>; template <typename T> bool chmin(T &x, const T &y) { if (x > y) { x = y; return true; } return false; } template <typename T> bool chmax(T &x, const T &y) { if (x < y) { x = y; return true; } return false; } istream &operator>>(istream &is, i128 &x) { i64 v; is >> v; x = v; return is; } ostream &operator<<(ostream &os, i128 x) { os << (i64) x; return os; } istream &operator>>(istream &is, u128 &x) { u64 v; is >> v; x = v; return is; } ostream &operator<<(ostream &os, u128 x) { os << (u64) x; return os; } [[maybe_unused]] constexpr i32 INF = 1000000100; [[maybe_unused]] constexpr i64 INF64 = 3000000000000000100; struct SetUpIO { SetUpIO() { #ifdef FAST_IO ios::sync_with_stdio(false); cin.tie(nullptr); #endif cout << fixed << setprecision(15); } } set_up_io; // ===== template.hpp ===== #ifdef DEBUGF #include "cpl/template/debug.hpp" #else #define DBG(x) (void) 0 #endif class RMaxQ { i32 n; Vec<i32> node; public: RMaxQ(i32 n) : n(n), node(2 * n, 0) {} void update_max(i32 idx, i32 val) { idx += n; while (idx > 0) { chmax(node[idx], val); idx /= 2; } } i32 range_max(i32 l, i32 r) const { l += n; r += n; i32 ans = 0; while (l < r) { if (l % 2 == 1) { chmax(ans, node[l++]); } if (r % 2 == 1) { chmax(ans, node[--r]); } l /= 2; r /= 2; } return ans; } }; i32 position(const Vec<i32> &xs, i32 x) { return (i32) (lower_bound(ALL(xs), x) - xs.begin()); } int main() { i32 n, m; cin >> n >> m; Vec<i32> t(m), a(m); REP(i, m) { cin >> t[i]; } REP(i, m) { cin >> a[i]; } Vec<pair<i32, i32>> evs(m); REP(i, m) { evs[i].first = a[i]; evs[i].second = t[i]; } sort(ALL(evs)); Vec<i32> dp(m, 0); const auto rec = [&](const auto &rec, i32 l, i32 r) -> void { DBG(l); DBG(r); DBG(dp); if (r - l == 1) { ++dp[l]; return; } i32 mid = (l + r) / 2; rec(rec, l, mid); Vec<i32> xs, ys; xs.reserve(r - l); ys.reserve(r - l); REP(i, l, r) { xs.push_back(evs[i].second - evs[i].first); ys.push_back(evs[i].second); } sort(ALL(xs)); xs.erase(unique(ALL(xs)), xs.end()); sort(ALL(ys)); ys.erase(unique(ALL(ys)), ys.end()); Vec<Vec<pair<i32, i32>>> upd(xs.size()); Vec<Vec<i32>> queries(xs.size()); REP(i, l, mid) { upd[position(xs, evs[i].second - evs[i].first)].emplace_back(position(ys, evs[i].second), dp[i]); } REP(i, mid, r) { queries[position(xs, evs[i].second - evs[i].first)].emplace_back(i); } RMaxQ seg(ys.size()); PER(i, xs.size()) { for (auto j : queries[i]) { i32 y = position(ys, evs[j].second); chmax(dp[j], seg.range_max(0, y + 1)); } for (auto [p, c] : upd[i]) { seg.update_max(p, c); } } xs.clear(); REP(i, l, r) { xs.push_back(evs[i].first + evs[i].second); } sort(ALL(xs)); xs.erase(unique(ALL(xs)), xs.end()); upd = Vec<Vec<pair<i32, i32>>>(xs.size()); queries = Vec<Vec<i32>>(xs.size()); REP(i, l, mid) { upd[position(xs, evs[i].first + evs[i].second)].emplace_back(position(ys, evs[i].second), dp[i]); } REP(i, mid, r) { queries[position(xs, evs[i].first + evs[i].second)].push_back(i); } seg = RMaxQ(ys.size()); REP(i, xs.size()) { for (i32 j : queries[i]) { i32 y = position(ys, evs[j].second); chmax(dp[j], seg.range_max(y + 1, (i32) ys.size())); } for (auto [p, c] : upd[i]) { seg.update_max(p, c); } } rec(rec, mid, r); }; rec(rec, 0, m); cout << *max_element(ALL(dp)) << '\n'; DBG(dp); DBG(evs); }
#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...
#Verdict Execution timeMemoryGrader output
Fetching results...