結果

問題 No.2170 Left Addition Machine
ユーザー suisensuisen
提出日時 2022-12-22 17:49:44
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 550 ms / 2,000 ms
コード長 1,014 bytes
コンパイル時間 2,644 ms
コンパイル使用メモリ 79,000 KB
実行使用メモリ 7,288 KB
最終ジャッジ日時 2023-08-11 13:06:31
合計ジャッジ時間 38,882 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 475 ms
6,684 KB
testcase_04 AC 199 ms
4,380 KB
testcase_05 AC 297 ms
4,628 KB
testcase_06 AC 283 ms
5,360 KB
testcase_07 AC 436 ms
5,648 KB
testcase_08 AC 53 ms
4,588 KB
testcase_09 AC 370 ms
4,376 KB
testcase_10 AC 56 ms
4,380 KB
testcase_11 AC 216 ms
5,252 KB
testcase_12 AC 550 ms
6,992 KB
testcase_13 AC 516 ms
7,028 KB
testcase_14 AC 526 ms
6,992 KB
testcase_15 AC 545 ms
7,024 KB
testcase_16 AC 522 ms
7,044 KB
testcase_17 AC 532 ms
7,228 KB
testcase_18 AC 518 ms
7,288 KB
testcase_19 AC 520 ms
7,096 KB
testcase_20 AC 530 ms
7,108 KB
testcase_21 AC 341 ms
4,380 KB
testcase_22 AC 344 ms
4,380 KB
testcase_23 AC 348 ms
4,376 KB
testcase_24 AC 352 ms
4,376 KB
testcase_25 AC 342 ms
4,380 KB
testcase_26 AC 348 ms
4,376 KB
testcase_27 AC 344 ms
4,380 KB
testcase_28 AC 349 ms
4,380 KB
testcase_29 AC 346 ms
4,380 KB
testcase_30 AC 537 ms
6,976 KB
testcase_31 AC 525 ms
6,944 KB
testcase_32 AC 529 ms
7,008 KB
testcase_33 AC 527 ms
7,072 KB
testcase_34 AC 530 ms
7,024 KB
testcase_35 AC 528 ms
7,096 KB
testcase_36 AC 535 ms
7,036 KB
testcase_37 AC 530 ms
6,948 KB
testcase_38 AC 525 ms
6,988 KB
testcase_39 AC 345 ms
4,384 KB
testcase_40 AC 343 ms
4,388 KB
testcase_41 AC 339 ms
4,376 KB
testcase_42 AC 339 ms
4,380 KB
testcase_43 AC 345 ms
4,376 KB
testcase_44 AC 346 ms
4,380 KB
testcase_45 AC 339 ms
4,380 KB
testcase_46 AC 347 ms
4,376 KB
testcase_47 AC 347 ms
4,384 KB
testcase_48 AC 526 ms
7,028 KB
testcase_49 AC 504 ms
6,992 KB
testcase_50 AC 494 ms
7,024 KB
testcase_51 AC 524 ms
6,924 KB
testcase_52 AC 513 ms
6,924 KB
testcase_53 AC 494 ms
6,940 KB
testcase_54 AC 524 ms
7,004 KB
testcase_55 AC 528 ms
6,924 KB
testcase_56 AC 528 ms
7,032 KB
testcase_57 AC 518 ms
7,020 KB
testcase_58 AC 504 ms
6,944 KB
testcase_59 AC 508 ms
6,972 KB
testcase_60 AC 514 ms
6,964 KB
testcase_61 AC 531 ms
7,100 KB
testcase_62 AC 521 ms
7,256 KB
testcase_63 AC 511 ms
7,076 KB
testcase_64 AC 517 ms
7,084 KB
testcase_65 AC 531 ms
7,104 KB
testcase_66 AC 125 ms
4,380 KB
testcase_67 AC 463 ms
6,992 KB
testcase_68 AC 514 ms
6,992 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>

#include <atcoder/modint>

using mint = atcoder::modint998244353;

int main() {
    int n, q;
    std::cin >> n >> q;

    std::vector<long long> a(n);
    for (auto &&e : a) std::cin >> e;

    std::vector<int> inc_sum(n);
    for (int i = 0; i < n - 1; ++i) {
        inc_sum[i + 1] = inc_sum[i] + (a[i] < a[i + 1]);
    }
    std::vector<mint> a_sum(n + 1);
    for (int i = n - 1; i >= 0; --i) {
        a_sum[i] = 2 * a_sum[i + 1] + a[i];
    }
    std::vector<mint> pow_2(n + 1);
    pow_2[0] = 1;
    for (int i = 1; i <= n; ++i) {
        pow_2[i] = pow_2[i - 1] + pow_2[i - 1];
    }

    for (int qid = 0; qid < q; ++qid) {
        int l, r;
        std::cin >> l >> r;
        --l, --r;

        int ng = l - 1, ok = r;
        while (ok - ng > 1) {
            int mid = (ok + ng) >> 1;
            (inc_sum[r] - inc_sum[mid] == r - mid ? ok : ng) = mid;
        }
        std::cout << (a_sum[ok + 1] - a_sum[r + 1] * pow_2[r - ok] + a[ok]).val() << '\n';
    }
}
0