QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#756885 | #9727. Barkley III | electricstick | WA | 1ms | 5776kb | C++20 | 4.2kb | 2024-11-16 22:28:47 | 2024-11-16 22:28:48 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for (int i = a; i < (b); i++)
#define all(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define bit(x) (1ull << (x))
using ll = long long;
using ull = uint64_t;
using PII = pair<ll, ll>;
using VI = vector<int>;
#ifdef DEBUG
#include "debug.cpp"
#else
#define debug(...) 42
#endif
const int N = 1.01e6;
ll n, q;
ull a[N];
struct Node {
ull x, y, v, sz;
ull tag;
} seg[N << 2];
Node op(const Node &lhs, const Node &rhs) {
Node S = {(lhs.x ^ rhs.x), (lhs.y | rhs.y) | (lhs.x & rhs.x), lhs.v & rhs.v,
lhs.sz + rhs.sz, ~ull(0)};
S.x &= ~S.y;
return S;
}
void pull(int id) { seg[id] = op(seg[id * 2], seg[id * 2 + 1]); }
void settag(int id, ull t) {
seg[id].v &= ~t;
seg[id].tag &= t;
if (seg[id].sz == 1) {
seg[id].x = ~seg[id].v;
seg[id].y = 0;
} else {
seg[id].y &= t;
seg[id].x &= ~t;
}
}
void push(int id) {
if (seg[id].tag != ~ull(0)) {
settag(id * 2, seg[id].tag);
settag(id * 2 + 1, seg[id].tag);
seg[id].tag = ~ull(0);
}
}
void build(int l, int r, int id) {
seg[id].tag = ~ull(0);
if (l == r) {
seg[id].v = a[l];
seg[id].y = 0;
seg[id].x = ~seg[id].v;
seg[id].sz = 1;
} else {
int m = midpoint(l, r);
build(l, m, id * 2);
build(m + 1, r, id * 2 + 1);
pull(id);
}
}
void modify(int l, int r, int id, int pos, ull x) {
if (l == r) {
seg[id].v = x;
seg[id].y = 0;
seg[id].x = ~seg[id].v;
seg[id].sz = 1;
} else {
int m = midpoint(l, r);
push(id);
if (pos <= m) {
modify(l, m, id * 2, pos, x);
} else {
modify(m + 1, r, id * 2 + 1, pos, x);
}
pull(id);
}
}
void change(int l, int r, int id, int ql, int qr, ull t) {
if (ql == l && qr == r) {
settag(id, t);
} else {
int m = midpoint(l, r);
push(id);
if (qr <= m) {
change(l, m, id * 2, ql, qr, t);
} else if (ql > m) {
change(m + 1, r, id * 2 + 1, ql, qr, t);
} else {
change(l, m, id * 2, ql, m, t);
change(m + 1, r, id * 2 + 1, m + 1, qr, t);
}
pull(id);
}
}
Node query(int l, int r, int id, int ql, int qr) {
if (ql == l && qr == r) {
return seg[id];
} else {
int m = midpoint(l, r);
push(id);
if (qr <= m) {
return query(l, m, id * 2, ql, qr);
} else if (ql > m) {
return query(m + 1, r, id * 2 + 1, ql, qr);
} else {
return op(query(l, m, id * 2, ql, m),
query(m + 1, r, id * 2 + 1, m + 1, qr));
}
}
}
optional<ull> search(int l, int r, int id, int ql, int qr, int k) {
if (ql == l && qr == r) {
if ((seg[id].x & bit(k)) == 0) return {};
if (l == r) return seg[id].v;
int m = midpoint(l, r);
push(id);
if (seg[id * 2].x & bit(k)) {
return search(l, m, id * 2, ql, m, k);
} else {
return search(m + 1, r, id * 2 + 1, m + 1, qr, k);
}
} else {
int m = midpoint(l, r);
push(id);
if (qr <= m) {
return search(l, m, id * 2, ql, qr, k);
} else if (ql > m) {
return search(m + 1, r, id * 2 + 1, ql, qr, k);
} else {
auto x = search(l, m, id * 2, ql, m, k);
if (x) return x;
return search(m + 1, r, id * 2 + 1, m + 1, qr, k);
}
}
}
void solve() {
cin >> n >> q;
rep(i, 1, n + 1) cin >> a[i];
build(1, n, 1);
while (q--) {
ull op, l, r, s, x;
cin >> op;
if (op == 1) {
cin >> l >> r >> x;
change(1, n, 1, l, r, ~x);
} else if (op == 2) {
cin >> s >> x;
modify(1, n, 1, s, x);
} else {
cin >> l >> r;
auto nd = query(1, n, 1, l, r);
if (nd.x == 0) {
cout << nd.v << '\n';
} else {
int w{};
rep(i, 0, 64) if (nd.x & bit(i)) w = i;
auto p = search(1, n, 1, l, r, w);
rep(i, 0, 64) {
if ((nd.x & bit(i)) && (p.value() & bit(i)) == 0) {
nd.v |= bit(i);
}
}
cout << nd.v << '\n';
}
}
}
}
int main() {
cin.tie(0)->sync_with_stdio(0);
cout << fixed << setprecision(12);
int tt = 1;
// cin >> tt;
while (tt--) {
solve();
}
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 5760kb
input:
5 9 7 7 7 6 7 3 1 5 2 1 3 3 1 5 3 1 3 1 1 2 3 3 1 3 2 2 8 3 1 3 3 1 2
output:
7 6 7 3 3 8
result:
ok 6 lines
Test #2:
score: 0
Accepted
time: 1ms
memory: 5708kb
input:
10 10 6760061359215711796 1568091718842717482 1568091718842717482 1568091718842717482 5232472783634052627 8795942500783873690 1568091718842717482 1568091718842717482 1568091718842717482 1568091718842717482 1 3 5 7587422031989082829 3 6 10 1 7 8 5197616143400216932 2 4 2518604563805514908 2 2 4533959...
output:
1568091718842717482 35184908959744 176025477579040 8795942500783873690
result:
ok 4 lines
Test #3:
score: -100
Wrong Answer
time: 1ms
memory: 5776kb
input:
100 100 4263579105072360993 4263579105072360993 4263579105072360993 4263579105072360993 4263579105072360993 4263579105072360993 4263579105072360993 4263579105072360993 4263579105072360993 625967318191814868 4263579105072360993 4263579105072360993 4263579105072360993 4263579105072360993 4263579105072...
output:
576531121047601152 1 576460752303423488 4263579105072360993 1306043896232411137 4263579105072360993 576531121047601152 633397148123136 2305843013525438464 2845573901390510121 8974787518591588089 1730020640668059136 8819723155916537833 563018740006912 3422105606705444905 576460752303423488 1729387320...
result:
wrong answer 9th lines differ - expected: '0', found: '2305843013525438464'