結果

問題 No.2170 Left Addition Machine
ユーザー hotman78hotman78
提出日時 2022-12-22 10:06:03
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 566 ms / 2,000 ms
コード長 945 bytes
コンパイル時間 3,829 ms
コンパイル使用メモリ 210,908 KB
実行使用メモリ 15,252 KB
最終ジャッジ日時 2023-08-11 13:04:48
合計ジャッジ時間 42,672 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,384 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 505 ms
14,972 KB
testcase_04 AC 229 ms
4,380 KB
testcase_05 AC 329 ms
8,768 KB
testcase_06 AC 316 ms
9,560 KB
testcase_07 AC 477 ms
13,616 KB
testcase_08 AC 57 ms
8,824 KB
testcase_09 AC 408 ms
6,012 KB
testcase_10 AC 63 ms
4,384 KB
testcase_11 AC 230 ms
9,020 KB
testcase_12 AC 550 ms
15,124 KB
testcase_13 AC 542 ms
15,232 KB
testcase_14 AC 552 ms
15,244 KB
testcase_15 AC 552 ms
15,164 KB
testcase_16 AC 550 ms
15,116 KB
testcase_17 AC 558 ms
15,176 KB
testcase_18 AC 542 ms
15,156 KB
testcase_19 AC 553 ms
15,160 KB
testcase_20 AC 542 ms
15,216 KB
testcase_21 AC 393 ms
4,380 KB
testcase_22 AC 382 ms
4,384 KB
testcase_23 AC 392 ms
4,380 KB
testcase_24 AC 388 ms
4,380 KB
testcase_25 AC 391 ms
4,380 KB
testcase_26 AC 395 ms
4,380 KB
testcase_27 AC 385 ms
4,384 KB
testcase_28 AC 385 ms
4,380 KB
testcase_29 AC 388 ms
4,384 KB
testcase_30 AC 554 ms
15,044 KB
testcase_31 AC 559 ms
15,252 KB
testcase_32 AC 557 ms
15,104 KB
testcase_33 AC 556 ms
15,160 KB
testcase_34 AC 551 ms
15,244 KB
testcase_35 AC 551 ms
15,076 KB
testcase_36 AC 552 ms
15,152 KB
testcase_37 AC 566 ms
15,108 KB
testcase_38 AC 539 ms
15,220 KB
testcase_39 AC 386 ms
4,384 KB
testcase_40 AC 384 ms
4,380 KB
testcase_41 AC 381 ms
4,380 KB
testcase_42 AC 382 ms
4,384 KB
testcase_43 AC 382 ms
4,380 KB
testcase_44 AC 398 ms
4,384 KB
testcase_45 AC 397 ms
4,384 KB
testcase_46 AC 381 ms
4,384 KB
testcase_47 AC 380 ms
4,384 KB
testcase_48 AC 558 ms
15,172 KB
testcase_49 AC 558 ms
15,104 KB
testcase_50 AC 554 ms
15,240 KB
testcase_51 AC 545 ms
15,040 KB
testcase_52 AC 554 ms
15,176 KB
testcase_53 AC 561 ms
15,072 KB
testcase_54 AC 563 ms
15,152 KB
testcase_55 AC 553 ms
15,100 KB
testcase_56 AC 543 ms
15,168 KB
testcase_57 AC 552 ms
15,048 KB
testcase_58 AC 541 ms
15,176 KB
testcase_59 AC 538 ms
15,232 KB
testcase_60 AC 533 ms
15,076 KB
testcase_61 AC 542 ms
15,220 KB
testcase_62 AC 543 ms
15,164 KB
testcase_63 AC 526 ms
15,192 KB
testcase_64 AC 526 ms
15,140 KB
testcase_65 AC 559 ms
15,172 KB
testcase_66 AC 133 ms
4,388 KB
testcase_67 AC 497 ms
15,216 KB
testcase_68 AC 538 ms
15,160 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#include<atcoder/segtree.hpp>
#include<atcoder/modint.hpp>
using mint=atcoder::static_modint<998244353>;

using T=tuple<int,int,mint,mint>;
T f(T s,T t){
    if(get<1>(s)==-1)return t;
    if(get<1>(t)==-1)return s;
    if(get<1>(s)<get<0>(t)){
        return make_tuple(get<0>(s),get<1>(t),get<2>(s)*get<2>(t),get<3>(s)+get<3>(t)*get<2>(s));
    }else{
        return make_tuple(get<0>(t)>0?~get<0>(t):get<0>(t),get<1>(t),get<2>(t),get<3>(t));
    }
}
T id(){
    return make_tuple(-1,-1,mint(1),mint(0));
}

int main(){
    int n,q;
    cin>>n>>q;
    vector<int>a(n);
    vector<T>v(n);
    for(int i=0;i<n;++i){
        cin>>a[i];
        v[i]=make_tuple(a[i],a[i],mint(2),mint(a[i]));
    }
    atcoder::segtree<T,f,id>seg(v);
    while(q--){
        int l,r;
        cin>>l>>r;
        l--;
        auto [x,y,z,w]=seg.prod(l,r);
        if(x<0)x=~x;
        cout<<((w+x)/2).val()<<endl;
    }
}
0