QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#820467#4496. Shinobu Loves Segment TreeSGColinAC ✓14ms3884kbC++201.6kb2024-12-18 21:32:362024-12-18 21:32:37

Judging History

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

  • [2024-12-18 21:32:37]
  • 评测
  • 测评结果:AC
  • 用时:14ms
  • 内存:3884kb
  • [2024-12-18 21:32:36]
  • 提交

answer

#include <bits/stdc++.h>
//
#define var auto
#define let auto const
#define mid ((l + r) >> 1)
#define loop for (;;)
#define downTo(n) for (int it{n}; it; --it)
#define repeat(n) for (int it{1}, ed{n}; it <= ed; ++it)
typedef long long Int;
typedef long double real;

Int i32() {
    Int a{};
    int b{}, sgn{};
    for (; !isdigit(b); b = getchar()) sgn = b == '-';
    for (; +isdigit(b); b = getchar()) a = a * 10 + b - '0';
    return sgn ? -a : +a;
}

void solve() {
    {
        Int n = i32();
        Int x = i32();
        Int lc = 1;
        Int mc = 1;
        Int rc = 1;
        for (int i = std::__lg(x); i; --i, mc <<= 1) {
            if (n == 1) {
                puts("0");
                return;
            }
            if (x & (1 << i - 1)) {
                if (n == 2) {
                    lc = rc;
                    n = 1;
                } else if (n == 3) {
                    lc = rc = mc + rc;
                    n = 1;
                } else {
                    lc = mc << 1;
                    rc += (n & 1) ? mc : 0;
                    n = n + 0 >> 1;
                }
            } else {
                if (n == 2) {
                    lc = rc;
                    n = 1;
                } else {
                    lc = mc;
                    rc += (n & 1) ? 0 : mc;
                    n = n + 1 >> 1;
                }
            }
        }
        if (n == 1)
            printf("%lld\n", lc);
        else
            printf("%lld\n", (n + 1) * (n - 2) / 2 * mc + n * rc + lc);
    }
}

int main() {
    Int T = i32();
    while (T--) solve();
}

详细

Test #1:

score: 100
Accepted
time: 14ms
memory: 3884kb

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
61
0
28
0
64
151
176
0
0
11
58
230
1585
0
0
192
0
0
0
100
108
0
0
0
0
0
70
0
0
0
0
64
328
0
808
390
0
0
0
35
0
63
128
405
0
0
52
0
0
146
0
48
662
0
0
0
0
72
6757
0
15
63
150
30
6
66
0
0
236
0
459
100
0
63
0
0
105
0
81
34
0
0
208
0
0
2484
0
63
71
198
89
172
83
19
160
0
237
0
0
0
28
423
32
0
220...

result:

ok 100000 lines