結果

問題 No.2498 OX Operations
ユーザー ecottea
提出日時 2023-10-07 01:16:16
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 2,042 ms / 4,000 ms
コード長 10,186 bytes
コンパイル時間 4,328 ms
コンパイル使用メモリ 267,588 KB
最終ジャッジ日時 2025-02-17 05:59:08
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 23
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

#ifndef HIDDEN_IN_VS //
//
#define _CRT_SECURE_NO_WARNINGS
//
#include <bits/stdc++.h>
using namespace std;
//
using ll = long long; // -2^63 2^63 = 9 * 10^18int -2^31 2^31 = 2 * 10^9
using pii = pair<int, int>; using pll = pair<ll, ll>; using pil = pair<int, ll>; using pli = pair<ll, int>;
using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>; using vvvvi = vector<vvvi>;
using vl = vector<ll>; using vvl = vector<vl>; using vvvl = vector<vvl>; using vvvvl = vector<vvvl>;
using vb = vector<bool>; using vvb = vector<vb>; using vvvb = vector<vvb>;
using vc = vector<char>; using vvc = vector<vc>; using vvvc = vector<vvc>;
using vd = vector<double>; using vvd = vector<vd>; using vvvd = vector<vvd>;
template <class T> using priority_queue_rev = priority_queue<T, vector<T>, greater<T>>;
using Graph = vvi;
//
const double PI = acos(-1);
const vi DX = { 1, 0, -1, 0 }; // 4
const vi DY = { 0, 1, 0, -1 };
int INF = 1001001001; ll INFL = 4004004003104004004LL; // (int)INFL = 1010931620;
double EPS = 1e-15;
//
struct fast_io { fast_io() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(18); } } fastIOtmp;
//
#define all(a) (a).begin(), (a).end()
#define sz(x) ((int)(x).size())
#define lbpos(a, x) (int)distance((a).begin(), std::lower_bound(all(a), x))
#define ubpos(a, x) (int)distance((a).begin(), std::upper_bound(all(a), x))
#define Yes(b) {cout << ((b) ? "Yes\n" : "No\n");}
#define rep(i, n) for(int i = 0, i##_len = int(n); i < i##_len; ++i) // 0 n-1
#define repi(i, s, t) for(int i = int(s), i##_end = int(t); i <= i##_end; ++i) // s t
#define repir(i, s, t) for(int i = int(s), i##_end = int(t); i >= i##_end; --i) // s t
#define repe(v, a) for(const auto& v : (a)) // a
#define repea(v, a) for(auto& v : (a)) // a
#define repb(set, d) for(int set = 0; set < (1 << int(d)); ++set) // d
#define repp(a) sort(all(a)); for(bool a##_perm = true; a##_perm; a##_perm = next_permutation(all(a))) // a
#define smod(n, m) ((((n) % (m)) + (m)) % (m)) // mod
#define uniq(a) {sort(all(a)); (a).erase(unique(all(a)), (a).end());} //
#define EXIT(a) {cout << (a) << endl; exit(0);} //
#define inQ(x, y, u, l, d, r) ((u) <= (x) && (l) <= (y) && (x) < (d) && (y) < (r)) //
//
template <class T> inline ll pow(T n, int k) { ll v = 1; rep(i, k) v *= n; return v; }
template <class T> inline bool chmax(T& M, const T& x) { if (M < x) { M = x; return true; } return false; } // true
    
template <class T> inline bool chmin(T& m, const T& x) { if (m > x) { m = x; return true; } return false; } // true
    
template <class T> inline T get(T set, int i) { return (set >> i) & T(1); }
//
template <class T, class U> inline istream& operator>>(istream& is, pair<T, U>& p) { is >> p.first >> p.second; return is; }
template <class T> inline istream& operator>>(istream& is, vector<T>& v) { repea(x, v) is >> x; return is; }
template <class T> inline vector<T>& operator--(vector<T>& v) { repea(x, v) --x; return v; }
template <class T> inline vector<T>& operator++(vector<T>& v) { repea(x, v) ++x; return v; }
#endif //
#if __has_include(<atcoder/all>)
#include <atcoder/all>
using namespace atcoder;
#ifdef _MSC_VER
#include "localACL.hpp"
#endif
//using mint = modint1000000007;
using mint = modint998244353;
//using mint = modint; // mint::set_mod(m);
namespace atcoder {
inline istream& operator>>(istream& is, mint& x) { ll x_; is >> x_; x = x_; return is; }
inline ostream& operator<<(ostream& os, const mint& x) { os << x.val(); return os; }
}
using vm = vector<mint>; using vvm = vector<vm>; using vvvm = vector<vvm>; using vvvvm = vector<vvvm>;
#endif
#ifdef _MSC_VER // Visual Studio
#include "local.hpp"
#else // gcc
inline int popcount(int n) { return __builtin_popcount(n); }
inline int popcount(ll n) { return __builtin_popcountll(n); }
inline int lsb(int n) { return n != 0 ? __builtin_ctz(n) : -1; }
inline int lsb(ll n) { return n != 0 ? __builtin_ctzll(n) : -1; }
inline int msb(int n) { return n != 0 ? (31 - __builtin_clz(n)) : -1; }
inline int msb(ll n) { return n != 0 ? (63 - __builtin_clzll(n)) : -1; }
inline int msb(__int128 n) { return (n >> 64) != 0 ? (127 - __builtin_clzll((ll)(n >> 64))) : n != 0 ? (63 - __builtin_clzll((ll)(n))) : -1; }
#define gcd __gcd
#define dump(...)
#define dumpel(v)
#define dump_list(v)
#define dump_mat(v)
#define input_from_file(f)
#define output_to_file(f)
#define Assert(b) { if (!(b)) while (1) cout << "OLE"; }
#endif
//AND XOR
using S110 = int;
S110 op110(S110 x, S110 y) { return x ^ y; }
S110 e110() { return 0; }
using F110 = int;
S110 act110(F110 f, S110 x) { return f & x; }
F110 comp110(F110 f, F110 g) { return f & g; }
F110 id110() { return ~0; }
#define AND_XOR_mmonoid S110, op110, e110, F110, act110, comp110, id110
// DPO(n b m)
/*
* b=10 n num m
*/
vm count_digit_sum(const string& num, const string& a0, const string& a1, int b = 2) {
// : https://ferin-tech.hatenablog.com/entry/2019/11/10/%E6%A1%81DP%E3%81%AE%E5%AE%9F%E8%A3%85
// verify : https://atcoder.jp/contests/dp/tasks/dp_s
int n = sz(num);
// dump(n);
// dp[i][f][j] :
// i : d[0..i)
// f : d[0..i) < num[0..i) 1 0
// j : d[0..i) popcount
int K = 30;
vvvm dp(n + 1, vvm(1LL << 1, vm(K + 1)));
dp[0][0][0] = 1;
// DP
rep(i, n) {
// x : num i
int x = num[i] - '0';
repb(f, 1) {
// d_max : d[i]
int d_max = (f ? b - 1 : x);
repi(j, 0, K) {
// d : d[i]
repi(d, 0, d_max) {
int nf = (int)(f || (d < d_max));
int nj = j;
if (d == 0) nj += a0[i] - '0';
else nj += a1[i] - '0';
if (nj <= K) dp[i + 1][nf][nj] += dp[i][f][j];
}
}
}
// dump(i + 1);
// dump("!smaller"); dump(dp[i + 1][0]);
// dump("smaller"); dump(dp[i + 1][1]);
}
vm res(K + 1);
repi(j, 0, K) res[j] += dp[n][0][j] + dp[n][1][j];
return res;
}
//O(n)
/*
* a[0..n)
* A[i] = Σj≦i a[j]
* A[0..n)
*/
template <typename T>
void leq_zeta(vector<T>& a) {
// : https://qiita.com/convexineq/items/afc84dfb9ee4ec4a67d5
//n = 8
// A[0] = a[0]
// A[1] = a[0] + a[1]
// A[2] = a[0] + a[1] + a[2]
// A[3] = a[0] + a[1] + a[2] + a[3]
// A[4] = a[0] + a[1] + a[2] + a[3] + a[4]
// A[5] = a[0] + a[1] + a[2] + a[3] + a[4] + a[5]
// A[6] = a[0] + a[1] + a[2] + a[3] + a[4] + a[5] + a[6]
// A[7] = a[0] + a[1] + a[2] + a[3] + a[4] + a[5] + a[6] + a[7]
int n = sz(a);
repi(i, 1, n - 1) a[i] += a[i - 1];
}
//O(n)
/*
* A[0..n)
* A[i] = Σj≦i a[j]
* a[0..n)
*/
template <typename T>
void leq_mobius(vector<T>& A) {
// : https://qiita.com/convexineq/items/afc84dfb9ee4ec4a67d5
//n = 8
// a[0] = + A[0]
// a[1] = - A[0] + A[1]
// a[2] = - A[1] + A[2]
// a[3] = - A[2] + A[3]
// a[4] = - A[3] + A[4]
// a[5] = - A[4] + A[5]
// a[6] = - A[5] + A[6]
// a[7] = - A[6] + A[7]
int n = sz(A);
repir(i, n - 1, 1) A[i] -= A[i - 1];
}
// max O(n)
/*
* a[0..n), b[0..n)
* c[k] = Σ_(max(i,j) = k) a[i] b[j]
* c[0..n)
*
* ,
*/
template <typename T>
vector<T> max_convolution(vector<vector<T>>& a) {
// : https://qiita.com/convexineq/items/afc84dfb9ee4ec4a67d5
int n = sz(a), K = 30;
rep(i, n) leq_zeta(a[i]);
vm b(K + 1, 1);
rep(i, n) repi(j, 0, K) b[j] *= a[i][j];
leq_mobius(b);
return b;
}
int main() {
// input_from_file("input.txt");
// output_to_file("output.txt");
int n, q;
cin >> n >> q;
vi m(n);
cin >> m;
vector<lazy_segtree<AND_XOR_mmonoid>> seg(2, lazy_segtree<AND_XOR_mmonoid>(n + 2));
seg[1].set(0, ~0);
dump(seg[0]); dump(seg[1]);
rep(hoge, q) {
char c; int l, r, x;
cin >> c >> l >> r >> x;
r++;
rep(b, 2) {
if (c == 'o') {
int al1 = seg[b].prod(0, l);
int al2 = seg[b].prod(0, l + 1);
int ar1 = seg[b].prod(0, r);
int ar2 = seg[b].prod(0, r + 1);
al2 |= x;
ar1 |= x;
seg[b].set(l, al1 ^ al2);
seg[b].set(r, ar1 ^ ar2);
seg[b].apply(l + 1, r, ~x);
}
else {
seg[b].set(l, seg[b].get(l) ^ x);
seg[b].set(r, seg[b].get(r) ^ x);
}
}
dump(seg[0]); dump(seg[1]);
}
vi a0(n), a1(n);
a0[0] = seg[0].prod(0, 2);
a1[0] = seg[1].prod(0, 2);
repi(i, 1, n - 1) {
a0[i] = a0[i - 1] ^ seg[0].get(i + 1);
a1[i] = a1[i - 1] ^ seg[1].get(i + 1);
}
dump(a0); dump(a1);
int K = 30;
vvm cnt(n);
rep(i, n) cnt[i] = count_digit_sum(bitset<30>(m[i]).to_string(),
bitset<30>(a0[i]).to_string(), bitset<30>(a1[i]).to_string());
dumpel(cnt);
auto Cnt = max_convolution(cnt);
dump(Cnt);
mint res = 0;
repi(j, 0, K) res += Cnt[j] * j;
cout << res << endl;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0