QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#94742 | #3237. Innocence | whatever# | 100 ✓ | 86ms | 3300kb | C++17 | 2.9kb | 2023-04-07 17:27:09 | 2023-04-07 17:27:19 |
Judging History
answer
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = a, I = b; i <= I; ++i)
#define per(i, a, b) for (int i = a, I = b; i >= I; --i)
using namespace std;
using i64 = long long;
using i128 = __int128_t;
using pii = pair<int, int>;
template<typename T> void up(T &x, T y) { if (x < y) x = y; }
template<typename T> void down(T &x, T y) { if (x > y) x = y; }
const int P = 1e9 + 7;
void add(int &x, int y) { (x += y) >= P && (x -= P); }
int Add(int x, int y) { return (x += y) >= P ? (x - P) : x; }
void sub(int &x, int y) { (x -= y) < 0 && (x += P); }
int Sub(int x, int y) { return (x -= y) < 0 ? (x + P) : x; }
void mul(int &x, int y) { x = 1ll * x * y % P; }
int Mul(int x, int y) { return 1ll * x * y % P; }
int power(int a, int b, int c = 1) {
for (; b; b >>= 1, mul(a, a))
if (b & 1) mul(c, a);
return c;
}
int p, ways[33][2][2], dp[33][2][2][2];
int get(int x, int lb, bool odd) {
int res = 0;
per(i, p, 0) {
if (x >> i & 1) {
if (lb < i) continue;
bool tmp = odd;
if (lb == i) tmp ^= (x >> i & 1);
(tmp ? sub : add)(res, 1 << i);
}
}
return res;
}
void solve() {
int n, l, r, q;
cin >> n >> l >> r >> q;
if (r == 0) {
while (q--) {
int k;
cin >> k;
cout << (k == 0) << "\n";
}
return;
}
p = 32 - __builtin_clz(r++);
rep(i, 0, p - 1) {
rep(x, 0, 1) rep(y, 0, 1) {
ways[i][x][y] = power(Sub(get(r, i, y), get(l, i, x)), n);
}
}
int offset = power(r - l, n), coef = power(1 << p, P - 2);
while (q--) {
int k;
cin >> k;
// rep(s, 1, (1 << p) - 1) {
// int sum = 0;
// rep(i, l, r - 1) (__builtin_parity(i & s) ? sub : add)(sum, 1);
// sum = power(sum, n);
// (__builtin_parity(k & s) ? sub : add)(ans, sum);
// }
int hb = (k == 0) ? 0 : (32 - __builtin_clz(k));
if (hb > p) {
cout << "0\n";
continue;
}
int ans = offset;
memset(dp[p], 0, sizeof dp[p]);
dp[p][0][0][0] = 1;
per(i, p, 1) {
memcpy(dp[i - 1], dp[i], sizeof dp[i - 1]);
bool pl = (l >> (i - 1) & 1);
bool pr = (r >> (i - 1) & 1);
bool pk = (k >> (i - 1) & 1);
rep(x, 0, 1) rep(y, 0, 1) rep(z, 0, 1) {
int val = dp[i][x][y][z];
if (!val) continue;
add(dp[i - 1][x ^ pl][y ^ pr][z ^ pk], val);
int cur = Mul(val, ways[i - 1][x ^ pl][y ^ pr]);
((z ^ pk) ? sub : add)(ans, cur);
}
}
mul(ans, coef);
cout << ans << "\n";
}
}
int main() {
// freopen("1.in", "r", stdin);
ios::sync_with_stdio(0), cin.tie(0);
int T; cin >> T;
while (T--) solve();
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 86ms
memory: 3300kb
input:
1000 5 17330 22941 100 8458 32262 8227 17235 1939 24947 7438 14756 30233 4486 20510 3152 14618 24315 19113 3899 6934 25498 31479 2476 21263 13832 6700 1039 10830 1773 6702 22153 10912 6995 18025 9708 26284 30903 19091 18594 25753 8177 8794 19038 6701 21116 9318 30713 8552 6510 25433 20723 22941 1405...
output:
0 0 0 779687326 0 0 0 0 0 0 248417020 0 0 498707308 248417020 0 0 0 0 0 248417020 0 0 0 0 0 0 248417020 0 0 538213695 0 0 0 248417020 248417020 0 0 0 248417020 0 248417020 0 0 0 0 0 248417020 148895215 0 0 248417020 148895215 0 0 0 0 0 498707308 0 0 0 0 0 148894959 0 427827735 0 0 498707308 53821369...
result:
ok 100000 lines