#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];
static uint32_t val_arr[MAXTOK];
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 uint32_t conv8f(const char *p){
__m128i v = _mm_loadu_si128((const __m128i*)p);
__m128i d = _mm_sub_epi8(v, _mm_set1_epi8('0'));
__m128i m = _mm_maddubs_epi16(d, _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 emit(const char *p, uint32_t *cnt, uint32_t start, int L){
uint32_t v;
if (L == 1){
v = (uint32_t)(p[start] - '0');
} else if (L == 8){
v = conv8f(p + start);
} else 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 + conv8f(lo);
} else {
v = conv8(p + start, L);
}
if (start && p[start - 1] == '-') v = (uint32_t)(-(int32_t)v);
val_arr[(*cnt)++] = v;
}
/* fused: SIMD scan + convert in one pass */
static inline uint32_t parse_all(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);
emit(p, &cnt, run_start, (int)((uint32_t)(pos - run_start) + (uint32_t)f0));
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);
emit(p, &cnt, (uint32_t)pos + (uint32_t)s, e - s + 1);
st &= st - 1;
en &= en - 1;
}
}
if (carry){
emit(p, &cnt, run_start, (int)(size - run_start));
}
return cnt;
}
__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 = parse_all(P, size);
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 | 7.56 us | 16 KB | Wrong Answer | Score: 0 | 显示更多 |
| Testcase #2 | 9.19 us | 16 KB | Wrong Answer | Score: 0 | 显示更多 |
| Testcase #3 | 56.03 us | 32 KB | Wrong Answer | Score: 0 | 显示更多 |
| Testcase #4 | 79.44 us | 52 KB | Wrong Answer | Score: 0 | 显示更多 |
| Testcase #5 | 96.02 us | 80 KB | Wrong Answer | Score: 0 | 显示更多 |
| Testcase #6 | 148.37 us | 104 KB | Wrong Answer | Score: 0 | 显示更多 |
| Testcase #7 | 189.37 us | 112 KB | Wrong Answer | Score: 0 | 显示更多 |
| Testcase #8 | 201.92 us | 124 KB | Wrong Answer | Score: 0 | 显示更多 |
| Testcase #9 | 575 us | 344 KB | Wrong Answer | Score: 0 | 显示更多 |
| Testcase #10 | 692.55 us | 576 KB | Wrong Answer | Score: 0 | 显示更多 |
| Testcase #11 | 1.119 ms | 680 KB | Wrong Answer | Score: 0 | 显示更多 |
| Testcase #12 | 1.095 ms | 736 KB | Wrong Answer | Score: 0 | 显示更多 |
| Testcase #13 | 1.316 ms | 792 KB | Wrong Answer | Score: 0 | 显示更多 |
| Testcase #14 | 3.712 ms | 2 MB + 188 KB | Wrong Answer | Score: 0 | 显示更多 |
| Testcase #15 | 5.035 ms | 3 MB + 276 KB | Wrong Answer | Score: 0 | 显示更多 |
| Testcase #16 | 7.731 ms | 4 MB + 368 KB | Wrong Answer | Score: 0 | 显示更多 |
| Testcase #17 | 9.269 ms | 5 MB + 452 KB | Wrong Answer | Score: 0 | 显示更多 |
| Testcase #18 | 11.904 ms | 6 MB + 544 KB | Wrong Answer | Score: 0 | 显示更多 |
| Testcase #19 | 13.888 ms | 7 MB + 632 KB | Wrong Answer | Score: 0 | 显示更多 |
| Testcase #20 | 16.142 ms | 8 MB + 412 KB | Wrong Answer | Score: 0 | 显示更多 |
| Testcase #21 | 16.53 ms | 9 MB + 808 KB | Wrong Answer | Score: 0 | 显示更多 |
| Testcase #22 | 17.244 ms | 10 MB + 120 KB | Wrong Answer | Score: 0 | 显示更多 |
| Testcase #23 | 13.897 ms | 10 MB + 556 KB | Wrong Answer | Score: 0 | 显示更多 |
| Testcase #24 | 18.313 ms | 10 MB + 780 KB | Wrong Answer | Score: 0 | 显示更多 |
| Testcase #25 | 19.705 ms | 10 MB + 892 KB | Wrong Answer | Score: 0 | 显示更多 |