結果
| 問題 |
No.2170 Left Addition Machine
|
| コンテスト | |
| ユーザー |
trineutron
|
| 提出日時 | 2022-12-22 18:57:03 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 112 ms / 2,000 ms |
| コード長 | 1,072 bytes |
| コンパイル時間 | 4,051 ms |
| コンパイル使用メモリ | 252,456 KB |
| 実行使用メモリ | 7,296 KB |
| 最終ジャッジ日時 | 2024-11-18 06:21:31 |
| 合計ジャッジ時間 | 17,051 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 69 |
ソースコード
#include <bits/stdc++.h>
#include <atcoder/modint>
using namespace std;
using namespace atcoder;
using mint = modint998244353;
int main() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
int n, q;
cin >> n >> q;
vector<int64_t> a(n);
for (auto &&x : a) {
cin >> x;
}
vector<int> last(n);
for (int i = 1; i < n; i++) {
if (a.at(i) > a.at(i - 1)) {
last.at(i) = last.at(i - 1);
} else {
last.at(i) = i;
}
}
const mint half = mint(1) / 2;
vector<mint> s(n + 1), pow_half(n + 1);
mint mul = 1;
pow_half.at(0) = 1;
for (int i = 0; i < n; i++) {
s.at(i + 1) = s.at(i) + mul * a.at(i);
mul += mul;
pow_half.at(i + 1) = pow_half.at(i) * half;
}
for (int i = 0; i < q; i++) {
int l, r;
cin >> l >> r;
l--;
r--;
l = max(l, last.at(r));
cout << ((s.at(r + 1) - s.at(l + 1)) * pow_half.at(l + 1) + a.at(l))
.val()
<< '\n';
}
return 0;
}
trineutron