結果

問題 No.2611 Count 01
ユーザー KudeKude
提出日時 2024-01-19 22:17:36
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 207 ms / 6,000 ms
コード長 1,794 bytes
コンパイル時間 3,272 ms
コンパイル使用メモリ 277,936 KB
実行使用メモリ 24,740 KB
最終ジャッジ日時 2024-01-19 22:17:46
合計ジャッジ時間 9,052 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 2 ms
6,676 KB
testcase_03 AC 192 ms
24,740 KB
testcase_04 AC 171 ms
24,740 KB
testcase_05 AC 204 ms
24,740 KB
testcase_06 AC 180 ms
24,740 KB
testcase_07 AC 190 ms
24,740 KB
testcase_08 AC 190 ms
24,740 KB
testcase_09 AC 180 ms
24,740 KB
testcase_10 AC 207 ms
24,740 KB
testcase_11 AC 174 ms
24,740 KB
testcase_12 AC 182 ms
24,740 KB
testcase_13 AC 167 ms
24,740 KB
testcase_14 AC 179 ms
24,740 KB
testcase_15 AC 176 ms
24,740 KB
testcase_16 AC 206 ms
24,740 KB
testcase_17 AC 180 ms
24,740 KB
testcase_18 AC 180 ms
24,740 KB
testcase_19 AC 188 ms
24,740 KB
testcase_20 AC 182 ms
24,740 KB
testcase_21 AC 182 ms
24,740 KB
testcase_22 AC 206 ms
24,740 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
namespace {
#pragma GCC diagnostic ignored "-Wunused-function"
#include<atcoder/all>
#pragma GCC diagnostic warning "-Wunused-function"
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;

struct S {
  mint lr, l, r, c;
  mint c0, s0, c1, s1;
};

S op(S x, S y) {
  return S{
    x.lr + y.lr - x.c0 * y.c1 - x.c1 * y.c0,
    x.l + y.l + x.c0 * y.s1 + x.c1 * y.s0,
    x.r + y.r + x.s0 * y.c1 + x.s1 * y.c0,
    x.c + y.c - x.s0 * y.s1 - x.s1 * y.s0,
    x.c0 + y.c0, x.s0 + y.s0, x.c1 + y.c1, x.s1 + y.s1
  };
}
S e() {
  return S{};
}

} int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, q;
  cin >> n >> q;
  string s;
  cin >> s;
  vector<S> init(n);
  rep(i, n) {
    init[i] = s[i] == '0' ? S{0, 0, 0, 0, 1, i, 0, 0} : S{0, 0, 0, 0, 0, 0, 1, i};
  }
  segtree<S, op, e> seg(init);
  rep(_, q) {
    int op;
    cin >> op;
    if (op == 1) {
      int i;
      cin >> i;
      i--;
      s[i] ^= '0' ^ '1';
      seg.set(i, s[i] == '0' ? S{0, 0, 0, 0, 1, i, 0, 0} : S{0, 0, 0, 0, 0, 0, 1, i});
    } else {
      int l, r;
      cin >> l >> r;
      l--;
      auto s = seg.prod(l, r);
      l--;
      mint ans = s.lr * l * r + s.l * l + s.r * r + s.c;
      cout << ans.val() << '\n';
    }
  }
}
0