結果

問題 No.2170 Left Addition Machine
ユーザー norikamenorikame
提出日時 2022-12-25 11:23:17
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 565 ms / 2,000 ms
コード長 1,315 bytes
コンパイル時間 5,687 ms
コンパイル使用メモリ 308,428 KB
実行使用メモリ 11,264 KB
最終ジャッジ日時 2024-04-29 17:16:17
合計ジャッジ時間 46,080 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 3 ms
5,376 KB
testcase_02 AC 3 ms
5,376 KB
testcase_03 AC 463 ms
10,880 KB
testcase_04 AC 204 ms
5,376 KB
testcase_05 AC 290 ms
6,784 KB
testcase_06 AC 290 ms
8,192 KB
testcase_07 AC 438 ms
8,320 KB
testcase_08 AC 58 ms
6,400 KB
testcase_09 AC 371 ms
5,376 KB
testcase_10 AC 57 ms
5,376 KB
testcase_11 AC 218 ms
7,296 KB
testcase_12 AC 565 ms
11,008 KB
testcase_13 AC 536 ms
11,264 KB
testcase_14 AC 507 ms
11,136 KB
testcase_15 AC 526 ms
11,136 KB
testcase_16 AC 514 ms
11,136 KB
testcase_17 AC 521 ms
11,008 KB
testcase_18 AC 518 ms
11,136 KB
testcase_19 AC 525 ms
11,008 KB
testcase_20 AC 521 ms
11,008 KB
testcase_21 AC 352 ms
5,376 KB
testcase_22 AC 363 ms
5,376 KB
testcase_23 AC 359 ms
5,376 KB
testcase_24 AC 354 ms
5,376 KB
testcase_25 AC 351 ms
5,376 KB
testcase_26 AC 350 ms
5,376 KB
testcase_27 AC 356 ms
5,376 KB
testcase_28 AC 355 ms
5,376 KB
testcase_29 AC 360 ms
5,376 KB
testcase_30 AC 500 ms
11,008 KB
testcase_31 AC 503 ms
11,136 KB
testcase_32 AC 514 ms
11,008 KB
testcase_33 AC 508 ms
11,008 KB
testcase_34 AC 513 ms
11,008 KB
testcase_35 AC 505 ms
11,008 KB
testcase_36 AC 518 ms
11,008 KB
testcase_37 AC 503 ms
11,008 KB
testcase_38 AC 507 ms
11,008 KB
testcase_39 AC 359 ms
5,376 KB
testcase_40 AC 351 ms
5,376 KB
testcase_41 AC 347 ms
5,376 KB
testcase_42 AC 355 ms
5,376 KB
testcase_43 AC 360 ms
5,376 KB
testcase_44 AC 359 ms
5,376 KB
testcase_45 AC 352 ms
5,376 KB
testcase_46 AC 352 ms
5,376 KB
testcase_47 AC 358 ms
5,376 KB
testcase_48 AC 520 ms
11,008 KB
testcase_49 AC 506 ms
11,008 KB
testcase_50 AC 507 ms
11,136 KB
testcase_51 AC 515 ms
11,136 KB
testcase_52 AC 504 ms
11,136 KB
testcase_53 AC 511 ms
11,136 KB
testcase_54 AC 528 ms
11,008 KB
testcase_55 AC 501 ms
11,008 KB
testcase_56 AC 504 ms
10,880 KB
testcase_57 AC 510 ms
11,008 KB
testcase_58 AC 525 ms
11,008 KB
testcase_59 AC 513 ms
11,008 KB
testcase_60 AC 514 ms
11,008 KB
testcase_61 AC 517 ms
11,008 KB
testcase_62 AC 518 ms
11,008 KB
testcase_63 AC 524 ms
11,008 KB
testcase_64 AC 515 ms
11,136 KB
testcase_65 AC 531 ms
11,008 KB
testcase_66 AC 129 ms
5,376 KB
testcase_67 AC 462 ms
11,008 KB
testcase_68 AC 521 ms
11,264 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

// 

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;

using ll = long long;

#define rep(i, n) for (int i=0; i<(int)(n); ++(i))
#define rep3(i, m, n) for (int i=(m); (i)<(int)(n); ++(i))
#define repr(i, n) for (int i=(int)(n)-1; (i)>=0; --(i))
#define rep3r(i, m, n) for (int i=(int)(n)-1; (i)>=(int)(m); --(i))
#define all(x) (x).begin(), (x).end()

const ll mod = 998244353LL;
ll modpow(ll a, ll b) {
	ll p = 1, q = a;
	rep(i, 63) {
		if (b & (1LL<<i)) p = p * q % mod;
		q = q * q % mod;
	}
	return p;
}

int main() {
	int n, q;
	cin >> n >> q;
	vector<int> a(n);
	rep(i, n) cin >> a[i];
	vector<ll> two(n+1), itwo(n+1), c(n), csum(n+1);
	two[0] = 1;
	rep(i, n) two[i+1] = two[i] * 2 % mod;
	itwo[n] = modpow(two[n], mod-2);
	repr(i, n) itwo[i] = itwo[i+1] * 2 % mod;
	rep(i, n) c[i] = two[i] * a[i] % mod;
	rep(i, n) csum[i+1] = (csum[i] + c[i]) % mod;
	vector<int> lids(n);
	int lid = 0;
	rep3(i, 1, n) {
		if (a[i] <= a[i-1]) lid = i;
		lids[i] = lid;
	}
	rep(i, q) {
		int li, ri;
		cin >> li >> ri;
		--li; --ri;
		ll res = 0;
		if (lids[ri] >= li) res = ((csum[ri+1] - csum[lids[ri]+1] + mod) % mod * itwo[lids[ri]+1] + a[lids[ri]]) % mod;
		else res = ((csum[ri+1] - csum[li+1] + mod) % mod * itwo[li+1] + a[li]) % mod;
		cout << res << endl;
	}
	return 0;
}
0