QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#384698#4496. Shinobu Loves Segment TreeTobo#WA 147ms3592kbC++201.4kb2024-04-10 10:36:462024-04-10 10:36:46

Judging History

你现在查看的是最新测评结果

  • [2024-04-10 10:36:46]
  • 评测
  • 测评结果:WA
  • 用时:147ms
  • 内存:3592kb
  • [2024-04-10 10:36:46]
  • 提交

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;
        long long y = x >> 1;
        while (y)
        {
            path.push_back(y & 1);
            y >>= 1;
        }
        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: 147ms
memory: 3592kb

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
0
70
0
49
0
34
143
23
47
0
0
43
138
1351
0
75
160
0
0
0
130
78
0
4
0
0
0
61
134
0
0
2
169
292
0
756
304
0
0
0
66
0
49
164
393
0
0
82
0
0
95
8
34
597
22
0
0
0
61
6844
0
0
63
127
13
0
54
0
14
203
0
552
7
0
0
0
9
15
18
81
26
0
0
172
0
0
2538
0
138
53
198
60
108
20
7
190
0
192
0
5
0
59
393
125
0
81
...

result:

wrong answer 4th lines differ - expected: '61', found: '70'