結果
問題 | No.2170 Left Addition Machine |
ユーザー |
![]() |
提出日時 | 2022-12-24 02:28:21 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 533 ms / 2,000 ms |
コード長 | 1,084 bytes |
コンパイル時間 | 5,339 ms |
コンパイル使用メモリ | 310,692 KB |
実行使用メモリ | 8,468 KB |
最終ジャッジ日時 | 2024-11-18 07:16:37 |
合計ジャッジ時間 | 42,220 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 69 |
ソースコード
//#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;}