結果

問題 No.2170 Left Addition Machine
ユーザー 👑 kmjpkmjp
提出日時 2022-12-22 00:13:22
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 392 ms / 2,000 ms
コード長 1,367 bytes
コンパイル時間 3,727 ms
コンパイル使用メモリ 197,868 KB
実行使用メモリ 12,248 KB
最終ジャッジ日時 2023-08-11 12:57:04
合計ジャッジ時間 33,338 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
9,528 KB
testcase_01 AC 5 ms
9,428 KB
testcase_02 AC 5 ms
9,692 KB
testcase_03 AC 329 ms
11,920 KB
testcase_04 AC 162 ms
9,588 KB
testcase_05 AC 210 ms
10,136 KB
testcase_06 AC 202 ms
10,600 KB
testcase_07 AC 307 ms
10,724 KB
testcase_08 AC 30 ms
10,160 KB
testcase_09 AC 273 ms
9,828 KB
testcase_10 AC 46 ms
9,560 KB
testcase_11 AC 148 ms
10,296 KB
testcase_12 AC 351 ms
12,024 KB
testcase_13 AC 350 ms
11,976 KB
testcase_14 AC 350 ms
12,044 KB
testcase_15 AC 349 ms
12,040 KB
testcase_16 AC 356 ms
11,976 KB
testcase_17 AC 370 ms
12,020 KB
testcase_18 AC 355 ms
12,248 KB
testcase_19 AC 381 ms
11,980 KB
testcase_20 AC 392 ms
11,992 KB
testcase_21 AC 293 ms
9,532 KB
testcase_22 AC 282 ms
9,444 KB
testcase_23 AC 285 ms
9,496 KB
testcase_24 AC 281 ms
9,496 KB
testcase_25 AC 287 ms
9,472 KB
testcase_26 AC 287 ms
9,680 KB
testcase_27 AC 285 ms
9,512 KB
testcase_28 AC 291 ms
9,532 KB
testcase_29 AC 292 ms
9,700 KB
testcase_30 AC 367 ms
12,032 KB
testcase_31 AC 373 ms
12,036 KB
testcase_32 AC 360 ms
12,232 KB
testcase_33 AC 362 ms
12,032 KB
testcase_34 AC 360 ms
12,048 KB
testcase_35 AC 349 ms
12,052 KB
testcase_36 AC 355 ms
11,956 KB
testcase_37 AC 361 ms
12,008 KB
testcase_38 AC 351 ms
12,044 KB
testcase_39 AC 286 ms
9,472 KB
testcase_40 AC 291 ms
9,540 KB
testcase_41 AC 285 ms
9,544 KB
testcase_42 AC 288 ms
9,592 KB
testcase_43 AC 285 ms
9,440 KB
testcase_44 AC 292 ms
9,496 KB
testcase_45 AC 284 ms
9,472 KB
testcase_46 AC 288 ms
9,604 KB
testcase_47 AC 280 ms
9,512 KB
testcase_48 AC 349 ms
12,100 KB
testcase_49 AC 337 ms
12,092 KB
testcase_50 AC 344 ms
12,212 KB
testcase_51 AC 345 ms
12,004 KB
testcase_52 AC 351 ms
12,040 KB
testcase_53 AC 335 ms
12,096 KB
testcase_54 AC 345 ms
12,048 KB
testcase_55 AC 349 ms
12,100 KB
testcase_56 AC 358 ms
12,048 KB
testcase_57 AC 358 ms
11,996 KB
testcase_58 AC 359 ms
12,072 KB
testcase_59 AC 358 ms
12,160 KB
testcase_60 AC 360 ms
12,092 KB
testcase_61 AC 350 ms
11,972 KB
testcase_62 AC 350 ms
12,100 KB
testcase_63 AC 359 ms
12,052 KB
testcase_64 AC 358 ms
12,072 KB
testcase_65 AC 356 ms
12,008 KB
testcase_66 AC 111 ms
9,600 KB
testcase_67 AC 336 ms
11,992 KB
testcase_68 AC 343 ms
12,248 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define FORR2(x,y,arr) for(auto& [x,y]:arr)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
template<class T> bool chmax(T &a, const T &b) { if(a<b){a=b;return 1;}return 0;}
template<class T> bool chmin(T &a, const T &b) { if(a>b){a=b;return 1;}return 0;}
//-------------------------------------------------------

int N,Q;
ll A[202020];
const ll mo=998244353;

int NG[202020];
ll S[202020];
ll MS[202020];
ll p2[202020],r2[202020];

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	p2[0]=r2[0]=1;
	FOR(i,201010) {
		p2[i+1]=p2[i]*2%mo;
		r2[i+1]=r2[i]*(mo+1)/2%mo;
	}
	
	cin>>N>>Q;
	FOR(i,N) {
		cin>>A[i];
		if(i&&A[i]>A[i-1]) {
			NG[i]=NG[i-1];
		}
		else {
			NG[i]=i;
		}
		S[i+1]=(S[i]+A[i])%mo;
		MS[i+1]=(MS[i]+p2[i]*A[i])%mo;
	}
	while(Q--) {
		int L,R;
		cin>>L>>R;
		L--,R--;
		L=max(NG[R],L);
		ll ret=(MS[R+1]-MS[L+1]+mo)*r2[L+1]+A[L];
		cout<<ret%mo<<endl;
		
	}
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}
0