結果

問題 No.2170 Left Addition Machine
ユーザー KudeKude
提出日時 2022-12-22 07:55:08
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 92 ms / 2,000 ms
コード長 1,453 bytes
コンパイル時間 4,189 ms
コンパイル使用メモリ 224,712 KB
実行使用メモリ 7,168 KB
最終ジャッジ日時 2023-08-11 13:00:51
合計ジャッジ時間 18,397 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
5,084 KB
testcase_01 AC 4 ms
4,928 KB
testcase_02 AC 3 ms
4,980 KB
testcase_03 AC 81 ms
6,640 KB
testcase_04 AC 28 ms
4,980 KB
testcase_05 AC 47 ms
5,628 KB
testcase_06 AC 50 ms
6,340 KB
testcase_07 AC 70 ms
6,236 KB
testcase_08 AC 16 ms
5,636 KB
testcase_09 AC 52 ms
5,112 KB
testcase_10 AC 11 ms
5,088 KB
testcase_11 AC 39 ms
5,960 KB
testcase_12 AC 88 ms
6,992 KB
testcase_13 AC 88 ms
6,944 KB
testcase_14 AC 87 ms
7,028 KB
testcase_15 AC 83 ms
7,004 KB
testcase_16 AC 85 ms
6,960 KB
testcase_17 AC 88 ms
6,932 KB
testcase_18 AC 88 ms
7,004 KB
testcase_19 AC 88 ms
6,964 KB
testcase_20 AC 90 ms
6,944 KB
testcase_21 AC 44 ms
4,972 KB
testcase_22 AC 44 ms
4,900 KB
testcase_23 AC 43 ms
4,932 KB
testcase_24 AC 45 ms
5,092 KB
testcase_25 AC 44 ms
4,932 KB
testcase_26 AC 43 ms
5,024 KB
testcase_27 AC 44 ms
4,932 KB
testcase_28 AC 44 ms
4,940 KB
testcase_29 AC 44 ms
5,172 KB
testcase_30 AC 84 ms
6,936 KB
testcase_31 AC 83 ms
6,952 KB
testcase_32 AC 84 ms
6,880 KB
testcase_33 AC 87 ms
7,016 KB
testcase_34 AC 81 ms
6,940 KB
testcase_35 AC 85 ms
6,960 KB
testcase_36 AC 86 ms
6,904 KB
testcase_37 AC 84 ms
6,904 KB
testcase_38 AC 86 ms
6,944 KB
testcase_39 AC 42 ms
4,940 KB
testcase_40 AC 43 ms
4,968 KB
testcase_41 AC 43 ms
4,892 KB
testcase_42 AC 44 ms
4,968 KB
testcase_43 AC 43 ms
5,000 KB
testcase_44 AC 43 ms
4,932 KB
testcase_45 AC 43 ms
4,932 KB
testcase_46 AC 43 ms
4,968 KB
testcase_47 AC 43 ms
4,964 KB
testcase_48 AC 82 ms
6,948 KB
testcase_49 AC 84 ms
6,956 KB
testcase_50 AC 85 ms
7,016 KB
testcase_51 AC 83 ms
6,960 KB
testcase_52 AC 90 ms
6,952 KB
testcase_53 AC 87 ms
6,904 KB
testcase_54 AC 86 ms
6,884 KB
testcase_55 AC 86 ms
7,012 KB
testcase_56 AC 85 ms
7,168 KB
testcase_57 AC 89 ms
7,016 KB
testcase_58 AC 89 ms
6,944 KB
testcase_59 AC 89 ms
6,996 KB
testcase_60 AC 92 ms
6,880 KB
testcase_61 AC 91 ms
6,876 KB
testcase_62 AC 88 ms
7,024 KB
testcase_63 AC 87 ms
6,952 KB
testcase_64 AC 88 ms
6,940 KB
testcase_65 AC 88 ms
6,932 KB
testcase_66 AC 17 ms
4,936 KB
testcase_67 AC 74 ms
7,020 KB
testcase_68 AC 86 ms
6,896 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
namespace {
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-function"
#include<atcoder/all>
#pragma GCC diagnostic pop
using namespace std;
using namespace atcoder;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(i,n) for(int i = (int)(n) - 1; i >= 0; i--)
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
template<class T> bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; }
template<class T> bool chmin(T& a, const T& b) { if (b < a) { a = b; return true; } else return false; }
using ll = long long;
using P = pair<int,int>;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<ll>;
using VVL = vector<VL>;
using mint = modint998244353;

constexpr int M = 200010;
mint pow2[M], powinv2[M];

} int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  const mint inv2 = mint(2).inv();
  pow2[0] = powinv2[0] = 1;
  rep(i, M - 1) {
    pow2[i + 1] = pow2[i] * 2;
    powinv2[i + 1] = powinv2[i] * inv2;
  }
  int n, q;
  cin >> n >> q;
  VI a(n);
  rep(i, n) cin >> a[i];
  vector<mint> s(n + 1);
  rep(i, n) s[i + 1] = s[i] + a[i] * pow2[i];
  VI last_le(n);
  rep(i, n - 1) last_le[i + 1] = a[i] >= a[i + 1] ? i + 1 : last_le[i];
  while(q--) {
    int l, r;
    cin >> l >> r;
    l--;
    chmax(l, last_le[r - 1]);
    mint ans = a[l];
    ans += (s[r] - s[l + 1]) * powinv2[l + 1];
    cout << ans.val() << '\n';
  }
}
0