結果
| 問題 | No.2170 Left Addition Machine |
| コンテスト | |
| ユーザー |
hotman78
|
| 提出日時 | 2022-12-22 10:06:03 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 674 ms / 2,000 ms |
| コード長 | 945 bytes |
| 記録 | |
| コンパイル時間 | 2,737 ms |
| コンパイル使用メモリ | 207,100 KB |
| 最終ジャッジ日時 | 2025-02-09 18:21:41 |
|
ジャッジサーバーID (参考情報) |
judge1 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 69 |
ソースコード
#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;
}
}
hotman78