結果

問題 No.1441 MErGe
ユーザー momoharamomohara
提出日時 2021-03-26 23:19:56
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,905 bytes
コンパイル時間 3,034 ms
コンパイル使用メモリ 214,448 KB
実行使用メモリ 11,952 KB
最終ジャッジ日時 2023-08-19 10:09:12
合計ジャッジ時間 18,590 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
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 -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <atcoder/lazysegtree.hpp>
#include <bits/stdc++.h>

using namespace std;
using namespace atcoder;

using ll = long long;
using ull = unsigned long long;
using ld = long double;
using P = pair<ll, ll>;
using tp = tuple<ll, ll, ll>;

template <class T>
using vec = vector<T>;
template <class T>
using vvec = vector<vec<T>>;

#define all(hoge) (hoge).begin(), (hoge).end()
#define en '\n'
#define rep(i, m, n) for(ll i = (ll)(m); i < (ll)(n); ++i)
#define rep2(i, m, n) for(ll i = (ll)(n)-1; i >= (ll)(m); --i)
#define REP(i, n) rep(i, 0, n)
#define REP2(i, n) rep2(i, 0, n)

constexpr long long INF = 1LL << 60;
constexpr int INF_INT = 1 << 25;
constexpr long long MOD = (ll)1e9 + 7;
//constexpr long long MOD = 998244353LL;
static const ld pi = 3.141592653589793L;

#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

template <class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}

template <class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

//グラフ関連
struct Edge {
    int to, rev;
    ll cap;
    Edge(int _to, ll _cap, int _rev) : to(_to), cap(_cap), rev(_rev) {}
};

typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

void add_edge(Graph &G, int from, int to, ll cap, bool revFlag, ll revCap) {
    G[from].push_back(Edge(to, cap, (int)G[to].size()));
    if(revFlag)
        G[to].push_back(Edge(from, revCap, (int)G[from].size() - 1));
}

struct S {
    int num;
    int sum;
};

struct F {
    int num;
    int sum;
};

S op(S l, S r) { return S{l.num + r.num, l.sum + r.sum}; }

S e() { return S{0, 0}; }

S mapping(F l, S r) {
    if(l.num == INF_INT and l.sum == 0)
        return r;
    return S{l.num, l.sum};
}

F composition(F l, F r) {
    if(l.num == INF_INT and l.sum == 0)
        return r;
    return l;
}

F id() { return F{INF_INT, 0}; }

ll k = 0;
bool g(S a) {
    return a.num <= k;
}

void solve() {
    int n, q;
    cin >> n >> q;
    vec<int> a(n);
    REP(i, n) {
        cin >> a[i];
    }

    lazy_segtree<S, op, e, F, mapping, composition, id> seg(vec<S>(n + 2, S{1, 0}));
    REP(i, n) {
        seg.apply(i, F{1, a[i]});
    }
    seg.apply(n, F{1, 0});

    REP(i, q) {
        int t, l, r;
        cin >> t >> l >> r;
        l--;
        k = l;
        int l2 = seg.max_right<g>(0);
        k = r;
        int r2 = seg.max_right<g>(0);
        if(t == 2) {
            cout << seg.prod(l2, r2).sum << endl;
        } else {
            int sum = seg.prod(l2, r2).sum;
            seg.apply(l2, l2 + 1, F{1, sum});
            seg.apply(l2 + 1, r2, F{0, 0});
        }
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    // ll t;
    // cin >> t;
    // REP(i, t - 1) {
    //     solve();
    // }

    solve();

    return 0;
}
0