結果
問題 |
No.2170 Left Addition Machine
|
ユーザー |
![]() |
提出日時 | 2022-12-22 21:12:30 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,055 bytes |
コンパイル時間 | 1,024 ms |
コンパイル使用メモリ | 89,296 KB |
実行使用メモリ | 8,064 KB |
最終ジャッジ日時 | 2024-11-18 06:24:57 |
合計ジャッジ時間 | 10,719 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 6 WA * 63 |
ソースコード
#include <iostream> #include <vector> constexpr int mod = 998244353; int main() { std::cin.tie(nullptr); std::ios::sync_with_stdio(false); int n, q; std::cin >> n >> q; std::vector<int> a(n); for (auto &&x : a) { std::cin >> x; } std::vector<int> last(n); for (int i = 1; i < n; i++) { if (a[i] > a[i - 1]) { last[i] = last[i - 1]; } else { last[i] = i; } } const int64_t half = (mod + 1) / 2; std::vector<int64_t> s(n + 1), pow_half(n + 1); int64_t mul = 1; pow_half[0] = 1; for (int i = 0; i < n; i++) { s[i + 1] = (s[i] + mul * a[i]) % mod; mul += mul; if (mul >= mod) mul -= mod; pow_half[i + 1] = pow_half[i] * half % mod; } for (int i = 0; i < q; i++) { int l, r; std::cin >> l >> r; l--; r--; l = std::max(l, last[r]); std::cout << ((s[r + 1] - s[l + 1]) * pow_half[l + 1] + a[l]) % mod << '\n'; } return 0; }