QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#384700 | #4496. Shinobu Loves Segment Tree | Tobo# | WA | 161ms | 3620kb | C++20 | 1.4kb | 2024-04-10 10:40:08 | 2024-04-10 10:40:08 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int t;
cin >> t;
while (t--)
{
long long n, x;
cin >> n >> x;
if (x == 1)
{
cout << n * (n + 1) / 2 << '\n';
continue;
}
if (n == 1)
{
cout << 0 << '\n';
continue;
}
vector<int> path;
while (x > 1)
{
path.push_back(x & 1);
x >>= 1;
}
reverse(path.begin(), path.end());
auto dfs1 = [&](auto &dfs1, long long n, int dep)
{
if (dep == path.size())
return n;
return path[dep] ? dfs1(dfs1, n / 2, dep + 1) : dfs1(dfs1, (n + 1) / 2, dep + 1);
};
auto dfs2 = [&](auto &dfs2, long long l, long long r, int dep)
{
if (dep == path.size())
return (r - l + 1) * (l + r) / 2;
long long res = 0;
if (!path[dep])
l++, r++;
res = dfs2(dfs2, l / 2, r / 2, dep + 1) * 2;
if (l % 2 == 1)
res -= dfs1(dfs1, l / 2, dep + 1);
if (r % 2 == 0)
res -= dfs1(dfs1, r / 2, dep + 1);
return res;
};
cout << dfs2(dfs2, 1, n, 0) << '\n';
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 161ms
memory: 3620kb
input:
100000 249 707 360 1429 151 380 118 103 221 711 88 79 471 1668 222 377 481 676 483 921 326 558 347 1151 104 220 91 97 258 250 446 122 368 1335 242 335 395 470 180 669 99 222 342 979 345 431 119 97 283 781 325 643 488 1413 285 868 205 723 118 115 397 526 432 1557 197 761 145 287 304 270 331 243 98 36...
output:
0 0 89 61 0 28 338 64 407 176 94 0 75 58 294 1617 0 0 320 0 38 0 100 108 0 0 0 208 0 70 173 0 0 0 192 328 12 812 518 92 0 0 35 221 63 128 405 0 0 52 26 0 146 58 48 726 0 12 0 0 104 6757 0 15 63 278 94 262 194 0 0 236 0 459 228 0 63 262 0 361 0 209 290 102 0 240 127 418 2484 42 191 199 198 105 300 21...
result:
wrong answer 3rd lines differ - expected: '0', found: '89'