結果
| 問題 | No.879 Range Mod 2 Query |
| コンテスト | |
| ユーザー |
risujiroh
|
| 提出日時 | 2019-09-06 22:32:04 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.89.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 3,126 bytes |
| 記録 | |
| コンパイル時間 | 1,868 ms |
| コンパイル使用メモリ | 173,852 KB |
| 実行使用メモリ | 9,344 KB |
| 最終ジャッジ日時 | 2024-06-24 22:12:10 |
| 合計ジャッジ時間 | 3,989 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | WA * 1 |
| other | AC * 3 WA * 18 |
コンパイルメッセージ
main.cpp:13:27: warning: use of 'auto' in parameter declaration only available with '-std=c++20' or '-fconcepts'
13 | bool operator==(const auto& r) { return tp == r.tp and v == r.v; }
| ^~~~
ソースコード
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;
struct SegmentTree {
using T = struct { uint64_t s, o, e; };
static T op(const T& a, const T& b) { return {a.s + b.s, a.o + b.o, a.e + b.e}; }
static constexpr T e() { return {0, 0, 0}; }
using U = struct {
int tp; lint v;
bool operator==(const auto& r) { return tp == r.tp and v == r.v; }
};
static void ap(const U& f, T& a) {
if (f.tp == 1) {
a.s = a.o;
if (f.v & 1) swap(a.e, a.o);
} else if (f.tp == 2) {
a.s = a.e;
if (~f.v & 1) swap(a.e, a.o);
}
a.s += f.v * (a.o + a.e);
}
static void cp(const U& g, U& f) {
if (!g.tp) {
f.v += g.v;
} else if (g.tp == 1) {
if (f.tp == 2 ^ f.v & 1) {
f.tp = 2;
} else {
f.tp = 1;
}
f.v = g.v;
} else {
if (f.tp == 2 ^ f.v & 1) {
f.tp = 1;
} else {
f.tp = 2;
}
f.v = g.v;
}
}
static constexpr U id() { return {0, 0}; }
const int n;
V<T> t;
V<U> u;
SegmentTree(int n) : n(n), t(2 * n, e()), u(n, id()) {}
T& operator[](int i) { return t[i + n]; }
void build() { for (int i = n - 1; i; --i) t[i] = op(t[2 * i], t[2 * i + 1]); }
void push() { for (int i = 1; i < n; ++i) push(i); }
void apply(const U& f, int i) {
ap(f, t[i]);
if (i < n) cp(f, u[i]);
}
void push(int i) {
if (u[i] == id()) return;
apply(u[i], 2 * i);
apply(u[i], 2 * i + 1);
u[i] = id();
}
void push(int l, int r) {
for (int hl = __lg(l + n), hr = __lg(r - 1 + n); hr > 0; --hl, --hr) {
int al = l + n >> hl, ar = r - 1 + n >> hr;
if (al < n) push(al);
if (ar != al) push(ar);
}
}
T acc(int l, int r) {
push(l, r);
T resl = e(), resr = e();
for (l += n, r += n; l < r; l >>= 1, r >>= 1) {
if (l & 1) resl = op(resl, t[l++]);
if (r & 1) resr = op(t[--r], resr);
}
return op(resl, resr);
}
T get(int i) { return acc(i, i + 1); }
void act(int l, int r, const U& f) {
push(l, r);
for (int i = l + n, j = r + n; i < j; i >>= 1, j >>= 1) {
if (i & 1) apply(f, i++);
if (j & 1) apply(f, --j);
}
l = l + n >> __builtin_ctz(l + n);
while (l >>= 1) t[l] = op(t[2 * l], t[2 * l + 1]);
r = r + n >> __builtin_ctz(r + n);
while (r >>= 1) t[r] = op(t[2 * r], t[2 * r + 1]);
}
void set(int i, const T& a) {
push(i, i + 1);
t[i += n] = a;
while (i >>= 1) t[i] = op(t[2 * i], t[2 * i + 1]);
}
};
int main() {
cin.tie(nullptr); ios::sync_with_stdio(false);
int n, q; cin >> n >> q;
SegmentTree st(n);
for (int i = 0; i < n; ++i) {
uint64_t a; cin >> a;
st[i] = {a, a & 1, ~a & 1};
}
st.build();
while (q--) {
int tp; cin >> tp;
if (tp == 1) {
int l, r; cin >> l >> r, --l;
st.act(l, r, {1, 0});
} else if (tp == 2) {
int l, r, x; cin >> l >> r >> x, --l;
st.act(l, r, {0, x});
} else {
int l, r; cin >> l >> r, --l;
cout << st.acc(l, r).s << '\n';
}
}
}
risujiroh