結果

問題 No.879 Range Mod 2 Query
ユーザー KumaTachiRenKumaTachiRen
提出日時 2023-06-01 23:37:31
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 563 ms / 3,000 ms
コード長 1,740 bytes
コンパイル時間 4,834 ms
コンパイル使用メモリ 270,172 KB
実行使用メモリ 21,156 KB
最終ジャッジ日時 2023-08-28 02:12:43
合計ジャッジ時間 12,509 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 4 ms
4,380 KB
testcase_02 AC 4 ms
4,376 KB
testcase_03 AC 4 ms
4,376 KB
testcase_04 AC 5 ms
4,380 KB
testcase_05 AC 3 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 4 ms
4,380 KB
testcase_08 AC 4 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 3 ms
4,376 KB
testcase_11 AC 542 ms
20,584 KB
testcase_12 AC 309 ms
20,652 KB
testcase_13 AC 412 ms
20,364 KB
testcase_14 AC 352 ms
20,804 KB
testcase_15 AC 363 ms
12,408 KB
testcase_16 AC 524 ms
20,876 KB
testcase_17 AC 551 ms
21,120 KB
testcase_18 AC 559 ms
20,788 KB
testcase_19 AC 516 ms
21,084 KB
testcase_20 AC 509 ms
21,156 KB
testcase_21 AC 563 ms
20,968 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>

using namespace std;
using namespace atcoder;

struct Fast
{
  Fast()
  {
    std::cin.tie(0);
    ios::sync_with_stdio(false);
  }
} fast;

#define rep(i, a, b) for (int i = (a); i < (int)(b); i++)
#define rrep(i, a, b) for (int i = (int)(b)-1; i >= (a); i--)
#define Yn(b) cout << ((b) ? "Yes" : "No") << "\n";
#define ll long long

template <typename T>
bool chmax(T &a, const T &b)
{
  if (a < b)
  {
    a = b;
    return true;
  }
  return false;
}
template <typename T>
bool chmin(T &a, const T &b)
{
  if (a > b)
  {
    a = b;
    return true;
  }
  return false;
}

using S = array<ll, 3>;
using F = array<ll, 9>;

S e() { return {0, 0, 0}; }
F id() { return {1, 0, 0, 0, 1, 0, 0, 0, 1}; }
S op(S x, S y)
{
  S z{};
  rep(i, 0, 3) z[i] = x[i] + y[i];
  return z;
}
S mapping(F f, S x)
{
  S y{};
  rep(i, 0, 3) rep(j, 0, 3) y[i] += f[3 * i + j] * x[j];
  return y;
}
F composition(F f, F g)
{
  F h{};
  rep(i, 0, 3) rep(j, 0, 3) rep(k, 0, 3) h[3 * i + j] += f[3 * i + k] * g[3 * k + j];
  return h;
}

int main()
{
  int n, q;
  cin >> n >> q;
  vector<int> a(n);
  rep(i, 0, n) cin >> a[i];
  vector<S> b(n);
  rep(i, 0, n) b[i] = {a[i], 1 - (a[i] & 1), a[i] & 1};
  lazy_segtree<S, op, e, F, mapping, composition, id> seg(b);
  while (q--)
  {
    int type;
    cin >> type;
    if (type == 1)
    {
      int l, r;
      cin >> l >> r;
      seg.apply(l - 1, r, {0, 0, 1, 0, 1, 0, 0, 0, 1});
    }
    if (type == 2)
    {
      int l, r, x;
      cin >> l >> r >> x;
      int y = x & 1;
      seg.apply(l - 1, r, {1, x, x, 0, 1 - y, y, 0, y, 1 - y});
    }
    if (type == 3)
    {
      int l, r;
      cin >> l >> r;
      cout << seg.prod(l - 1, r)[0] << "\n";
    }
  }
}
0