QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#831984#6842. Popcount WordsWilliamxzhWA 489ms366156kbC++232.2kb2024-12-25 18:26:012024-12-25 18:26:06

Judging History

你现在查看的是最新测评结果

  • [2024-12-25 18:26:06]
  • 评测
  • 测评结果:WA
  • 用时:489ms
  • 内存:366156kb
  • [2024-12-25 18:26:01]
  • 提交

answer

#include <bits/stdc++.h>
#define il inline
#define pii pair<int,int>
#define fi first
#define se second
using namespace std;
typedef long long ll;
il int pc(int x){
    int s=0;
    while(x) ++s,x-=(x&-x);
    return s;
}
const int N=1e5+5,M=3e6+5,K=5e5+5;
int n,m,k,pos[N],cnt,t[K][2];pii a[N];char s[K];
il void add(int id){
    int len=strlen(s+1),x=0,c;
    for(int i=1;i<=len;++i){
        c=s[i]-'0';if(!t[x][c]) t[x][c]=++cnt;
        x=t[x][c];
    }pos[id]=x;
}
vector<int> e[K];
int q[K],hh,tt,nxt[K],to[K][30][2];ll sum[N],g[K][30][2];
il void build(){
    int x,y,z,u,v,w;hh=1,tt=0;
    for(int i=0;i<2;++i) if(t[0][i]) q[++tt]=t[0][i];
    while(hh<=tt){
        x=q[hh++],e[nxt[x]].push_back(x);//printf("%d\n",x);
        for(int i=0;i<2;++i){
            if(t[x][i]) nxt[t[x][i]]=t[nxt[x]][i],q[++tt]=t[x][i];
            else t[x][i]=t[nxt[x]][i];
        }
    }
    for(int i=0;i<=cnt;++i) for(int c=0;c<2;++c) to[i][0][c]=t[i][c];
    for(int j=1;j<30;++j)
        for(int i=0;i<=cnt;++i)
            for(int c=0;c<2;++c)
                to[i][j][c]=to[to[i][j-1][c]][j-1][!c];
}
void dfs(int x){
    //printf("*** %d\n",x);
    for(int y:e[x]) dfs(y),sum[x]+=sum[y];
}
il void query(){
    int x=0,c,y,z,u,v,w,l,r;
    for(int i=1;i<=n;++i){
        l=a[i].fi,r=a[i].se;
        y=l;
        //printf("%d %d : ",l,r);
        while(y<=r){
            z=(1<<(int(log2(r-y+1)))),z=min(z,(y&-y)),w=log2(z),c=(pc(y)&1);
            ++g[x][w][c],x=to[x][w][c],y+=z;
            //printf("%d %d\n",x,w); 
        }//puts("");
    }
    for(int j=29;j;--j)
        for(int i=0;i<=cnt;++i)
            for(int c=0;c<2;++c){
                g[i][j-1][c]+=g[i][j][c];
                g[to[i][j-1][c]][j-1][!c]+=g[i][j][c];
            }
    for(int i=0;i<=cnt;++i) sum[t[i][0]]+=g[i][0][0],sum[t[i][1]]+=g[i][0][1];
}
int l,r,x,y,z,u,v,w;
int main(){
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;++i) scanf("%d%d",&a[i].fi,&a[i].se);
    for(int i=1;i<=m;++i){
        scanf("%s",s+1);
        add(i);
    }
    build();query();
    dfs(0);
    for(int i=1;i<=m;++i) printf("%lld\n",sum[pos[i]]);
    return 0;
}
/*
4 1
40 1
5 0
3 0
4 1
7 2
8 0
*/

詳細信息

Test #1:

score: 100
Accepted
time: 2ms
memory: 10040kb

input:

3 5
2 6
1 3
4 8
0
1
11
101
0011010

output:

6
7
2
2
1

result:

ok 5 lines

Test #2:

score: 0
Accepted
time: 2ms
memory: 12248kb

input:

3 10
2 6
1 3
4 8
0
1
11
101
0011010
0
1
11
101
0011010

output:

6
7
2
2
1
6
7
2
2
1

result:

ok 10 lines

Test #3:

score: 0
Accepted
time: 37ms
memory: 41708kb

input:

100000 37701
605224571 605224571
681034454 681034463
468837041 468837048
323235128 323235135
400367345 400367345
394938241 394938241
221026001 221026007
183872918 183872926
881878131 881878138
374491962 374491967
588030380 588030381
109143398 109143401
727016146 727016149
857189138 857189138
1940312...

output:

273828
273405
99633
174195
174195
99209
16229
83404
91124
83071
83404
90791
83070
16138
3449
12780
43045
40359
43221
47903
70380
12690
12780
70624
48079
42712
40183
42887
12690
3448
413
3036
6576
6204
11678
31367
34167
6191
6484
36737
16633
31270
33957
36423
9697
2993
3036
9744
36469
34155
31543
165...

result:

ok 37701 lines

Test #4:

score: -100
Wrong Answer
time: 489ms
memory: 366156kb

input:

100000 2064
155864032 155864033
351106162 351106162
63569309 63569310
446198383 446198387
844050143 844050148
28666643 28666652
948049121 948049128
422938918 422938925
590576664 590576664
118827333 118827339
248813547 248813549
222041903 222041911
481862624 481862626
39190429 39190429
373420004 3734...

output:

-3766200640553577267
-3936874493426618162
6963237716139968168
7717305717016006180
7546876406766607535
6962993173516325919
4209977118316179745
2753260597823788423
4894179032260942702
2823126684755063478
2846561297642779909
4700315109123827625
2800883654711602405
4162109518804723514
880045877269829148...

result:

wrong answer 1st lines differ - expected: '274777', found: '-3766200640553577267'