結果

問題 No.1441 MErGe
ユーザー KoDKoD
提出日時 2021-03-26 21:35:42
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 340 ms / 1,000 ms
コード長 2,191 bytes
コンパイル時間 4,192 ms
コンパイル使用メモリ 269,368 KB
実行使用メモリ 18,860 KB
最終ジャッジ日時 2023-08-19 07:40:25
合計ジャッジ時間 13,276 ms
ジャッジサーバーID
(参考情報)
judge10 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 4 ms
4,380 KB
testcase_04 AC 4 ms
4,376 KB
testcase_05 AC 6 ms
4,380 KB
testcase_06 AC 6 ms
4,380 KB
testcase_07 AC 6 ms
4,376 KB
testcase_08 AC 66 ms
6,976 KB
testcase_09 AC 63 ms
6,480 KB
testcase_10 AC 93 ms
6,208 KB
testcase_11 AC 79 ms
5,744 KB
testcase_12 AC 99 ms
6,752 KB
testcase_13 AC 279 ms
17,820 KB
testcase_14 AC 292 ms
17,956 KB
testcase_15 AC 288 ms
17,252 KB
testcase_16 AC 286 ms
17,888 KB
testcase_17 AC 267 ms
17,232 KB
testcase_18 AC 194 ms
14,072 KB
testcase_19 AC 230 ms
16,304 KB
testcase_20 AC 178 ms
13,664 KB
testcase_21 AC 151 ms
11,960 KB
testcase_22 AC 189 ms
11,552 KB
testcase_23 AC 333 ms
18,612 KB
testcase_24 AC 340 ms
18,684 KB
testcase_25 AC 331 ms
18,860 KB
testcase_26 AC 334 ms
18,628 KB
testcase_27 AC 336 ms
18,628 KB
testcase_28 AC 205 ms
18,676 KB
testcase_29 AC 203 ms
18,620 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#line 1 "main.cpp"
#include <bits/extc++.h>
#line 4 "/Users/kodamankod/Desktop/CppProcon/Library/proconlib/utility/int_alias.cpp"

using i32 = std::int32_t;
using u32 = std::uint32_t;
using i64 = std::int64_t;
using u64 = std::uint64_t;
using i128 = __int128_t;
using u128 = __uint128_t;
using isize = std::ptrdiff_t;
using usize = std::size_t;
#line 4 "/Users/kodamankod/Desktop/CppProcon/Library/proconlib/utility/rep.cpp"

class rep {
    struct Iter {
        usize itr;
        constexpr Iter(const usize pos) noexcept: itr(pos) { }
        constexpr void operator ++ () noexcept { ++itr; }
        constexpr bool operator != (const Iter& other) const noexcept { return itr != other.itr; }
        constexpr usize operator * () const noexcept { return itr; }
    };
    const Iter first, last;
public:
    explicit constexpr rep(const usize first, const usize last) noexcept: first(first), last(std::max(first, last)) { }
    constexpr Iter begin() const noexcept { return first; }
    constexpr Iter end() const noexcept { return last; }
};
#line 4 "main.cpp"

namespace extlib {
    using namespace std;
    using namespace __gnu_pbds;
    template <class T>
    using Tree = tree<T, null_type, std::less<T>, rb_tree_tag, tree_order_statistics_node_update>;
}

template <class T>
using Vec = std::vector<T>;

void E_main() {
    usize N, Q;
    std::cin >> N >> Q;
    Vec<i64> A(N);
    for (auto &x: A) {
        std::cin >> x;
    }
    Vec<i64> sum(N + 1);
    for (auto i: rep(0, N)) {
        sum[i + 1] = sum[i] + A[i];
    }
    extlib::Tree<usize> idx;
    for (auto i: rep(0, N + 1)) {
        idx.insert(i);
    }
    while (Q--) {
        usize t, l, r;
        std::cin >> t >> l >> r;
        l -= 1;
        if (t == 1) {
            auto itr = std::next(idx.find_by_order(l));
            for (auto _: rep(l + 1, r)) {
                itr = idx.erase(itr);
            }
        }
        else {
            l = *idx.find_by_order(l);
            r = *idx.find_by_order(r);
            std::cout << sum[r] - sum[l] << '\n';
        }
    }
    return;
}

int main() {
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(nullptr);
    E_main();
    return 0;
}
0