結果

問題 No.2498 OX Operations
ユーザー KudeKude
提出日時 2023-10-07 00:49:34
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,543 ms / 4,000 ms
コード長 4,048 bytes
コンパイル時間 4,702 ms
コンパイル使用メモリ 303,012 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-07-26 17:38:47
合計ジャッジ時間 21,290 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 2 ms
6,940 KB
testcase_08 AC 2 ms
6,940 KB
testcase_09 AC 2 ms
6,940 KB
testcase_10 AC 2 ms
6,944 KB
testcase_11 AC 4 ms
6,940 KB
testcase_12 AC 11 ms
6,940 KB
testcase_13 AC 7 ms
6,944 KB
testcase_14 AC 11 ms
6,940 KB
testcase_15 AC 1,197 ms
6,940 KB
testcase_16 AC 1,353 ms
6,940 KB
testcase_17 AC 1,138 ms
6,940 KB
testcase_18 AC 1,509 ms
6,940 KB
testcase_19 AC 1,482 ms
6,944 KB
testcase_20 AC 1,514 ms
6,940 KB
testcase_21 AC 1,513 ms
6,940 KB
testcase_22 AC 514 ms
6,944 KB
testcase_23 AC 409 ms
6,944 KB
testcase_24 AC 1,536 ms
6,944 KB
testcase_25 AC 1,535 ms
6,944 KB
testcase_26 AC 1,543 ms
6,940 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
In file included from /usr/include/atcoder/modint:1,
                 from /usr/include/atcoder/convolution.hpp:11,
                 from /usr/include/atcoder/convolution:1,
                 from /usr/include/atcoder/all:1,
                 from main.cpp:8:
In member function '{anonymous}::atcoder::static_modint<m, <anonymous> >::mint& {anonymous}::atcoder::static_modint<m, <anonymous> >::operator+=(const mint&) [with int m = 998244353; std::enable_if_t<(1 <= m)>* <anonymous> = 0]',
    inlined from 'int main()' at main.cpp:146:41:
/usr/include/atcoder/modint.hpp:75:9: warning: iteration 30 invokes undefined behavior [-Waggressive-loop-optimizations]
   75 |         _v += rhs._v;
      |         ^~
main.cpp: In function 'int main()':
main.cpp:12:35: note: within this loop
   12 | #define rep(i,n) for(int i = 0; i < (int)(n); i++)
      |                                   ^
main.cpp:145:17: note: in expansion of macro 'rep'
  145 |       rep(i, 2) rep(j, 31) rep(p, 2) rep(q, 2) {
      |                 ^~~

ソースコード

diff #

#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#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;

template <class F, F (*composition)(F, F), F (*id)()> struct dual_segtree {
  public:
    dual_segtree() : dual_segtree(0) {}
    explicit dual_segtree(int n) : dual_segtree(std::vector<F>(n, id())) {}
    explicit dual_segtree(const std::vector<F>& v) : _n(int(v.size())) {
        auto ceil_log2 = [](int n) {
            int x = 0;
            while ((1U << x) < (unsigned int)(n)) x++;
            return x;
        };
        log = ceil_log2(_n);
        size = 1 << log;
        lz = std::vector<F>(2 * size, id());
        for (int i = 0; i < _n; i++) lz[size + i] = v[i];
    }

    void set(int p, F x) {
        assert(0 <= p && p < _n);
        p += size;
        for (int i = log; i >= 1; i--) push(p >> i);
        lz[p] = x;
    }

    F get(int p) {
        assert(0 <= p && p < _n);
        p += size;
        for (int i = log; i >= 1; i--) push(p >> i);
        return lz[p];
    }

    void apply(int p, F f) {
        assert(0 <= p && p < _n);
        p += size;
        for (int i = log; i >= 1; i--) push(p >> i);
        lz[p] = composition(f, lz[p]);
    }
    void apply(int l, int r, F f) {
        assert(0 <= l && l <= r && r <= _n);
        if (l == r) return;

        l += size;
        r += size;

        for (int i = log; i >= 1; i--) {
            if (((l >> i) << i) != l) push(l >> i);
            if (((r >> i) << i) != r) push((r - 1) >> i);
        }

        while (l < r) {
            if (l & 1) all_apply(l++, f);
            if (r & 1) all_apply(--r, f);
            l >>= 1;
            r >>= 1;
        }
    }

    void push_all() {
        for (int i = 1; i < size; i++) push(i);
    }
    F get_raw(int p) {
        assert(0 <= p && p < _n);
        return lz[size + p];
    }

  private:
    int _n, size, log;
    std::vector<F> lz;

    void all_apply(int k, F f) {
        lz[k] = composition(f, lz[k]);
    }
    void push(int k) {
        all_apply(2 * k, lz[k]);
        all_apply(2 * k + 1, lz[k]);
        lz[k] = id();
    }
};

struct F {
  int a, b;
};

F compositon(F f, F g) {
  // fa(gax + gb) + fb
  return {f.a & g.a, (f.a & g.b) ^ f.b};
}

F id() {
  return {~0, 0};
}

} int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, q;
  cin >> n >> q;
  VI m(n);
  rep(i, n) cin >> m[i];
  dual_segtree<F, compositon, id> seg(n);
  rep(_, q) {
    char c;
    int l, r, x;
    cin >> c >> l >> r >> x;
    l--;
    if (c == 'o') seg.apply(l, r, {~x, x});
    else seg.apply(l, r, {~0, x});
  }
  vector<mint> cnt(31, 1);
  rep(i, n) {
    auto [a, b] = seg.get(i);
    int x = b, y = a ^ b;
    mint f[2][31];
    f[0][0] = 1;
    int k = m[i];
    rep(_, 31) {
      mint g[2][2];
      g[0][x & 1] = 1;
      g[1][y & 1] = 1;
      mint nf[4][31];
      rep(i, 2) rep(j, 31) rep(p, 2) rep(q, 2) {
        nf[i+p][j+q] += f[i][j] * g[p][q];
      }
      rrep(i, 3) rep(j, 31) nf[i+1][j] += nf[i][j];
      rep(i, 4) if ((i & 1) == (k & 1)) rep(j, 31) {
        f[i >> 1][j] = nf[i][j];
      }
      x >>= 1, y >>= 1, k >>= 1;
    }
    rep(j, 30) f[0][j+1] += f[0][j];
    rep(j, 31) cnt[j] *= f[0][j];
  }
  rrep(j, 30) cnt[j+1] -= cnt[j];
  mint ans;
  rep(j, 31) ans += j * cnt[j];
  cout << ans.val() << '\n';
}
0