QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#756630 | #9727. Barkley III | electricstick | WA | 4ms | 97260kb | C++23 | 3.6kb | 2024-11-16 21:16:48 | 2024-11-16 21:16:50 |
Judging History
answer
#include<cstdio>
const int N = 1e6 + 10;
using u64 = unsigned long long;
struct node {
u64 andsum;
u64 zero1, zero2;
node(): node{~0ull} {}
node(u64 x): andsum{x}, zero1{~x}, zero2{0} {}
node(u64 x, u64 y, u64 z): andsum{x}, zero1{y}, zero2{z} {}
node operator+(const node& oth) const {
return node{
andsum & oth.andsum,
(zero1 ^ oth.zero1) & ~(zero2 | oth.zero2),
zero2 | oth.zero2 | (zero1 & oth.zero1)
};
}
}t[N << 2];
u64 tag[N << 2];
int n, q;
u64 a[N];
void build(int rt, int l, int r) {
tag[rt] = ~0ull;
if (l == r) {
t[rt] = node{a[l]};
return;
}
int mid = (l + r) >> 1;
build(rt << 1, l, mid);
build(rt << 1 | 1, mid + 1, r);
t[rt] = t[rt << 1] + t[rt << 1 | 1];
}
void adt(int rt, int l, int r, u64 x) {
if(l == r) {
t[rt] = node{t[rt].andsum & x};
} else {
t[rt] = t[rt] + node{x, 0, ~x};
tag[rt] &= x;
}
}
void pushdown(int rt, int l, int r) {
if(~tag[rt]) {
int mid = (l + r) >> 1;
adt(rt << 1, l, mid, tag[rt]);
adt(rt << 1 | 1, mid + 1, r, tag[rt]);
tag[rt] = ~0ull;
}
}
void update(int rt, int l, int r, int p, u64 x) {
if(l == r) {
t[rt] = node{x};
} else {
int mid = (l + r) >> 1;
pushdown(rt, l, r);
if(p <= mid) update(rt << 1, l, mid, p, x);
else update(rt << 1 | 1, mid + 1, r, p, x);
t[rt] = t[rt << 1] + t[rt << 1 | 1];
}
}
void update(int rt, int l, int r, int ql, int qr, u64 x) {
if(ql <= l && r <= qr) {
adt(rt, l, r, x);
} else {
int mid = (l + r) >> 1;
pushdown(rt, l, r);
if(ql <= mid) update(rt << 1, l, mid, ql, qr, x);
if(mid < qr) update(rt << 1 | 1, mid + 1, r, ql, qr, x);
t[rt] = t[rt << 1] + t[rt << 1 | 1];
}
}
node query(int rt, int l, int r, int ql, int qr) {
if(ql <= l && r <= qr) {
return t[rt];
} else {
int mid = (l + r) >> 1;
pushdown(rt, l, r);
node res{};
if(ql <= mid) res = res + query(rt << 1, l, mid, ql, qr);
if(mid < qr) res = res + query(rt << 1 | 1, mid + 1, r, ql, qr);
return res;
}
}
u64 query(int rt, int l, int r, int ql, int qr, int k) {
int mid = (l + r) >> 1;
if(l < r) pushdown(rt, l, r);
if(ql <= l && r <= qr) {
if((t[rt].zero1 >> k) & 1) return 0;
if(l == r) return t[rt].andsum;
if((t[rt << 1].zero1 >> k) & 1) return query(rt << 1, l, mid, ql, qr, k);
else return query(rt << 1 | 1, mid + 1, r, ql, qr, k);
} else {
u64 res = 0;
if(ql <= mid) res |= query(rt << 1, l, mid, ql, qr, k);
if(mid < qr) res |= query(rt << 1 | 1, mid + 1, r, ql, qr, k);
return res;
}
}
int main() {
scanf("%d%d", &n, &q);
for(int i = 1; i <= n; ++i) scanf("%llu", &a[i]);
build(1, 1, n);
while(q--) {
int opt, l, r; u64 x;
scanf("%d", &opt);
switch(opt) {
case 1: {
scanf("%d%d%llu", &l, &r, &x);
update(1, 1, n, l, r, x);
break;
}
case 2: {
scanf("%d%llu", &l, &x);
update(1, 1, n, l, x);
break;
}
case 3: {
scanf("%d%d", &l, &r);
auto [sum, zero1, zero2] = query(1, 1, n, l, r);
int k = -1;
for(int i = 63; ~i; --i) {
if((zero1 >> i) & 1) {
k = i;
break;
}
}
if(~k) {
u64 y = query(1, 1, n, l, r, k);
for(int i = 0; i < 64; i++) {
if(((zero1 >> i) & 1) && ((y >> i) & 1 ^ 1)) {
sum |= (1 << i);
}
}
}
printf("%llu\n", sum);
break;
}
}
}
return 0;
}
詳細信息
Test #1:
score: 0
Wrong Answer
time: 4ms
memory: 97260kb
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 7 7 3 3 11
result:
wrong answer 2nd lines differ - expected: '6', found: '7'