結果

問題 No.1234 典型RMQ
ユーザー firiexpfiriexp
提出日時 2020-09-18 22:13:50
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
CE  
(最新)
AC  
(最初)
実行時間 -
コード長 3,235 bytes
コンパイル時間 1,056 ms
コンパイル使用メモリ 94,772 KB
最終ジャッジ日時 2024-11-15 04:59:43
合計ジャッジ時間 2,441 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。

コンパイルメッセージ
main.cpp:97:18: error: 'a' has incomplete type
   97 |     static T f(T a, T b) { return {a[0]+b[0], min(a[1], b[1]+a[0])}; }
      |                ~~^
In file included from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/bits/stl_map.h:63,
                 from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/map:61,
                 from main.cpp:3:
/home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/tuple:1595:45: note: declaration of 'using T = struct std::array<long long int, 2>' {aka 'struct std::array<long long int, 2>'}
 1595 |   template<typename _Tp, size_t _Nm> struct array;
      |                                             ^~~~~
main.cpp:97:23: error: 'b' has incomplete type
   97 |     static T f(T a, T b) { return {a[0]+b[0], min(a[1], b[1]+a[0])}; }
      |                     ~~^
/home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/tuple:1595:45: note: declaration of 'using T = struct std::array<long long int, 2>' {aka 'struct std::array<long long int, 2>'}
 1595 |   template<typename _Tp, size_t _Nm> struct array;
      |                                             ^~~~~
main.cpp:97:26: error: return type 'using T = struct std::array<long long int, 2>' {aka 'struct std::array<long long int, 2>'} is incomplete
   97 |     static T f(T a, T b) { return {a[0]+b[0], min(a[1], b[1]+a[0])}; }
      |                          ^
main.cpp:98:18: error: return type 'using T = struct std::array<long long int, 2>' {aka 'struct std::array<long long int, 2>'} is incomplete
   98 |     static T e() { return {0, INF<ll>}; }
      |                  ^
main.cpp: In function 'int main()':
main.cpp:113:16: error: cannot convert '<brace-enclosed initializer list>' to 'const SegmentTree<Monoid>::T&' {aka 'const std::array<long long int, 2>&'}
  113 |         seg.set(i, {v[i], v[i]});
      |         ~~~~~~~^~~~~~~~~~~~~~~~~
main.cpp:29:30: note:   initializing argument 2 of 'void SegmentTree<M>::set(int, const T&) [wit

ソースコード

diff #

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

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = 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) {
        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();
        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();
        do {
            while(r&1) r >>= 1;
            if(!cond(M::f(val, seg[r]))){
                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, 2>; // val, min
    static T f(T a, T b) { return {a[0]+b[0], min(a[1], b[1]+a[0])}; }
    static T e() { return {0, INF<ll>}; }
};



int main() {
    int n;
    cin >> n;
    vector<ll> v(n);
    for (auto &&i : v) scanf("%lld", &i);
    for (int i = n-1; i > 0; --i) {
        v[i] -= v[i-1];
    }
    SegmentTree<Monoid> seg(n);
    for (int i = 0; i < n; ++i) {
        seg.set(i, {v[i], v[i]});
    }
    seg.build();
    int q;
    cin >> q;
    for (int i = 0; i < q; ++i) {
        int k, l, r, c;
        scanf("%d %d %d %d", &k, &l, &r, &c);
        l--;
        if(k == 1){
            v[l] += c; seg.update(l, {v[l], v[l]});
            if(r != n) v[r] -= c, seg.update(r, {v[r], v[r]});
        }else {
            printf("%lld\n", seg.query(0, l)[0]+seg.query(l, r)[1]);
        }
    }
    return 0;
}
0