結果

問題 No.2170 Left Addition Machine
ユーザー norikamenorikame
提出日時 2022-12-24 02:28:21
言語 C++23(draft)
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 516 ms / 2,000 ms
コード長 1,084 bytes
コンパイル時間 5,148 ms
コンパイル使用メモリ 306,392 KB
実行使用メモリ 8,156 KB
最終ジャッジ日時 2023-08-11 13:48:10
合計ジャッジ時間 40,496 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 448 ms
7,760 KB
testcase_04 AC 202 ms
4,380 KB
testcase_05 AC 293 ms
5,096 KB
testcase_06 AC 273 ms
5,960 KB
testcase_07 AC 420 ms
6,372 KB
testcase_08 AC 52 ms
5,088 KB
testcase_09 AC 363 ms
4,380 KB
testcase_10 AC 54 ms
4,376 KB
testcase_11 AC 208 ms
5,632 KB
testcase_12 AC 493 ms
7,756 KB
testcase_13 AC 491 ms
7,584 KB
testcase_14 AC 488 ms
7,632 KB
testcase_15 AC 491 ms
7,916 KB
testcase_16 AC 486 ms
7,588 KB
testcase_17 AC 492 ms
7,764 KB
testcase_18 AC 483 ms
7,652 KB
testcase_19 AC 500 ms
7,704 KB
testcase_20 AC 501 ms
7,764 KB
testcase_21 AC 355 ms
4,380 KB
testcase_22 AC 347 ms
4,376 KB
testcase_23 AC 349 ms
4,380 KB
testcase_24 AC 346 ms
4,384 KB
testcase_25 AC 345 ms
4,376 KB
testcase_26 AC 351 ms
4,380 KB
testcase_27 AC 341 ms
4,376 KB
testcase_28 AC 350 ms
4,380 KB
testcase_29 AC 348 ms
4,376 KB
testcase_30 AC 469 ms
7,000 KB
testcase_31 AC 463 ms
7,096 KB
testcase_32 AC 470 ms
7,164 KB
testcase_33 AC 456 ms
7,160 KB
testcase_34 AC 470 ms
7,068 KB
testcase_35 AC 471 ms
7,096 KB
testcase_36 AC 477 ms
6,996 KB
testcase_37 AC 479 ms
7,004 KB
testcase_38 AC 470 ms
7,044 KB
testcase_39 AC 340 ms
4,380 KB
testcase_40 AC 347 ms
4,380 KB
testcase_41 AC 334 ms
4,380 KB
testcase_42 AC 336 ms
4,384 KB
testcase_43 AC 334 ms
4,376 KB
testcase_44 AC 335 ms
4,380 KB
testcase_45 AC 335 ms
4,376 KB
testcase_46 AC 329 ms
4,380 KB
testcase_47 AC 343 ms
4,384 KB
testcase_48 AC 465 ms
7,164 KB
testcase_49 AC 455 ms
7,092 KB
testcase_50 AC 467 ms
6,996 KB
testcase_51 AC 469 ms
7,092 KB
testcase_52 AC 452 ms
7,164 KB
testcase_53 AC 465 ms
6,992 KB
testcase_54 AC 461 ms
7,044 KB
testcase_55 AC 461 ms
7,108 KB
testcase_56 AC 467 ms
7,004 KB
testcase_57 AC 486 ms
7,992 KB
testcase_58 AC 506 ms
8,036 KB
testcase_59 AC 516 ms
8,020 KB
testcase_60 AC 484 ms
8,104 KB
testcase_61 AC 470 ms
8,156 KB
testcase_62 AC 477 ms
7,976 KB
testcase_63 AC 471 ms
8,076 KB
testcase_64 AC 500 ms
8,024 KB
testcase_65 AC 498 ms
7,976 KB
testcase_66 AC 125 ms
4,380 KB
testcase_67 AC 431 ms
8,096 KB
testcase_68 AC 491 ms
7,972 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;

int main() {
	int n, q;
	cin >> n >> q;
	vector<int> a(n);
	rep(i, n) cin >> a[i];
	vector<ll> two(n+1, 1);
	rep(i, n) two[i+1] = two[i] * 2 % mod;
	vector<ll> sums(n+1);
	vector<int> sids;
	sids.push_back(n);
	ll nval = 0;
	repr(i, n) {
		sums[i+1] = nval;
		if (i-1<0 || a[i-1]>=a[i]) {
			sids.push_back(i);
			nval = 0;
		}
		else nval = (nval * 2 + a[i]) % mod;
	}
	reverse(all(sids));
	rep(i, q) {
		int li, ri;
		cin >> li >> ri;
		--li;
		int ti = lower_bound(all(sids), ri) - sids.begin(), pi = ti - 1, spi = max(li+1, sids[pi]+1);
		ll res = (sums[spi] - sums[ri] * two[ri-spi] % mod + mod + a[spi-1]) % mod;
		cout << res << endl;
	}
	return 0;
}
0