結果

問題 No.2333 Slime Structure
ユーザー firiexpfiriexp
提出日時 2023-05-16 18:12:38
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 4,270 bytes
コンパイル時間 1,317 ms
コンパイル使用メモリ 113,572 KB
実行使用メモリ 25,324 KB
最終ジャッジ日時 2023-08-21 07:39:34
合計ジャッジ時間 8,891 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>
#include <limits>
#include <array>

static const int MOD = 1000000007;
using ll = long long;
using uint = unsigned;
using ull = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max() / 32 * 15 + 208;

template <class M>
struct SegmentTree{
    using T = typename M::T;
    int sz, n, height{};
    vector<T> seg;
    explicit SegmentTree(int n) : n(n) {
        sz = 1; while(sz < n) sz <<= 1, height++;
        seg.assign(2*sz, M::e());
    }

    void set(int k, const T &x){ seg[k + sz] = x; }

    void build(){
        for (int i = sz-1; i > 0; --i) seg[i] = M::f(seg[2*i], seg[2*i+1]);
    }

    void update(int k, const T &x){
        k += sz;
        seg[k] = x;
        while (k >>= 1) seg[k] = M::f(seg[2*k], seg[2*k+1]);
    }

    T query(int a, int b){
        T l = M::e(), r = M::e();
        for(a += sz, b += sz; a < b; a >>=1, b>>=1){
            if(a & 1) l = M::f(l, seg[a++]);
            if(b & 1) r = M::f(seg[--b], r);
        }
        return M::f(l, r);
    }

    template<class F>
    int search_right(int l, F cond){
        if(l == n) return n;
        T val = M::e();
        l += sz;
        do {
            while(!(l&1)) l >>= 1;
            if(!cond(M::f(val, seg[l]))){
                while(l < sz) {
                    l <<= 1;
                    if (cond(M::f(val, seg[l]))){
                        val = M::f(val, seg[l]);
                        l++;
                    }
                }
                return l - sz;
            }
            val = M::f(val, seg[l]);
            l++;
        } while((l & -l) != l);
        return n;
    }

    template<class F>
    int search_left(int r, F cond){
        if(r == 0) return 0;
        T val = M::e();
        r += sz;
        do {
            r--;
            while(r&1) r >>= 1;
            if(!cond(M::f(seg[r], val))){
                while(r < sz) {
                    r = ((r << 1)|1);
                    if (cond(M::f(seg[r], val))){
                        val = M::f(seg[r], val);
                        r--;
                    }
                }
                return r + 1 - sz;
            }
            val = M::f(seg[r], val);
        } while((r & -r) != r);
        return 0;
    }
    T operator[](const int &k) const { return seg[k + sz]; }
};

struct Monoid{
    using T = array<ll, 4>;
    static T f(T a, T b) { // L, R, sum, ans
        return {
            max(a[0], b[0]+a[2]),
            max(b[1], a[1]+b[2]),
            a[2]+b[2],
            max({a[3], b[3], a[1]+max(0LL, b[0]), b[0]+max(0LL, a[1])})
        };
    }
    static T e() { return {-INF<ll>, -INF<ll>, -INF<ll>, -INF<ll>}; }
};

int main() {
    int n;
    cin >> n;
    vector<ll> A(n), B(n);
    ll S = 0;
    vector<ll> z;
    z.emplace_back(0);
    for (int i = 0; i < n; ++i) {
        scanf("%lld %lld", &A[i], &B[i]);
        S += B[i];
        z.emplace_back(S);
    }
    ll q;
    cin >> q;
    vector<ll> t(q), x(q), y(q);
    for (int i = 0; i < q; ++i) {
        scanf("%lld %lld %lld", &t[i], &x[i], &y[i]);
        if(t[i] == 1){
            x[i]--;
            z.emplace_back(x[i]);
            z.emplace_back(x[i]+1);
        }else {
            x[i]--; y[i]--;
        }
    }
    sort(z.begin(), z.end());
    z.erase(unique(z.begin(), z.end()), z.end());
    auto f = [&](ll a){ return lower_bound(z.begin(),z.end(), a) - z.begin(); };
    SegmentTree<Monoid> seg(z.size());
    S = 0;
    for (int i = 0; i < n; ++i) {
        int l = f(S), r = f(S+B[i]);
        for (int j = l; j < r; ++j) {
            ll len = z[j+1]-z[j];
            seg.set(j, {
                max(A[i], A[i]*len),
                max(A[i], A[i]*len),
                A[i]*len,
                max(A[i], A[i]*len)
                });
        }
        S += B[i];
    }
    seg.build();
    for (int i = 0; i < q; ++i) {
        if(t[i] == 1){
            int xx = f(x[i]);
            seg.update(xx, {y[i], y[i], y[i], y[i]});
        }else {
            int l = f(x[i]), r = f(y[i]);
            printf("%lld\n", seg.query(l, r)[3]);
        }
    }
    return 0;
}
0