結果

問題 No.2333 Slime Structure
ユーザー hitonanode
提出日時 2023-05-28 14:45:08
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 327 ms / 3,000 ms
コード長 3,100 bytes
コンパイル時間 2,948 ms
コンパイル使用メモリ 193,276 KB
実行使用メモリ 67,304 KB
最終ジャッジ日時 2024-12-27 02:49:57
合計ジャッジ時間 16,936 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 31
権限があれば一括ダウンロードができます

ソースコード

diff #

#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';
        }
    }
}
0