QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#755851 | #9727. Barkley III | electricstick | WA | 11ms | 128624kb | C++17 | 4.8kb | 2024-11-16 18:13:08 | 2024-11-16 18:13:09 |
Judging History
answer
#include<cstdio>
const int N = 1e6 + 10;
using u128 = __uint128_t;
using u64 = __uint64_t;
u128 st1, st2;
int n, q;
u64 a[N];
u128 to128(u64 x) {
u128 res{0};
for(int i = 0; i < 64; i++) {
res |= ((((u128)x) >> i) & 1) << (i << 1);
}
return res;
}
u64 to64(u128 x) {
u64 res{0};
for(int i = 0; i < 64; i++) {
res |= ((x >> (i << 1)) & 1) << i;
}
return res;
}
struct node {
u128 band, f;
node(): node(st1) {}
node(u128 x): band(x), f((~x) & st1){}
node(u128 x, u128 f): band(x), f(f) {}
node operator+ (const node &oth) {
node ans{0, 0};
ans.band = band & oth.band;
ans.f = ((f & st1) + (oth.f & st1)) | (f & st2) | (oth.f & st2);
return ans;
}
}t[N << 2];
u128 tag[N << 2];
void build(int rt, int l, int r) {
tag[rt] = ~u128{0};
if(l == r) {
t[rt] = node{to128(a[l])};
return;
}
int m = (l + r) >> 1;
build(rt << 1, l, m);
build(rt << 1 | 1, m + 1, r);
t[rt] = t[rt << 1] + t[rt << 1 | 1];
}
void adt(int rt, int l, int r, u128 x) {
if(r - l + 1 == 1) {
t[rt] = node{t[rt].band & x};
tag[rt] &= x;
} else {
t[rt] = t[rt] + node{x << 1};
tag[rt] &= x;
}
}
void pushdown(int rt, int l, int r, int m) {
if(~tag[rt]) {
adt(rt << 1, l, m, tag[rt]);
adt(rt << 1 | 1, m + 1, r, tag[rt]);
tag[rt] = ~u128{0};
}
}
void update(int rt, int l, int r, int p, u128 x) {
if(l == r) {
t[rt] = node{x};
return;
}
int m = (l + r) >> 1;
pushdown(rt, l, r, m);
p <= m? update(rt << 1, l, m, p, x): update(rt << 1 | 1, m + 1, r, p, x);
t[rt] = t[rt << 1] + t[rt << 1 | 1];
// printf("?[%d, %d]: %llu %llu %llu\n", l, r, to64(t[rt].band), to64(t[rt << 1].band), to64(t[rt << 1|1].band));
}
void update(int rt, int l, int r, int ql, int qr, u128 x) {
if(ql <= l && r <= qr) {
adt(rt, l, r, x);
return;
}
int m = (l + r) >> 1;
pushdown(rt, l, r, m);
if(ql <= m) update(rt << 1, l, m, ql, qr, x);
if(qr > m) update(rt << 1 | 1, m + 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) {
// printf("[%d, %d]: %llu %llu %llu\n", l, r, to64(t[rt].band), to64(t[rt << 1].band), to64(t[rt << 1|1].band));
if(ql <= l && r <= qr) {
return t[rt];
}
int m = (l + r) >> 1;
pushdown(rt, l, r, m);
node res{};
if(ql <= m) res = res + query(rt << 1, l, m, ql, qr);
if(qr > m) res = res + query(rt << 1 | 1, m + 1, r, ql, qr);
return res;
}
u128 query(int rt, int l, int r, int ql, int qr, int k) {
// printf("![%d, %d]: %llu %llu %llu\n", l, r, to64(t[rt].band), to64(t[rt << 1].band), to64(t[rt << 1|1].band));
int m = (l + r) >> 1;
if(ql <= l && r <= qr) {
if((t[rt].f >> (k << 1) & 3) != 1) {
return 0;
}
if(l == r) {
return t[rt].band;
}
pushdown(rt, l, r, m);
if(((t[rt << 1].f >> (k << 1)) & 3) == 1) {
return query(rt << 1, l, m, ql, qr, k);
} else {
return query(rt << 1 | 1, m + 1, r, ql, qr, k);
}
}
pushdown(rt, l, r, m);
u128 res = 0;
if(ql <= m) res |= query(rt << 1, l, m, ql, qr, k);
if(qr > m) res |= query(rt << 1, m + 1, r, l, qr, k);
return res;
}
int main() {
for(int i = 0; i < 64; i++) {
st1 = st1 << 2 | 1;
st2 = st2 << 2 | 2;
}
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;
unsigned long long x;
scanf("%d", &opt);
switch(opt) {
case 1: {
scanf("%d%d%llu", &l, &r, &x);
update(1, 1, n, l, r, to128(x));
break;
}
case 2: {
scanf("%d%llu", &l, &x);
update(1, 1, n, l, to128(x));
break;
}
case 3: {
scanf("%d%d", &l, &r);
auto [p, f] = query(1, 1, n, l, r);
x = to64(p);
int k = -1;
for(int i = 63; ~i; i--) {
if(((f >> (i << 1)) & 3) == 1) {
k = i;
break;
}
}
// printf("#%d %llu\n", k, x);
if(k == -1) {
printf("%llu\n", x);
} else {
u64 y = to64(query(1, 1, n, l, r, k));
for(int i = 0; i < 64; i++) {
if(((f >> (i << 1)) & 3) == 1 && (((y >> i) & 1) == 0)) {
x |= (1ull << i);
}
}
printf("%llu\n", x);
}
break;
}
}
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 11ms
memory: 128596kb
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: -100
Wrong Answer
time: 0ms
memory: 128624kb
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 9201416980081139450
result:
wrong answer 4th lines differ - expected: '8795942500783873690', found: '9201416980081139450'