結果

問題 No.2333 Slime Structure
ユーザー firiexpfiriexp
提出日時 2023-05-16 18:26:06
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 204 ms / 3,000 ms
コード長 4,375 bytes
コンパイル時間 1,269 ms
コンパイル使用メモリ 113,924 KB
実行使用メモリ 44,156 KB
最終ジャッジ日時 2023-08-21 07:44:40
合計ジャッジ時間 9,829 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 88 ms
23,032 KB
testcase_03 AC 118 ms
24,340 KB
testcase_04 AC 129 ms
24,144 KB
testcase_05 AC 100 ms
23,488 KB
testcase_06 AC 144 ms
24,840 KB
testcase_07 AC 182 ms
42,564 KB
testcase_08 AC 183 ms
42,400 KB
testcase_09 AC 183 ms
42,344 KB
testcase_10 AC 181 ms
43,376 KB
testcase_11 AC 179 ms
42,280 KB
testcase_12 AC 179 ms
42,724 KB
testcase_13 AC 180 ms
42,356 KB
testcase_14 AC 179 ms
42,680 KB
testcase_15 AC 175 ms
42,400 KB
testcase_16 AC 175 ms
43,136 KB
testcase_17 AC 180 ms
42,344 KB
testcase_18 AC 182 ms
43,104 KB
testcase_19 AC 183 ms
42,416 KB
testcase_20 AC 183 ms
42,968 KB
testcase_21 AC 182 ms
42,484 KB
testcase_22 AC 198 ms
42,672 KB
testcase_23 AC 198 ms
42,488 KB
testcase_24 AC 198 ms
43,748 KB
testcase_25 AC 204 ms
42,400 KB
testcase_26 AC 196 ms
42,272 KB
testcase_27 AC 197 ms
42,640 KB
testcase_28 AC 198 ms
44,156 KB
testcase_29 AC 195 ms
42,616 KB
testcase_30 AC 195 ms
42,388 KB
testcase_31 AC 195 ms
42,464 KB
testcase_32 AC 164 ms
42,672 KB
権限があれば一括ダウンロードができます

ソースコード

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]--;
            z.emplace_back(x[i]);
            z.emplace_back(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]);
            auto [a, b, c, d] = seg.query(l, r);
            printf("%lld\n", max({a, b, d}));
        }
    }
    return 0;
}
0