#include <stdint.h>
#include <sys/auxv.h>
#include <unistd.h>
#include <immintrin.h>
#pragma GCC target("avx2,bmi,bmi2")
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));
typedef unsigned __int128 u128;
#define FULL ((u128)-1)
#define NB 234496
#define N1 3664
#define N2 58
static u128 blk[NB];
static uint64_t fm1[N1], nm1[N1];
static uint64_t fm2[N2], nm2[N2];
static uint64_t fm3, nm3;
static uint64_t O;
static char *out;
/* ---------- tokenizer ---------- */
#define IBUF_SIZE (32*1024*1024)
#define MAXTOK (3000008)
static char ibuf[IBUF_SIZE + 64];
/* packed token: low 24 bits = start offset, high 8 bits = length */
static uint32_t tok_arr[MAXTOK];
static uint32_t val_arr[MAXTOK];
/* Pass A: SIMD scan -> packed (start|len<<24) tokens */
static inline uint32_t scan_tokens(const char *p, uint64_t size){
uint32_t cnt = 0;
int carry = 0;
uint32_t run_start = 0;
const __m256i zl = _mm256_set1_epi8('0' - 1);
uint64_t pos = 0;
for (; pos < size; pos += 32){
__m256i v = _mm256_loadu_si256((const __m256i*)(p + pos));
__m256i d = _mm256_cmpgt_epi8(v, zl);
uint32_t dm = (uint32_t)_mm256_movemask_epi8(d);
if (pos + 32 > size) dm &= (1u << (size - pos)) - 1;
if (carry){
int f0 = __builtin_ctz(~dm); /* first non-digit (dm != ~0 always here) */
tok_arr[cnt] = run_start | (((uint32_t)(pos - run_start) + (uint32_t)f0) << 24);
cnt++;
carry = 0;
dm &= ~((1u << (f0 + 1)) - 1);
}
if (dm & 0x80000000u){
int s_last = 32 - __builtin_clz(~dm);
run_start = (uint32_t)pos + (uint32_t)s_last;
carry = 1;
dm &= (1u << s_last) - 1;
}
uint32_t starts = dm & ~(dm << 1);
uint32_t ends = dm & ~(dm >> 1);
uint32_t st = starts, en = ends;
while (st){
int s = __builtin_ctz(st);
int e = __builtin_ctz(en);
tok_arr[cnt] = ((uint32_t)pos + (uint32_t)s) | ((uint32_t)(e - s + 1) << 24);
cnt++;
st &= st - 1;
en &= en - 1;
}
}
if (carry){
tok_arr[cnt] = run_start | ((uint32_t)(size - run_start) << 24);
cnt++;
}
return cnt;
}
static const int8_t sh[9][16] __attribute__((aligned(16))) = {
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{-128,-128,-128,-128,-128,-128,-128,0, -128,-128,-128,-128,-128,-128,-128,-128},
{-128,-128,-128,-128,-128,-128,0,1, -128,-128,-128,-128,-128,-128,-128,-128},
{-128,-128,-128,-128,-128,0,1,2, -128,-128,-128,-128,-128,-128,-128,-128},
{-128,-128,-128,-128,0,1,2,3, -128,-128,-128,-128,-128,-128,-128,-128},
{-128,-128,-128,0,1,2,3,4, -128,-128,-128,-128,-128,-128,-128,-128},
{-128,-128,0,1,2,3,4,5, -128,-128,-128,-128,-128,-128,-128,-128},
{-128,0,1,2,3,4,5,6, -128,-128,-128,-128,-128,-128,-128,-128},
{0,1,2,3,4,5,6,7, -128,-128,-128,-128,-128,-128,-128,-128},
};
static inline uint32_t conv8(const char *p, int L){
__m128i v = _mm_loadu_si128((const __m128i*)p);
__m128i d = _mm_sub_epi8(v, _mm_set1_epi8('0'));
__m128i a = _mm_shuffle_epi8(d, _mm_load_si128((const __m128i*)sh[L]));
__m128i m = _mm_maddubs_epi16(a, _mm_setr_epi8(10,1,10,1,10,1,10,1,10,1,10,1,10,1,10,1));
__m128i m2 = _mm_madd_epi16(m, _mm_setr_epi16(100,1,100,1,100,1,100,1));
__m128i m3 = _mm_mullo_epi32(m2, _mm_setr_epi32(10000,1,10000,1));
__m128i h = _mm_hadd_epi32(m3, m3);
return (uint32_t)_mm_cvtsi128_si32(h);
}
static inline void convert_all(const char *p, uint32_t cnt){
for (uint32_t i = 0; i < cnt; i++){
uint32_t tok = tok_arr[i];
uint32_t start = tok & 0xFFFFFFu;
int L = (int)(tok >> 24);
uint32_t v;
if (L > 8){
int h = p[start] - '0';
const char *lo = p + start + 1;
if (L == 10){ h = h*10 + (p[start+1]-'0'); lo = p + start + 2; }
v = (uint32_t)h * 100000000u + conv8(lo, 8);
} else if (L == 1){
v = (uint32_t)(p[start] - '0');
} else {
v = conv8(p + start, L);
}
if (start && p[start - 1] == '-') v = (uint32_t)(-(int32_t)v);
val_arr[i] = v;
}
}
__attribute__((noreturn)) static void done(uint64_t olen, struct DuckInfo *di, 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);
uint64_t size; const char *P; int use_di = 0;
if (di && di->abi_version >= 1 && di->stdin_ptr && di->stdout_ptr){
size = di->stdin_size; P = di->stdin_ptr; out = di->stdout_ptr; use_di = 1;
} else {
long n2 = 0, t;
while (n2 < IBUF_SIZE && (t = read(0, ibuf + n2, IBUF_SIZE - n2)) > 0) n2 += t;
size = (uint64_t)n2;
for (int j = 0; j < 64; j++) ibuf[n2 + j] = ' ';
P = ibuf;
static char obuf[1<<22]; out = obuf;
}
uint32_t cnt = scan_tokens(P, size);
convert_all(P, cnt);
int n = (int32_t)val_arr[0];
uint32_t idx = 4;
uint64_t acc = 0;
for (int i = 0; i < n; i++){
int op = (int32_t)val_arr[idx++];
if (op == 1){
int a = (int32_t)val_arr[idx++];
int b = (int32_t)val_arr[idx++];
acc += (uint64_t)(a < 0 ? -(int64_t)a : a) + (uint64_t)b;
} else {
int k = (int32_t)val_arr[idx++];
acc += (uint64_t)k;
out[O++] = (char)('0' + (acc & 1));
out[O++] = '\n';
}
}
done(O, di, use_di);
}
| Compilation | N/A | N/A | Compile OK | Score: N/A | 显示更多 |
| Testcase #1 | 6.21 us | 20 KB | Wrong Answer | Score: 0 | 显示更多 |
| Testcase #2 | 9.42 us | 20 KB | Wrong Answer | Score: 0 | 显示更多 |
| Testcase #3 | 56.81 us | 56 KB | Wrong Answer | Score: 0 | 显示更多 |
| Testcase #4 | 86.83 us | 96 KB | Wrong Answer | Score: 0 | 显示更多 |
| Testcase #5 | 106.87 us | 148 KB | Wrong Answer | Score: 0 | 显示更多 |
| Testcase #6 | 161.73 us | 192 KB | Wrong Answer | Score: 0 | 显示更多 |
| Testcase #7 | 206.19 us | 212 KB | Wrong Answer | Score: 0 | 显示更多 |
| Testcase #8 | 223.58 us | 236 KB | Wrong Answer | Score: 0 | 显示更多 |
| Testcase #9 | 657.46 us | 664 KB | Wrong Answer | Score: 0 | 显示更多 |
| Testcase #10 | 811.66 us | 1 MB + 96 KB | Wrong Answer | Score: 0 | 显示更多 |
| Testcase #11 | 1.274 ms | 1 MB + 292 KB | Wrong Answer | Score: 0 | 显示更多 |
| Testcase #12 | 1.263 ms | 1 MB + 400 KB | Wrong Answer | Score: 0 | 显示更多 |
| Testcase #13 | 1.507 ms | 1 MB + 508 KB | Wrong Answer | Score: 0 | 显示更多 |
| Testcase #14 | 4.294 ms | 4 MB + 252 KB | Wrong Answer | Score: 0 | 显示更多 |
| Testcase #15 | 5.948 ms | 6 MB + 368 KB | Wrong Answer | Score: 0 | 显示更多 |
| Testcase #16 | 8.697 ms | 8 MB + 488 KB | Wrong Answer | Score: 0 | 显示更多 |
| Testcase #17 | 10.786 ms | 10 MB + 600 KB | Wrong Answer | Score: 0 | 显示更多 |
| Testcase #18 | 13.047 ms | 12 MB + 724 KB | Wrong Answer | Score: 0 | 显示更多 |
| Testcase #19 | 15.173 ms | 14 MB + 836 KB | Wrong Answer | Score: 0 | 显示更多 |
| Testcase #20 | 16.474 ms | 16 MB + 36 KB | Wrong Answer | Score: 0 | 显示更多 |
| Testcase #21 | 18.264 ms | 19 MB + 44 KB | Wrong Answer | Score: 0 | 显示更多 |
| Testcase #22 | 20.185 ms | 19 MB + 700 KB | Wrong Answer | Score: 0 | 显示更多 |
| Testcase #23 | 15.676 ms | 20 MB + 632 KB | Wrong Answer | Score: 0 | 显示更多 |
| Testcase #24 | 21.474 ms | 20 MB + 964 KB | Wrong Answer | Score: 0 | 显示更多 |
| Testcase #25 | 21.584 ms | 21 MB + 200 KB | Wrong Answer | Score: 0 | 显示更多 |