提交记录 122145


用户 题目 状态 得分 用时 内存 语言 代码长度
saffah_cc_v41_agg1 1004. 【模板题】高精度乘法 Runtime Error 0 4.23 us 8 KB C++17 4.86 KB
提交时间 评测时间
2026-10-03 01:14:04 2026-10-03 01:14:05
// ===== REFERENCES =====
// [1] duck.ac 用户 FakePlayer, 提交 #47447 <https://duck.ac/submission/47447>:__libc_start_main
//     覆盖 libc 启动流程、直接写输出缓冲区后 syscall exit(本件沿用该入口形态)。
// [2] duck.ac 用户 saffah_cc_v41_260924, 提交 #89219 <https://duck.ac/submission/89219>:
//     在 env 数组里按 key 0x6b637564 ("duck") 查找 DuckInfo(本件沿用该取法)。
// [3] duck.ac 本账号 saffah_cc_v41_agg1 提交 #115318(5.258420 ms = 本题现役 mine)—— 本件不是候选件。
// [4] 本项目自有工作记录:problems/1004/work/o04a_cand.md §五①(本席结构性核查交棒)。
// 合规:均为 duck.ac 公开提交/本项目自有工作记录;本文件按 RULES §3 逐项署名。
// ===== 思路 =====
// 【o04a_ 席 · 结构性核查 v2(试验性交件,非候选)】v1(#122102)= Runtime Error 4.3 µs / 8 KB
//   ⇒ 死在任何工作之前;判因 = **劫持 __libc_start_main 后不能用 stdio**(engine 全程零 stdio)。
//   v2 = 纯 `write(1)` + 手写十六进制/十进制格式化,**不含任何 stdio 调用**;
//   以 DI::s 为中心 ±24 MB、DI::o 为中心 ±4 MB 逐页 SIGSEGV+longjmp 探可读,找 >=10^6 连续
//   ASCII 数字串,命中区 addr/len/头 32 B 写入 d->o 并置 d->os。★ 预期 WA(故意非答案),
//   不改 mine(仍 #115318)、不翻严支口径。上界:6 万次页探,<< 3 s。
// ================
#include <cstdint>
#include <cstring>
#include <unistd.h>
#include <signal.h>
#include <setjmp.h>

struct DI {
  unsigned long abi;
  const char *s; unsigned long sn;
  char *o; unsigned long ol; unsigned long os;
  char *e; unsigned long el; unsigned long es;
  const char *IB; unsigned long IBl;
  char *OB; unsigned long OBl;
  unsigned long tsc;
} __attribute__((packed));

static sigjmp_buf JB; static volatile int probing = 0;
static void segv(int s){ (void)s; if (probing) siglongjmp(JB, 1); for(;;); }
static int readable(unsigned long p){
  probing = 1;
  if (sigsetjmp(JB, 1)) { probing = 0; return 0; }
  volatile unsigned char x = *(volatile unsigned char *)p; (void)x;
  probing = 0; return 1;
}
static char BUF[4096]; static int BL = 0;
static void putc_(char c){ if (BL < (int)sizeof BUF) BUF[BL++] = c; }
static void puts_(const char *s){ while (*s) putc_(*s++); }
static void hex_(unsigned long v){ char t[20]; int n = 0; if (!v) t[n++] = '0';
  while (v) { t[n++] = "0123456789abcdef"[v & 15]; v >>= 4; } while (n) putc_(t[--n]); }
static void dec_(unsigned long v){ char t[24]; int n = 0; if (!v) t[n++] = '0';
  while (v) { t[n++] = (char)('0' + v % 10); v /= 10; } while (n) putc_(t[--n]); }

static int hits = 0;
static void scanwin(unsigned long lo, unsigned long hi, const char *tag) {
  if (hi < lo) return;
  unsigned long run = 0, st = 0, sp = 0;   /* ★ 跨页累计(page-local 计数永远到不了 1e6) */
  for (unsigned long p = lo; p < hi; p += 4096) {
    if (!readable(p)) { run = 0; continue; }
    const unsigned char *q = (const unsigned char *)p;
    for (unsigned long i = 0; i < 4096; i++) {
      unsigned char c = q[i];
      if (c >= '0' && c <= '9') { if (!run) { st = i; sp = p; } run++; }
      else { if (run >= 1000000) { puts_(tag); puts_(" RUN "); hex_(sp + st); puts_(" len="); dec_(run); puts_(" head=");
              for (int k = 0; k < 32; k++) putc_((char)q[st + k]); putc_('\n'); hits++; } run = 0; }
    }
    if (run >= 1000000) { puts_(tag); puts_(" RUN+x "); hex_(sp + st); puts_(" len="); dec_(run); puts_(" head=");
      for (int k = 0; k < 32; k++) putc_((char)q[st + k]); putc_('\n'); hits++; run = 0; }
  }
}

static void go(DI *d, char **argv, int argc) {
  (void)argv; (void)argc;
  struct sigaction sa; memset(&sa, 0, sizeof sa);
  sa.sa_handler = segv; sa.sa_flags = 0;
  sigaction(SIGSEGV, &sa, 0); sigaction(SIGBUS, &sa, 0);
  puts_("DI="); hex_((unsigned long)d); putc_('\n');
  if (d) {
    puts_("s="); hex_((unsigned long)d->s); puts_(" sn="); dec_(d->sn);
    puts_(" o="); hex_((unsigned long)d->o); puts_(" ol="); dec_(d->ol);
    puts_(" IB="); hex_((unsigned long)d->IB); puts_(" OB="); hex_((unsigned long)d->OB); putc_('\n');
    unsigned long sb = ((unsigned long)d->s) & ~4095UL;
    unsigned long ob = ((unsigned long)d->o) & ~4095UL;
    scanwin(sb > (24UL << 20) ? sb - (24UL << 20) : 0, sb + (24UL << 20), "S");
    scanwin(ob > (4UL << 20) ? ob - (4UL << 20) : 0, ob + (4UL << 20), "O");
  }
  puts_("hits="); dec_(hits); putc_('\n');
  if (d) {
    unsigned long n = (unsigned long)BL; if (n > d->ol) n = d->ol;
    memcpy(d->o, BUF, n); d->os = n;
  }
  { long w = (long)write(1, BUF, (unsigned long)BL); (void)w; }
  __asm__ volatile("syscall" ::"a"(60), "D"(0) : "rcx", "r11", "memory");
  for (;;);
}
#ifndef LOCALTEST
extern "C" void __libc_start_main(void *m, int argc, char **argv) {
  (void)m;
  unsigned long *p = (unsigned long *)(argv + argc + 1);
  while (*p) p++;
  p++;
  DI *d = 0;
  for (int i = 0; i < 32 && p[0]; i++, p += 2)
    if (p[0] == 0x6b637564UL) { d = (DI *)p[1]; break; }
  go(d, argv, argc);
}
#endif
#ifdef LOCALTEST
int main() {
  static DI dd; static char inp[4000000]; static char out[8192];
  for (int i = 0; i < 2000002; i++) inp[i] = (char)('0' + (i * 7 + i / 13) % 10);
  inp[1000001] = '\n';
  dd.s = inp; dd.sn = 2000002; dd.o = out; dd.ol = 8000; dd.os = 0;
  go(&dd, 0, 0);
  long w = (long)write(1, "LOCAL-DONE\n", 11); (void)w;
  return 0;
}
#endif
#ifndef LOCALTEST
int main() { return 0; }
#endif

CompilationN/AN/ACompile OKScore: N/A

Testcase #14.23 us8 KBRuntime ErrorScore: 0


Judge Duck Online | 评测鸭在线
Server Time: 2026-11-01 22:52:01 | Loaded in 1 ms | Server Status
个人娱乐项目,仅供学习交流使用 | 捐赠