結果
問題 |
No.2170 Left Addition Machine
|
ユーザー |
![]() |
提出日時 | 2022-12-22 18:54:52 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 510 ms / 2,000 ms |
コード長 | 1,016 bytes |
コンパイル時間 | 3,479 ms |
コンパイル使用メモリ | 252,324 KB |
実行使用メモリ | 7,296 KB |
最終ジャッジ日時 | 2024-11-18 06:22:54 |
合計ジャッジ時間 | 38,877 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() { 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; }