QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#440625 | #6842. Popcount Words | bykem | RE | 58ms | 32492kb | C++17 | 2.0kb | 2024-06-13 21:29:14 | 2024-06-13 21:29:15 |
Judging History
answer
#include <vector>
#include <iostream>
using namespace std;
using LL = long long;
using S = pair<int, bool>;
const int kN = 1e5 + 1, kT = 5e5 + 1;
const int kL = 30;
struct E {
int n[kL][2], f;
LL t[kL][2], c;
} e[kT];
int n, q, c, p[kN];
vector<S> s;
int d[kN], h = 1, t;
void A(int k, bool rv, int l, int r, int tl, int tr) {
if (l == tl && r == tr) {
s.emplace_back(k, rv);
return;
}
int m = l + (1 << k - 1) - 1;
if (tl <= m) {
A(k - 1, rv, l, m, tl, min(m, tr));
}
if (m < tr) {
A(k - 1, !rv, m + 1, r, max(m + 1, tl), tr);
}
}
int main() {
ios::sync_with_stdio(0), cin.tie(0);
cin >> n >> q;
for (int i = 1, l, r; i <= n; ++i) {
cin >> l >> r;
A(kL, 0, 0, (1 << kL) - 1, l, r);
}
for (int i = 1; i <= q; ++i) {
string t;
cin >> t;
int x = 0;
for (char ch : t) {
int &y = e[x].n[0][ch - '0'];
if (!y) {
y = ++c;
}
x = y;
}
p[i] = x;
}
for (d[++t] = 0; h <= t; ++h) {
int x = d[h];
for (int i = 0; i < 2; ++i) {
int &y = e[x].n[0][i];
if (y) {
e[y].f = (x ? e[e[x].f].n[0][i] : 0);
d[++t] = y;
} else {
y = e[e[x].f].n[0][i];
}
}
}
for (int i = 0; i < kL - 1; ++i) {
for (int x = 0; x <= c; ++x) {
e[x].n[i + 1][0] = e[e[x].n[i][0]].n[i][1];
e[x].n[i + 1][1] = e[e[x].n[i][1]].n[i][0];
}
}
int x = 0;
for (S i : s) {
++e[x].t[i.first][i.second];
x = e[x].n[i.first][i.second];
}
++e[x].c;
for (int i = kL - 2; i >= 0; --i) {
for (int x = 0; x <= c; ++x) {
LL v0 = e[x].t[i + 1][0], v1 = e[x].t[i + 1][1];
e[x].t[i][0] += v0, e[e[x].n[i][0]].t[i][1] += v0;
e[x].t[i][1] += v1, e[e[x].n[i][1]].t[i][0] += v1;
}
}
for (int x = 0; x <= c; ++x) {
e[x].c += e[x].t[0][0] + e[x].t[0][1];
}
for (int i = t; i >= 1; --i) {
e[e[d[i]].f].c += e[d[i]].c;
}
for (int i = 1; i <= q; ++i) {
cout << e[p[i]].c << '\n';
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3532kb
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: 1ms
memory: 5696kb
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: 58ms
memory: 32492kb
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
Runtime Error
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...