結果
問題 | No.2333 Slime Structure |
ユーザー | 👑 hitonanode |
提出日時 | 2023-05-28 14:45:08 |
言語 | C++23 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 228 ms / 3,000 ms |
コード長 | 3,100 bytes |
コンパイル時間 | 2,004 ms |
コンパイル使用メモリ | 191,764 KB |
実行使用メモリ | 69,212 KB |
最終ジャッジ日時 | 2023-08-27 10:31:38 |
合計ジャッジ時間 | 10,800 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge11 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
4,380 KB |
testcase_01 | AC | 1 ms
4,380 KB |
testcase_02 | AC | 101 ms
35,868 KB |
testcase_03 | AC | 124 ms
39,404 KB |
testcase_04 | AC | 143 ms
39,536 KB |
testcase_05 | AC | 110 ms
36,784 KB |
testcase_06 | AC | 159 ms
41,104 KB |
testcase_07 | AC | 191 ms
68,176 KB |
testcase_08 | AC | 197 ms
68,324 KB |
testcase_09 | AC | 197 ms
68,332 KB |
testcase_10 | AC | 194 ms
68,452 KB |
testcase_11 | AC | 190 ms
68,112 KB |
testcase_12 | AC | 191 ms
68,084 KB |
testcase_13 | AC | 189 ms
67,888 KB |
testcase_14 | AC | 187 ms
67,652 KB |
testcase_15 | AC | 188 ms
67,952 KB |
testcase_16 | AC | 188 ms
68,120 KB |
testcase_17 | AC | 192 ms
68,448 KB |
testcase_18 | AC | 188 ms
68,004 KB |
testcase_19 | AC | 190 ms
67,944 KB |
testcase_20 | AC | 189 ms
68,716 KB |
testcase_21 | AC | 193 ms
68,420 KB |
testcase_22 | AC | 208 ms
67,548 KB |
testcase_23 | AC | 205 ms
67,768 KB |
testcase_24 | AC | 228 ms
67,440 KB |
testcase_25 | AC | 205 ms
68,684 KB |
testcase_26 | AC | 202 ms
67,688 KB |
testcase_27 | AC | 199 ms
67,572 KB |
testcase_28 | AC | 203 ms
68,044 KB |
testcase_29 | AC | 201 ms
67,552 KB |
testcase_30 | AC | 202 ms
68,792 KB |
testcase_31 | AC | 200 ms
68,280 KB |
testcase_32 | AC | 167 ms
69,212 KB |
ソースコード
#include <algorithm> #include <array> #include <bitset> #include <cassert> #include <chrono> #include <cmath> #include <complex> #include <deque> #include <forward_list> #include <fstream> #include <functional> #include <iomanip> #include <ios> #include <iostream> #include <limits> #include <list> #include <map> #include <numeric> #include <queue> #include <random> #include <set> #include <sstream> #include <stack> #include <string> #include <tuple> #include <type_traits> #include <unordered_map> #include <unordered_set> #include <utility> #include <vector> using namespace std; using lint = long long; #define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++) #define REP(i, n) FOR(i,0,n) template <class T> std::vector<T> sort_unique(std::vector<T> vec) { sort(vec.begin(), vec.end()), vec.erase(unique(vec.begin(), vec.end()), vec.end()); return vec; } template <class T> int arglb(const std::vector<T> &v, const T &x) { return std::distance(v.begin(), std::lower_bound(v.begin(), v.end(), x)); } template <class T> int argub(const std::vector<T> &v, const T &x) { return std::distance(v.begin(), std::upper_bound(v.begin(), v.end(), x)); } #include <atcoder/segtree> constexpr lint inf = 1LL << 60; struct S { lint sum = 0; lint lmax = 0; lint rmax = 0; lint inmax = 0; lint single_max = -inf; static S init(lint val, lint len) { return S{val * len, max(val, 0LL) * len, max(val, 0LL) * len, max(val, 0LL) * len, val}; } lint get() const { return single_max >= 0 ? inmax : single_max; } }; S op(S l, S r) { return { l.sum + r.sum, max(l.lmax, l.sum + r.lmax), max(r.rmax, r.sum + l.rmax), max({l.inmax, r.inmax, l.rmax + r.lmax}), max(l.single_max, r.single_max), }; } S e() { return S(); } int main() { cin.tie(nullptr), ios::sync_with_stdio(false); int N; cin >> N; vector<int> A(N), B(N); vector<lint> xs; lint r = 0; xs.push_back(r); REP(i, N) { cin >> A.at(i) >> B.at(i); r += B.at(i); xs.push_back(r); } const auto heads = xs; int Q; cin >> Q; vector<tuple<int, lint, lint>> qs; REP(q, Q) { int tp; cin >> tp; if (tp == 1) { lint x, y; cin >> x >> y; --x; xs.push_back(x); xs.push_back(x + 1); qs.emplace_back(tp, x, y); } else { lint l, r; cin >> l >> r; --l; xs.push_back(l), xs.push_back(r); qs.emplace_back(tp, l, r); } } xs = sort_unique(xs); vector<S> init; FOR(i, 1, xs.size()) { const lint xl = xs.at(i - 1), xr = xs.at(i); const int d = argub(heads, xl) - 1; init.push_back(S::init(A.at(d), xr - xl)); } atcoder::segtree<S, op, e> tree(init); for (auto [tp, l, r] : qs) { if (tp == 1) { tree.set(arglb(xs, l), S::init(r, 1)); } else { cout << tree.prod(arglb(xs, l), arglb(xs, r)).get() << '\n'; } } }