結果
問題 | No.2333 Slime Structure |
ユーザー |
![]() |
提出日時 | 2023-05-28 14:25:56 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 188 ms / 3,000 ms |
コード長 | 8,482 bytes |
コンパイル時間 | 1,420 ms |
コンパイル使用メモリ | 139,584 KB |
最終ジャッジ日時 | 2025-02-13 11:28:27 |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 31 |
ソースコード
#ifndef LOCAL#define FAST_IO#endif// ============#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 i32 = signed int;using i64 = signed long long;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;}template <typename T>Vec<tuple<i32, i32, T>> runlength(const Vec<T> &a) {if (a.empty()) {return Vec<tuple<i32, i32, T>>();}Vec<tuple<i32, i32, T>> ret;i32 prv = 0;REP(i, 1, a.size()) {if (a[i - 1] != a[i]) {ret.emplace_back(prv, i, a[i - 1]);prv = i;}}ret.emplace_back(prv, (i32)a.size(), a.back());return ret;}#ifdef INT128using u128 = __uint128_t;using i128 = __int128_t;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;}#endif[[maybe_unused]] constexpr i32 INF = 1000000100;[[maybe_unused]] constexpr i64 INF64 = 3000000000000000100;struct SetUpIO {SetUpIO() {#ifdef FAST_IOios::sync_with_stdio(false);cin.tie(nullptr);#endifcout << fixed << setprecision(15);}} set_up_io;// ============#ifdef DEBUGF#else#define DBG(x) (void)0#endifstruct Val {i64 sum, mx, lmx, rmx, mx1;};struct Ops {using Value = Val;static Val id() {return Val{0, -INF64, -INF64, -INF64, -INF64};}static Val op(Val l, Val r) {return Val{l.sum + r.sum, max({l.mx, r.mx, l.rmx + r.lmx}), max(l.lmx, l.sum + r.lmx), max(r.rmx, r.sum + l.rmx), max(l.mx1, r.mx1)};}};// ============#include <cassert>#include <utility>#include <vector>// ============#include <limits>#include <utility>template <typename T>struct Add {using Value = T;static Value id() {return T(0);}static Value op(const Value &lhs, const Value &rhs) {return lhs + rhs;}static Value inv(const Value &x) {return -x;}};template <typename T>struct Mul {using Value = T;static Value id() {return Value(1);}static Value op(const Value &lhs, const Value &rhs) {return lhs * rhs;}static Value inv(const Value &x) {return Value(1) / x;}};template <typename T>struct Min {using Value = T;static Value id() {return std::numeric_limits<T>::max();}static Value op(const Value &lhs, const Value &rhs) {return std::min(lhs, rhs);}};template <typename T>struct Max {using Value = T;static Value id() {return std::numeric_limits<Value>::min();}static Value op(const Value &lhs, const Value &rhs) {return std::max(lhs, rhs);}};template <typename T>struct Xor {using Value = T;static Value id() {return T(0);}static Value op(const Value &lhs, const Value &rhs) {return lhs ^ rhs;}static Value inv(const Value &x) {return x;}};template <typename Monoid>struct Reversible {using Value = std::pair<typename Monoid::Value, typename Monoid::Value>;static Value id() {return Value(Monoid::id(), Monoid::id());}static Value op(const Value &v1, const Value &v2) {return Value(Monoid::op(v1.first, v2.first),Monoid::op(v2.second, v1.second));}};// ============template <typename Monoid>class SegmentTree {public:using Value = typename Monoid::Value;private:int old_length;int length;std::vector<Value> node;static int ceil2(int n) {int l = 1;while (l < n) {l <<= 1;}return l;}public:SegmentTree(int n) :old_length(n),length(ceil2(old_length)),node(length << 1, Monoid::id()) {assert(n >= 0);}SegmentTree(const std::vector<Value> &v) :old_length((int) v.size()),length(ceil2(old_length)),node(length << 1, Monoid::id()) {for (int i = 0; i < old_length; ++i) {node[i + length] = v[i];}for (int i = length - 1; i > 0; --i) {node[i] = Monoid::op(node[i << 1], node[i << 1 | 1]);}}template <typename F>SegmentTree(int n, const F &f) :old_length(n), length(ceil2(n)), node(length << 1, Monoid::id()) {assert(n >= 0);for (int i = 0; i < old_length; ++i) {node[i + length] = f(i);}for (int i = length - 1; i > 0; --i) {node[i] = Monoid::op(node[i << 1], node[i << 1 | 1]);}}const Value &operator[](int idx) const {assert(idx >= 0 && idx < old_length);return node[idx + length];}void update(int idx, Value val) {assert(idx >= 0 && idx < old_length);idx += length;node[idx] = std::move(val);while (idx != 1) {idx >>= 1;node[idx] = Monoid::op(node[idx << 1], node[idx << 1 | 1]);}}Value prod(int l, int r) const {assert(l >= 0 && l <= r && r <= old_length);Value prodl = Monoid::id();Value prodr = Monoid::id();l += length;r += length;while (l != r) {if (l & 1) {prodl = Monoid::op(prodl, node[l++]);}if (r & 1) {prodr = Monoid::op(node[--r], prodr);}l >>= 1;r >>= 1;}return Monoid::op(prodl, prodr);}Value all_prod() const {return node[1];}};// ============int main() {i32 n;cin >> n;Vec<i64> a(n), b(n);REP(i, n) {cin >> a[i] >> b[i];}i32 q;cin >> q;Vec<tuple<i32, i64, i64>> queries(q);for (auto &[a, b, c] : queries) {cin >> a >> b >> c;--a;--b;}Vec<i64> orgsps(n + 1, 0);REP(i, n) {orgsps[i + 1] = orgsps[i] + b[i];}Vec<i64> sps = orgsps;for (auto [a, b, c] : queries) {if (a == 0) {sps.push_back(b);sps.push_back(b + 1);} else {sps.push_back(b);sps.push_back(c);}}sort(ALL(sps));sps.erase(unique(ALL(sps)), sps.end());Vec<Val> vals(sps.size() - 1, Ops::id());REP(i, sps.size() - 1) {i32 idx = (i32)(upper_bound(ALL(orgsps), sps[i]) - orgsps.begin() - 1);i64 pw = a[idx];i64 len = sps[i + 1] - sps[i];DBG(sps[i]);DBG(pw);DBG(len);vals[i] = Val{pw * len, max(0LL, pw * len), max(0LL, pw * len), max(0LL, pw * len), pw};}SegmentTree<Ops> seg(vals);for (auto [a, b, c] : queries) {if (a == 0) {i32 idx = (i32)(lower_bound(ALL(sps), b) - sps.begin());seg.update(idx, {c, max(0LL, c), max(0LL, c), max(0LL, c), c});} else {i32 l = (i32)(lower_bound(ALL(sps), b) - sps.begin());i32 r = (i32)(lower_bound(ALL(sps), c) - sps.begin());Val prod = seg.prod(l, r);if (prod.mx1 < 0) {cout << prod.mx1 << '\n';} else {cout << prod.mx << '\n';}}}}