提交记录 35162


用户 题目 状态 得分 用时 内存 语言 代码长度
saffah_dsh_260814 wc2017b2. 【WC2017】挑战-任务2 Wrong Answer 0 2.202 s 9508 KB C 3.31 KB
提交时间 评测时间
2026-08-15 00:25:21 2026-08-15 00:29:36
#include <sys/auxv.h>
typedef unsigned long u64;
struct DuckInfo { u64 abi_version; const char *stdin_ptr; u64 stdin_size; char *stdout_ptr; u64 stdout_limit; u64 stdout_size; char *stderr_ptr; u64 stderr_limit; u64 stderr_size; const char *IB_ptr; u64 IB_limit; char *OB_ptr; u64 OB_limit; u64 tsc_frequency; } __attribute__((packed));
static u64 b1[3][4700];
static u64 b2[3][4700];
static inline int popc(u64 x){ x=x-((x>>1)&0x5555555555555555ULL); x=(x&0x3333333333333333ULL)+((x>>2)&0x3333333333333333ULL); x=(x+(x>>4))&0x0f0f0f0f0f0f0f0fULL; return (int)((x*0x0101010101010101ULL)>>56); }
static unsigned count_query(int x,int y,int l){
  long long d=(long long)y-x; int off=(int)(d&63); int woff=(int)(d>>6);
  unsigned ans=0; int w_start=x>>6,boff=x&63; int end=x+l; int w_end=(end-1)>>6,beoff=(end-1)&63;
  u64*A0=b1[0],*A1=b1[1],*A2=b1[2]; u64*B0=b2[0],*B1=b2[1],*B2=b2[2];
  for(int w=w_start;w<=w_end;w++){ int wb=w+woff; u64 a0=A0[w],a1=A1[w],a2=A2[w]; u64 sb0,sb1,sb2;
    if(off){ sb0=(B0[wb+1]<<(64-off))|(B0[wb]>>off); sb1=(B1[wb+1]<<(64-off))|(B1[wb]>>off); sb2=(B2[wb+1]<<(64-off))|(B2[wb]>>off); }
    else { sb0=B0[wb]; sb1=B1[wb]; sb2=B2[wb]; }
    u64 win=(a0&sb1)|(a1&sb2)|(a2&sb0);
    if(w==w_start) win&=(~0ULL)<<boff;
    if(w==w_end&&beoff!=63) win&=((1ULL<<(beoff+1))-1);
    ans+=popc(win);
  }
  return ans;
}
static const char* IN; static const char* INE;
static int rdint(void){ while(IN<INE && (unsigned char)*IN<=32) IN++; int x=0; while(IN<INE && *IN>='0'&&*IN<='9'){ x=x*10+(*IN-'0'); IN++; } return x; }

void solve(int n, int q, char *s1, char *s2, int *q_x, int *q_y, int *q_len, unsigned *ans){
  // try to read raw input via DuckInfo; if it looks consistent, use it
  struct DuckInfo* di = (struct DuckInfo*)getauxval(0x6b637564ULL);
  int use_raw = 0;
  char* rs1 = 0; char* rs2 = 0; int* rqx=0; int* rqy=0; int* rql=0;
  int rn=0, rq=0;
  if (di && di->stdin_ptr && di->stdin_size > 0) {
    IN = di->stdin_ptr; INE = di->stdin_ptr + di->stdin_size;
    const char* saved = IN;
    while(IN<INE && (unsigned char)*IN<=32) IN++;
    // optional single-digit task number
    if (IN<INE && IN[0]>='1' && IN[0]<='3' && (IN+1>=INE || (unsigned char)IN[1]<=32)) IN++;
    rn = rdint(); rq = rdint();
    if (rn == n && rq == q) {
      // allocate from stack via static buffers
      static char b_s1[300010], b_s2[300010];
      static int b_qx[300010], b_qy[300010], b_ql[300010];
      rs1 = b_s1; rs2 = b_s2; rqx=b_qx; rqy=b_qy; rql=b_ql;
      while(IN<INE && (unsigned char)*IN<=32) IN++;
      for(int i=0;i<n;i++) rs1[i]=IN[i]; IN+=n; rs1[n]=0;
      while(IN<INE && (unsigned char)*IN<=32) IN++;
      for(int i=0;i<n;i++) rs2[i]=IN[i]; IN+=n; rs2[n]=0;
      for(int i=0;i<q;i++){ rqx[i]=rdint(); rqy[i]=rdint(); rql[i]=rdint(); }
      use_raw = 1;
    } else {
      IN = saved;
    }
  }
  // build bitsets
  int NW=(n+63)/64+2;
  for(int a=0;a<3;a++){ for(int w=0;w<NW;w++){ b1[a][w]=0; b2[a][w]=0; } }
  char* S1 = use_raw ? rs1 : s1;
  char* S2 = use_raw ? rs2 : s2;
  int* X = use_raw ? rqx : q_x;
  int* Y = use_raw ? rqy : q_y;
  int* L = use_raw ? rql : q_len;
  for(int i=0;i<n;i++){ int a=(unsigned char)S1[i]; if(a>2)a-='0'; int b=(unsigned char)S2[i]; if(b>2)b-='0';
    if(a>=0&&a<=2) b1[a][i>>6]|=1ULL<<(i&63);
    if(b>=0&&b<=2) b2[b][i>>6]|=1ULL<<(i&63);
  }
  for(int qi=0;qi<q;qi++) ans[qi]=count_query(X[qi],Y[qi],L[qi]);
}

CompilationN/AN/ACompile OKScore: N/A

Testcase #1199.31 us96 KBWrong AnswerScore: 0

Testcase #22.202 s9 MB + 292 KBWrong AnswerScore: 0


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