QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#278591 | #6842. Popcount Words | rageOfThunder# | WA | 22ms | 96608kb | C++14 | 2.2kb | 2023-12-07 17:53:10 | 2023-12-07 17:53:11 |
Judging History
answer
// MagicDark
#include <bits/stdc++.h>
#define debug cerr << "[" << __LINE__ << "] "
#define SZ(x) (int) x.size() - 1
#define all(x) x.begin(), x.end()
#define ms(x, y) memset(x, y, sizeof x)
#define F(i, x, y) for (int i = (x); i <= (y); i++)
#define DF(i, x, y) for (int i = (x); i >= (y); i--)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
template <typename T> inline void chkmax(T& x, T y) {x = max(x, y);}
template <typename T> inline void chkmin(T& x, T y) {x = min(x, y);}
const int N = 5e5 + 10;
int n, m, l[N], r[N], t[N][2], fail[N], tot, id[N], jump[31][N][2];
ll ans[N][31][2], occ[N];
int ins() {
string st; cin >> st;
int x = 0;
for (char i: st) {
int k = i == '1';
if (!t[x][k]) t[x][k] = ++tot;
x = t[x][k];
}
return x;
}
vector <int> g[N];
void build() {
queue <int> q;
F(i, 0, 1)
if (t[0][i]) q.push(t[0][i]);
while (q.size()) {
int x = q.front(); q.pop();
F(i, 0, 1)
if (t[x][i]) {
fail[t[x][i]] = t[fail[x]][i];
q.push(t[x][i]);
} else t[x][i] = t[fail[x]][i];//, debug << fail[x] << " " << i << endl;
}
F(i, 1, tot) g[fail[i]].push_back(i);
// F(i, 0, tot)
// F(j, 0, 1)
// cout << i << ' ' << j << ' ' << ' ' << t[i][j] << '\n';
F(i, 0, tot)
F(j, 0, 1)
jump[0][i][j] = t[i][j];
F(i, 1, 30)
F(j, 0, tot)
F(k, 0, 1)
jump[i][j][k] = jump[i - 1][jump[i - 1][j][k]][k ^ 1];
}
void update() {
DF(i, 30, 1)
F(j, 0, tot)
F(k, 0, 1) {
ans[i - 1][j][k] += ans[i][j][k];
ans[i - 1][jump[i - 1][j][k]][k ^ 1] += ans[i][j][k];
}
F(i, 0, tot)
F(j, 0, 1)
occ[t[i][j]] += ans[0][i][j];
}
void dfs(int x) {
for (int i: g[x]) dfs(i), occ[x] += occ[i];
}
signed main() {
cin.tie(0) -> sync_with_stdio(0);
cin >> n >> m;
F(i, 1, n) cin >> l[i] >> r[i];
F(i, 1, m) id[i] = ins();
build();
int x = 0;
F(i, 1, n)
while (l[i] <= r[i]) {
int t = l[i] & -l[i];
while (l[i] + t - 1 > r[i]) t /= 2;
// debug << x << " " << __builtin_ctz(t) << endl;
ans[__builtin_ctz(t)][x][__builtin_parity(l[i])]++;
x = jump[__builtin_ctz(t)][x][__builtin_parity(l[i])];
l[i] += t;
}
update();
dfs(0);
F(i, 1, m) cout << occ[id[i]] << '\n';
return 0;
}
/* why?
3 1
2 6
1 3
4 8
0
*/
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 88812kb
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: 8ms
memory: 87828kb
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: -100
Wrong Answer
time: 22ms
memory: 96608kb
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:
7831533269934317583 7831533269934318096 -5257503603799658090 -5357707199975575943 -5357705524192536266 -5257505279582697255 18260394228525 -5257521864193886615 -100214677165974802 -5257492522809601141 -2628720676227672931 -2728984847964863335 -5257522000261240711 16720678543455 4154490781908 1410590...
result:
wrong answer 1st lines differ - expected: '273828', found: '7831533269934317583'