// 压32bit,否则不好处理
#include <bits/stdc++.h>
#define fst first
#define snd second
using namespace std;
typedef int i32;
typedef long long i64;
typedef __int128 i128;
typedef unsigned u32;
typedef unsigned long long u64;
typedef unsigned __int128 u128;
const int MAXN = 1e6+2;
const u32 NONEMARK = 0x3f3f3f3fu;
const u32 FULL = 0xffffffffu;
int q;
u32 andv[(MAXN+10)<<2], orv[(MAXN+10)<<2], setv[(MAXN+10)<<2];
struct FastIO {
char bufin[1<<27], bufout[1<<24];
char *pin, *pout;
FastIO() {
fseek(stdin, 0, SEEK_END);
int len = ftell(stdin);
fseek(stdin, 0, SEEK_SET);
fread(bufin, sizeof(char), len, stdin);
pin = bufin; pout = bufout;
}
template<typename T>
inline void readint(T& x) {
T f=1, r=0;
while(!isdigit(*pin)) { if(*pin=='-')f=-1; pin++; }
while(isdigit(*pin)) { r=r*10+*pin-'0'; pin++; }
x = f*r;
}
template<typename T>
inline void writeint(T x) {
static char t[25], *pt; pt = t;
if(x<0) { *pout++ = '-'; x = -x; }
do {
*pt++ = x%10 + '0'; x /= 10;
} while(x);
pt--;
while(pt>=t) *pout++ = *pt--;
*pout++ = '\n';
}
~FastIO() {
fwrite(bufout, sizeof(char), pout - bufout, stdout);
}
} fio;
#define readint fio.readint
#define writeint fio.writeint
#define lc(o) ((o)<<1)
#define rc(o) ((o)<<1|1)
inline void maintain(int o, int l, int r) {
andv[o] = orv[o] = 0u;
if(l != r) {
andv[o] = andv[lc(o)] & andv[rc(o)];
orv[o] = orv[lc(o)] | orv[rc(o)];
}
if(setv[o] != NONEMARK) {
andv[o] = setv[o];
orv[o] = setv[o];
}
}
inline void pushdown(int o) {
if(setv[o] != NONEMARK) {
setv[lc(o)] = setv[o];
setv[rc(o)] = setv[o];
setv[o] = NONEMARK;
}
}
u32 getval(int o, int l, int r, int p) {
maintain(o, l, r);
if(l == r) return andv[o];
else {
int mid = (l + r) / 2;
pushdown(o);
if(p <= mid) {
maintain(rc(o), mid + 1, r);
return getval(lc(o), l, mid, p);
} else {
maintain(lc(o), l, mid);
return getval(rc(o), mid + 1, r, p);
}
}
}
void cover(int o, int l, int r, int ql, int qr, u32 val) {
if(ql <= l && r <= qr)
setv[o] = val;
else {
int mid = (l + r) / 2;
pushdown(o);
if(ql <= mid) cover(lc(o), l, mid, ql, qr, val);
else maintain(lc(o), l, mid);
if(qr >= mid + 1) cover(rc(o), mid + 1, r, ql, qr, val);
else maintain(rc(o), mid + 1, r);
}
maintain(o, l, r);
}
// find the end pointer of consecutive 1's
int end1(int o, int l, int r, int ql) {
maintain(o, l, r);
if(ql <= l) {
if(l == r) return andv[o] == FULL ? l : ql - 1;
if(andv[o] == FULL) return r;
else {
int mid = (l + r) / 2, ret = ql - 1;
pushdown(o);
maintain(lc(o), l, mid), maintain(rc(o), mid + 1, r);
if(andv[lc(o)] == FULL) {
ret = max(ret, mid);
ret = max(ret, end1(rc(o), mid + 1, r, ql));
} else {
ret = max(ret, end1(lc(o), l, mid, ql));
}
return ret;
}
} else {
int mid = (l + r) / 2, ret = ql - 1;
pushdown(o);
if(ql <= mid) ret = max(ret, end1(lc(o), l, mid, ql));
else maintain(lc(o), l, mid);
if(ql > mid || ret == mid)
ret = max(ret, end1(rc(o), mid + 1, r, ql));
else maintain(rc(o), mid + 1, r);
return ret;
}
}
// 0's
int end0(int o, int l, int r, int ql) {
maintain(o, l, r);
if(ql <= l) {
if(l == r) return orv[o] == 0u ? l : ql - 1;
if(orv[o] == 0u) return r;
else {
int mid = (l + r) / 2, ret = ql - 1;
pushdown(o);
maintain(lc(o), l, mid), maintain(rc(o), mid+1, r);
if(orv[lc(o)] == 0u) {
ret = max(ret, mid);
ret = max(ret, end0(rc(o), mid + 1, r, ql));
} else {
ret = max(ret, end0(lc(o), l, mid, ql));
}
return ret;
}
} else {
int mid = (l + r) / 2, ret = ql - 1;
pushdown(o);
if(ql <= mid) ret = max(ret, end0(lc(o), l, mid, ql));
else maintain(lc(o), l, mid);
if(ql > mid || ret == mid)
ret = max(ret, end0(rc(o), mid + 1, r, ql));
else maintain(rc(o), mid + 1, r);
return ret;
}
}
#undef lc
#undef rc
inline int get_bucket(int p) {
return (p >> 5) + 1;
}
inline int get_bit(int p) { // shl
return (p & 31);
}
inline void do_add(int x, int p) {
// consider compressing into a byte
// 01234567 01234567
// 00001001 11001000
// +100 00101
register int bucket = get_bucket(p), bit = get_bit(p);
register i128 cur; register u64 low, high;
low = getval(1, 1, MAXN, bucket);
high = getval(1, 1, MAXN, bucket+1);
cur = low | (high << 32);
cur += i128(x) << bit;
cover(1, 1, MAXN, bucket, bucket, cur & FULL);
cover(1, 1, MAXN, bucket+1, bucket+1, (cur >> 32) & FULL);
if(cur > ULLONG_MAX) { // overflow
int ql = bucket + 2, qr;
qr = end1(1, 1, MAXN, ql);
if(ql <= qr) cover(1, 1, MAXN, ql, qr, 0);
u32 t = getval(1, 1, MAXN, qr + 1);
register int i;
for(i = 0; ((t >> i) & 1) && i < 32; i++);
for(; ~i; --i) t ^= (1 << i);
cover(1, 1, MAXN, qr + 1, qr + 1, t);
} else if(cur < 0) { // underflow
int ql = bucket + 2, qr;
qr = end0(1, 1, MAXN, ql);
if(ql <= qr) cover(1, 1, MAXN, ql, qr, FULL);
u32 t = getval(1, 1, MAXN, qr + 1);
register int i;
for(i = 0; (not ((t >> i) & 1)) && i < 32; i++);
for(; ~i; --i) t ^= (1 << i);
cover(1, 1, MAXN, qr + 1, qr + 1, t);
}
}
inline int query_bit(int p) {
int bucket = get_bucket(p), bit = get_bit(p);
return (getval(1, 1, MAXN, bucket) >> bit) & 1;
}
int main() {
int t;
memset(setv, 0x3f, sizeof(setv));
readint(q);
for(int i = 1; i <= 3; i++)
readint(t);
while(q--) {
int op, a, b;
readint(op);
switch(op) {
case 1:
readint(a); readint(b);
do_add(a, b);
break;
case 2:
readint(a);
writeint(query_bit(a));
break;
}
}
return 0;
}
Compilation | N/A | N/A | Compile OK | Score: N/A | 显示更多 |
Testcase #1 | 1.325 ms | 15 MB + 404 KB | Accepted | Score: 4 | 显示更多 |
Testcase #2 | 1.364 ms | 15 MB + 404 KB | Accepted | Score: 4 | 显示更多 |
Testcase #3 | 2.104 ms | 15 MB + 424 KB | Accepted | Score: 4 | 显示更多 |
Testcase #4 | 2.753 ms | 15 MB + 440 KB | Accepted | Score: 4 | 显示更多 |
Testcase #5 | 7.188 ms | 15 MB + 496 KB | Accepted | Score: 4 | 显示更多 |
Testcase #6 | 6.681 ms | 15 MB + 484 KB | Accepted | Score: 4 | 显示更多 |
Testcase #7 | 10.068 ms | 15 MB + 704 KB | Accepted | Score: 4 | 显示更多 |
Testcase #8 | 9.949 ms | 15 MB + 560 KB | Accepted | Score: 4 | 显示更多 |
Testcase #9 | 31.669 ms | 16 MB + 368 KB | Accepted | Score: 4 | 显示更多 |
Testcase #10 | 56.459 ms | 17 MB + 4 KB | Accepted | Score: 4 | 显示更多 |
Testcase #11 | 53.622 ms | 16 MB + 348 KB | Accepted | Score: 4 | 显示更多 |
Testcase #12 | 52.11 ms | 17 MB + 132 KB | Accepted | Score: 4 | 显示更多 |
Testcase #13 | 74.279 ms | 17 MB + 656 KB | Accepted | Score: 4 | 显示更多 |
Testcase #14 | 211.854 ms | 21 MB + 816 KB | Accepted | Score: 4 | 显示更多 |
Testcase #15 | 253.739 ms | 23 MB + 552 KB | Accepted | Score: 4 | 显示更多 |
Testcase #16 | 443.968 ms | 28 MB + 448 KB | Accepted | Score: 4 | 显示更多 |
Testcase #17 | 464.941 ms | 23 MB + 664 KB | Accepted | Score: 4 | 显示更多 |
Testcase #18 | 692.404 ms | 35 MB + 36 KB | Accepted | Score: 4 | 显示更多 |
Testcase #19 | 799.722 ms | 38 MB + 340 KB | Accepted | Score: 4 | 显示更多 |
Testcase #20 | 450.886 ms | 37 MB + 720 KB | Accepted | Score: 4 | 显示更多 |
Testcase #21 | 818.679 ms | 40 MB + 108 KB | Accepted | Score: 4 | 显示更多 |
Testcase #22 | 874.705 ms | 31 MB + 272 KB | Accepted | Score: 4 | 显示更多 |
Testcase #23 | 1.2 s | 47 MB + 140 KB | Accepted | Score: 4 | 显示更多 |
Testcase #24 | 921.978 ms | 32 MB + 284 KB | Accepted | Score: 4 | 显示更多 |
Testcase #25 | 1.174 s | 48 MB + 212 KB | Accepted | Score: 4 | 显示更多 |