QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#393089 | #6842. Popcount Words | cqbzdj | WA | 514ms | 386360kb | C++14 | 3.3kb | 2024-04-18 09:22:44 | 2024-04-18 09:22:44 |
Judging History
answer
#include <bits/stdc++.h>
#define LL long long
#define mes(s, x) memset(s, x, sizeof(s))
#define Maxn 100005
#define Maxl 500005
using namespace std;
inline LL read(){char c;c = getchar();while(!(('0' <= c && c <= '9') || c == '-')) c = getchar();bool flag = 0;if(c == '-'){flag = 1;c = getchar();}LL tot = 0;while('0' <= c && c <= '9'){tot = 10 * tot + c - '0';c = getchar();}return flag ? -tot : tot;}
int L[Maxn], R[Maxn];
char s[Maxn];
int id[Maxn], tr[Maxl][2], nxt[Maxl][30][2], cnt, fail[Maxl], px;
LL x[Maxl][30][2], ans[Maxl];
vector<int> g[Maxl];
void insert(int l, int x){
int p = 0, c;
for(int i = 1; i <= l; i++){
c = s[i] - '0';
if(!tr[p][c]) tr[p][c] = ++cnt;
p = tr[p][c];
}
id[x] = p;
}
void build(){
queue<int> q;
for(int i = 0; i < 2; i++) if(tr[0][i]) q.push(tr[0][i]);
int x;
while(q.size()){
x = q.front();
q.pop();
g[fail[x]].push_back(x);
for(int i = 0; i < 2; i++){
if(tr[x][i]){
fail[tr[x][i]] = tr[fail[x]][i];
q.push(tr[x][i]);
}else tr[x][i] = tr[fail[x]][i];
}
}
for(int i = 0; i <= cnt; i++) nxt[i][0][0] = tr[i][0], nxt[i][0][1] = tr[i][1];
for(int i = 1; i < 30; i++){
for(int j = 0; j <= cnt; j++){
nxt[j][i][0] = nxt[nxt[j][i - 1][0]][i - 1][1];
nxt[j][i][1] = nxt[nxt[j][i - 1][1]][i - 1][0];
}
}
}
void add(int i, int k){
x[px][i][k]++;
px = nxt[px][i][k];
}
void dfs(int i){
ans[i] = x[i][0][0] + x[i][0][1];
int o;
for(int j = 0; j < g[i].size(); j++){
o = g[i][j];
dfs(o);
ans[i] += ans[o];
}
}
int popcnt(int i){
int t = 0;
while(i){
t++;
i &= i - 1;
}
return t;
}
int main(){
#ifndef ONLINE_JUDGE
freopen("in","r",stdin);
freopen("out","w",stdout);
#endif
int n = read(), m = read();
for(int i = 1; i <= n; i++) L[i] = read(), R[i] = read() + 1;
for(int i = 1; i <= m; i++){
scanf("%s", s + 1);
insert(strlen(s + 1), i);
}
build();
int flag;
for(int i = 1; i <= n; i++){
flag = 1;
for(int j = 29; j >= 0; j--){
if(((L[i] >> j) & 1) < ((R[i] >> j) & 1)){
for(int k = 0; k < j; k++){
if((L[i] >> k) & 1){
add(k, popcnt(L[i]) % 2);
L[i] += 1 << k;
}
}
if(!((L[i] >> j) & 1)){
add(j, popcnt(L[i]) % 2);
L[i] += 1 << j;
}
for(int k = j - 1; k >= 0; k--){
if((R[i] >> k) & 1){
add(k, popcnt(L[i]) % 2);
L[i] += 1 << k;
}
}
}
}
}
for(int i = 29; i >= 1; i--){
for(int j = 0; j <= cnt; j++){
for(int k = 0; k < 2; k++){
x[j][i - 1][k] += x[j][i][k];
x[nxt[j][i - 1][k]][i - 1][k ^ 1] += x[j][i][k];
}
}
}
x[px][0][0]++;
dfs(0);
for(int i = 1; i <= m; i++) printf("%lld\n", ans[id[i]]);
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 21180kb
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: 4ms
memory: 17988kb
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: 32ms
memory: 50984kb
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: 0
Accepted
time: 514ms
memory: 368156kb
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:
274777 274799 99973 174803 174803 99996 16241 83732 91053 83750 83732 91070 83750 16246 3457 12784 43222 40510 43091 47961 70993 12757 12784 70948 47831 43239 40641 43109 12757 3489 459 2998 6565 6219 11607 31614 34345 6165 6467 36624 16421 31540 34510 36483 9693 3064 2998 9786 36657 34291 31484 163...
result:
ok 2064 lines
Test #5:
score: 0
Accepted
time: 484ms
memory: 383448kb
input:
100000 264 863548123 863548131 726674730 726674731 23567654 23567655 388640944 388640951 11253180 11253185 364951459 364951461 954258329 954258336 370336558 370336567 783663445 783663448 948622704 948622711 241717161 241717163 167305985 167305985 559579744 559579746 686340873 686340882 110381066 110...
output:
275122 274500 100192 174929 174929 99571 16458 83734 91338 83591 83734 91194 83591 15980 3543 12915 43156 40578 43255 48082 70962 12629 12915 70819 48181 43013 40479 43112 12629 3351 482 3061 6476 6439 11559 31596 34378 6200 6644 36611 16564 31518 34274 36688 9720 2909 3061 9854 36680 34139 31696 16...
result:
ok 264 lines
Test #6:
score: 0
Accepted
time: 479ms
memory: 386360kb
input:
100000 82 440580187 440580195 363746917 363746923 253327641 253327648 77285448 77285454 16654500 16654506 701949354 701949357 335798407 335798407 510898124 510898124 728200505 728200507 657089802 657089806 811878897 811878897 740279233 740279234 2002051 2002056 201584556 201584557 905281625 90528163...
output:
274946 275169 99944 175001 175001 100168 16163 83781 91017 83984 83781 91219 83984 16184 3463 12700 42944 40837 42987 48029 71306 12678 12700 71081 48072 43147 40794 43190 12678 3506 483 2980 6395 6305 11456 31487 34601 6236 6440 36547 16623 31406 34670 36636 9614 3064 2980 9720 36549 34532 31531 16...
result:
ok 82 lines
Test #7:
score: -100
Wrong Answer
time: 479ms
memory: 383000kb
input:
100000 65 990903704 990903704 488837026 488837029 520610697 520610700 84740156 84740158 145465213 145465219 802621365 802621370 637129208 637129216 138040766 138040770 789708694 789708702 122215439 122215439 805389806 805389815 726116821 726116826 90711329 90711332 980579500 980579500 877100759 8771...
output:
5228329126425 5228329128646 1742776378354 3485552748071 3485552748071 1742776380574 13499 1742776364855 1742776381627 1742776366443 1742776364855 1742776383216 1742776366444 14130 2380 11119 871388188933 871388175921 871388188609 871388193018 1742776354700 11743 11119 1742776353736 871388192694 8713...
result:
wrong answer 1st lines differ - expected: '275313', found: '5228329126425'