#include <stdint.h>
#include <sys/auxv.h>
#include <unistd.h>
struct DuckInfo {
uint64_t abi_version;
const char *stdin_ptr; uint64_t stdin_size;
char *stdout_ptr; uint64_t stdout_limit; uint64_t stdout_size;
char *stderr_ptr; uint64_t stderr_limit; uint64_t stderr_size;
const char *IB_ptr; uint64_t IB_limit;
char *OB_ptr; uint64_t OB_limit;
uint64_t tsc_frequency;
} __attribute__((packed));
#define SZ (1<<20)
#define MASK 0x3FFFFFFFu
static uint32_t limb[SZ];
static uint8_t st[2*SZ]; /* 0 = all-zero, 1 = all-full, 2 = mixed */
static const char *P;
static uint64_t O;
static inline uint8_t comb(uint8_t a, uint8_t b){ return (a == b) ? a : 2; }
static inline void push_path(int idx){
int anc[20];
int na = 0;
for (int x = idx >> 1; x >= 1; x >>= 1) anc[na++] = x;
for (int i = na - 1; i >= 0; i--){
int node = anc[i];
uint8_t s = st[node];
if (s != 2){ st[node<<1] = s; st[node<<1|1] = s; }
}
}
static inline int padd(int q, uint32_t v){
int node = 1;
for (int i = 19; i >= 0; i--){
uint8_t s = st[node];
if (s != 2){ st[node<<1] = s; st[node<<1|1] = s; }
node = (node << 1) | ((q >> i) & 1);
}
int idx = node;
uint8_t ls = st[idx];
uint32_t cur = (ls == 0) ? 0u : (ls == 1) ? MASK : limb[q];
uint32_t nv = cur + v;
int carry = nv >> 30;
uint32_t n30 = nv & MASK;
limb[q] = n30;
st[idx] = (n30 == 0) ? 0 : (n30 == MASK) ? 1 : 2;
for (int node = idx >> 1; node >= 1; node >>= 1){
uint8_t a = st[node<<1], b = st[node<<1|1];
uint8_t c = (a == b) ? a : 2;
if (c == st[node]) break;
st[node] = c;
}
return carry;
}
static inline int psub(int q, uint32_t v){
int node = 1;
for (int i = 19; i >= 0; i--){
uint8_t s = st[node];
if (s != 2){ st[node<<1] = s; st[node<<1|1] = s; }
node = (node << 1) | ((q >> i) & 1);
}
int idx = node;
uint8_t ls = st[idx];
uint32_t cur = (ls == 0) ? 0u : (ls == 1) ? MASK : limb[q];
int32_t nv = (int32_t)cur - (int32_t)v;
int borrow = nv < 0;
uint32_t res = borrow ? (uint32_t)(nv + (1<<30)) : (uint32_t)nv;
limb[q] = res;
st[idx] = (res == 0) ? 0 : (res == MASK) ? 1 : 2;
for (int node = idx >> 1; node >= 1; node >>= 1){
uint8_t a = st[node<<1], b = st[node<<1|1];
uint8_t c = (a == b) ? a : 2;
if (c == st[node]) break;
st[node] = c;
}
return borrow;
}
/* ---- eager find (no lazy) ---- */
static inline int find_nonfull_eager(int j){
if (st[SZ+j] != 1) return j; /* O(1) common case */
int stk[21]; int top = 0;
int node = 1, nl = 0, nr = SZ;
while (nr - nl > 1){
int mid = (nl + nr) >> 1;
if (j < mid){ stk[top++] = (node<<1)|1; node <<= 1; nr = mid; }
else { node = (node<<1)|1; nl = mid; }
}
while (top > 0){
int c = stk[--top];
if (st[c] == 1) continue;
int cn = c;
while (cn < SZ){
if (st[cn<<1] != 1) cn <<= 1; else cn = (cn<<1)|1;
}
return cn - SZ;
}
return SZ;
}
static inline int find_nonzero_eager(int j){
if (st[SZ+j] != 0) return j;
int stk[21]; int top = 0;
int node = 1, nl = 0, nr = SZ;
while (nr - nl > 1){
int mid = (nl + nr) >> 1;
if (j < mid){ stk[top++] = (node<<1)|1; node <<= 1; nr = mid; }
else { node = (node<<1)|1; nl = mid; }
}
while (top > 0){
int c = stk[--top];
if (st[c] == 0) continue;
int cn = c;
while (cn < SZ){
if (st[cn<<1] != 0) cn <<= 1; else cn = (cn<<1)|1;
}
return cn - SZ;
}
return SZ;
}
/* ---- lazy find (recursive, correct under lazy nodes) ---- */
static int find_nf_rec(int node, int nl, int nr, int j){
if (nr <= j) return -1;
uint8_t s = st[node];
if (s == 1) return -1;
if (nr - nl == 1) return nl;
if (s == 0) return (j > nl) ? j : nl;
int mid = (nl + nr) >> 1;
int r = find_nf_rec(node<<1, nl, mid, j);
if (r != -1) return r;
return find_nf_rec(node<<1|1, mid, nr, j);
}
static int find_nz_rec(int node, int nl, int nr, int j){
if (nr <= j) return -1;
uint8_t s = st[node];
if (s == 0) return -1;
if (nr - nl == 1) return nl;
if (s == 1) return (j > nl) ? j : nl;
int mid = (nl + nr) >> 1;
int r = find_nz_rec(node<<1, nl, mid, j);
if (r != -1) return r;
return find_nz_rec(node<<1|1, mid, nr, j);
}
static void range_zero(int node, int nl, int nr, int l, int r){
if (nr <= l || r <= nl) return;
if (l <= nl && nr <= r){ st[node] = 0; return; }
uint8_t s = st[node];
if (s != 2){ st[node<<1] = s; st[node<<1|1] = s; }
int mid = (nl + nr) >> 1;
range_zero(node<<1, nl, mid, l, r);
range_zero(node<<1|1, mid, nr, l, r);
st[node] = comb(st[node<<1], st[node<<1|1]);
}
static void range_full(int node, int nl, int nr, int l, int r){
if (nr <= l || r <= nl) return;
if (l <= nl && nr <= r){ st[node] = 1; return; }
uint8_t s = st[node];
if (s != 2){ st[node<<1] = s; st[node<<1|1] = s; }
int mid = (nl + nr) >> 1;
range_full(node<<1, nl, mid, l, r);
range_full(node<<1|1, mid, nr, l, r);
st[node] = comb(st[node<<1], st[node<<1|1]);
}
static inline void add_val(int q, int r, uint32_t a){
uint32_t lo = (uint32_t)((uint64_t)a << r) & MASK;
uint32_t hi = (r == 0) ? 0u : (uint32_t)(a >> (30 - r));
int c0 = padd(q, lo);
int c1 = padd(q + 1, hi + c0);
if (c1){
int start = q + 2;
int p = find_nf_rec(1, 0, SZ, start);
if (p > start) range_zero(1, 0, SZ, start, p);
padd(p, 1);
}
}
static inline void sub_val(int q, int r, uint32_t a){
uint32_t lo = (uint32_t)((uint64_t)a << r) & MASK;
uint32_t hi = (r == 0) ? 0u : (uint32_t)(a >> (30 - r));
int b0 = psub(q, lo);
int b1 = psub(q + 1, hi + b0);
if (b1){
int start = q + 2;
int p = find_nz_rec(1, 0, SZ, start);
if (p > start) range_full(1, 0, SZ, start, p);
psub(p, 1);
}
}
static inline uint32_t read_limb(int q){
int node = 1, nl = 0, nr = SZ;
while (nr - nl > 1){
uint8_t s = st[node];
if (s == 0) return 0;
if (s == 1) return MASK;
int mid = (nl + nr) >> 1;
if (q < mid){ node = node<<1; nr = mid; }
else { node = node<<1|1; nl = mid; }
}
uint8_t s = st[node];
if (s == 0) return 0;
if (s == 1) return MASK;
return limb[q];
}
/* ---- parse ---- */
static inline int rd(){
while (*P <= ' ') P++;
int v = 0;
while (*P > ' ') v = v*10 + (*P - '0'), P++;
return v;
}
__attribute__((noreturn)) static void done(uint64_t olen, struct DuckInfo *di, char *out, int use_di){
if (use_di) di->stdout_size = olen;
else (void)!write(1, out, olen);
asm volatile("mov $60, %%eax; xor %%edi, %%edi; syscall" ::: "rax","rdi","memory");
__builtin_unreachable();
}
int main(){
struct DuckInfo *di = (struct DuckInfo*)getauxval(0x6b637564);
static char lbuf[1<<24];
static char obuf[1<<22];
char *out;
int use_di = 0;
if (di && di->abi_version >= 1 && di->stdin_ptr && di->stdout_ptr){
P = di->stdin_ptr;
out = di->stdout_ptr;
use_di = 1;
} else {
long n2 = 0, t;
while (n2 < (long)sizeof(lbuf) && (t = read(0, lbuf + n2, sizeof(lbuf) - n2)) > 0) n2 += t;
lbuf[n2] = 0;
P = lbuf;
out = obuf;
}
int n = rd();
rd(); rd(); rd();
P++;
for (int i = 0; i < n; i++){
int op = *P++ - '0';
P++;
if (op == 1){
int neg = 0;
if (*P == '-'){ neg = 1; P++; }
int a = 0;
while (*P > ' '){ a = a*10 + (*P - '0'); P++; }
P++;
int b = 0;
while (*P > ' '){ b = b*10 + (*P - '0'); P++; }
P++;
int q = b / 30;
int r = b % 30;
if (neg) sub_val(q, r, (uint32_t)a);
else if (a) add_val(q, r, (uint32_t)a);
} else {
int k = 0;
while (*P > ' '){ k = k*10 + (*P - '0'); P++; }
P++;
int q = k / 30;
int r = k % 30;
uint32_t v = read_limb(q);
out[O++] = (char)('0' + ((v >> r) & 1));
out[O++] = '\n';
}
}
done(O, di, out, use_di);
}
| Compilation | N/A | N/A | Compile OK | Score: N/A | 显示更多 |
| Testcase #1 | 8.96 us | 56 KB | Accepted | Score: 4 | 显示更多 |
| Testcase #2 | 16.25 us | 56 KB | Accepted | Score: 4 | 显示更多 |
| Testcase #3 | 137.78 us | 56 KB | Accepted | Score: 4 | 显示更多 |
| Testcase #4 | 254.16 us | 56 KB | Accepted | Score: 4 | 显示更多 |
| Testcase #5 | 1.476 ms | 56 KB | Accepted | Score: 4 | 显示更多 |
| Testcase #6 | 1.008 ms | 60 KB | Accepted | Score: 4 | 显示更多 |
| Testcase #7 | 2.526 ms | 104 KB | Accepted | Score: 4 | 显示更多 |
| Testcase #8 | 2.129 ms | 60 KB | Accepted | Score: 4 | 显示更多 |
| Testcase #9 | 8.627 ms | 232 KB | Accepted | Score: 4 | 显示更多 |
| Testcase #10 | 16.223 ms | 164 KB | Accepted | Score: 4 | 显示更多 |
| Testcase #11 | 13.603 ms | 96 KB | Accepted | Score: 4 | 显示更多 |
| Testcase #12 | 11.597 ms | 460 KB | Accepted | Score: 4 | 显示更多 |
| Testcase #13 | 20.775 ms | 496 KB | Accepted | Score: 4 | 显示更多 |
| Testcase #14 | 60.555 ms | 1 MB + 304 KB | Accepted | Score: 4 | 显示更多 |
| Testcase #15 | 55.857 ms | 1 MB + 952 KB | Accepted | Score: 4 | 显示更多 |
| Testcase #16 | 123.848 ms | 2 MB + 568 KB | Accepted | Score: 4 | 显示更多 |
| Testcase #17 | 133.236 ms | 444 KB | Accepted | Score: 4 | 显示更多 |
| Testcase #18 | 193.88 ms | 3 MB + 836 KB | Accepted | Score: 4 | 显示更多 |
| Testcase #19 | 236.454 ms | 4 MB + 452 KB | Accepted | Score: 4 | 显示更多 |
| Testcase #20 | 72.846 ms | 5 MB + 384 KB | Accepted | Score: 4 | 显示更多 |
| Testcase #21 | 181.843 ms | 5 MB + 712 KB | Accepted | Score: 4 | 显示更多 |
| Testcase #22 | 247.962 ms | 772 KB | Accepted | Score: 4 | 显示更多 |
| Testcase #23 | 331.877 ms | 1 MB + 664 KB | Accepted | Score: 4 | 显示更多 |
| Testcase #24 | 265.87 ms | 832 KB | Accepted | Score: 4 | 显示更多 |
| Testcase #25 | 346.217 ms | 6 MB + 340 KB | Accepted | Score: 4 | 显示更多 |