QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#578827 | #9346. Binary Numbers | psycho# | WA | 7ms | 6008kb | C++20 | 2.5kb | 2024-09-20 21:42:12 | 2024-09-20 21:42:13 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define vc vector
#define pii pair <int, int>
#define int long long
using ld = long double;
using ll = long long;
const int inf = 1e9;
template<class T>
bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template<class T>
bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
const int mod = 1e9 + 7;
const int N = 1 << 18;
int n, m;
int lg[N];
int F(int x, int y) {
return m - lg[x ^ y];
}
void solve_case() {
cin >> m >> n;
int f = 1;
vc <int> l(n), r(n);
for (int i = 0; i < n; ++i) {
cin >> l[i] >> r[i];
int x = 1 << lg[l[i] ^ r[i]];
if (l[i] & (x - 1)) {
f = 0;
}
}
if (!f) {
cout << "0\n";
return;
}
vc <vc <int>> dp(n);
for (int i = l[0]; i <= r[0]; ++i) {
dp[0].push_back(i % mod);
}
for (int k = 1; k < dp[0].size(); ++k) {
dp[0][k] = (dp[0][k - 1] + dp[0][k]) % mod;
}
for (int i = 1; i < n; ++i) {
for (int j = l[i]; j <= r[i]; ++j) {
dp[i].push_back(0);
int kl = l[i - 1] - 1, kr = r[i - 1] + 1;
while (kr - kl > 1) {
int k = (kl + kr) / 2;
if (F(k, r[i - 1]) >= F(j, r[i - 1])) {
kr = k;
} else {
kl = k;
}
}
int l1 = kr;
kl = l[i - 1] - 1, kr = r[i - 1] + 1;
while (kr - kl > 1) {
int k = (kl + kr) / 2;
if (F(j, l[i]) >= F(k, l[i])) {
kl = k;
} else {
kr = k;
}
}
int r1 = kl;
if (l1 <= r1) {
int sr1 = dp[i - 1][r1 - l[i - 1]];
if (l1 >= l[i - 1] + 1)
sr1 = ((sr1 - dp[i - 1][l1 - l[i - 1] - 1]) % mod + mod) % mod;
dp[i].back() = sr1 * j % mod;
}
}
for (int k = 1; k < dp[i].size(); ++k) {
dp[i][k] = (dp[i][k - 1] + dp[i][k]) % mod;
}
}
int ans = dp[n - 1].back();
cout << ans << '\n';
}
signed main() {
for (int i = 2; i < N; ++i) {
lg[i] = lg[i >> 1] + 1;
}
ios::sync_with_stdio(false);
cin.tie(nullptr);
int T = 1;
cin >> T;
while (T--) solve_case();
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 5824kb
input:
1 2 2 0 1 2 3
output:
5
result:
ok single line: '5'
Test #2:
score: -100
Wrong Answer
time: 7ms
memory: 6008kb
input:
20 4 6 0 1 2 3 4 6 7 7 8 11 12 15 9 39 0 31 32 47 48 51 52 63 64 87 88 92 93 95 96 127 128 143 144 159 160 167 168 175 176 191 192 207 208 255 256 263 264 271 272 283 284 287 288 289 290 295 296 303 304 319 320 351 352 357 358 367 368 375 376 383 384 391 392 399 400 403 404 407 408 415 416 443 444 4...
output:
430920 0 0 496341250 0 5040 28188720 0 0 0 0 0 2268 147499198 1 0 0 0 28 0
result:
wrong answer 2nd lines differ - expected: '27651757', found: '0'