UOJ Logo

NOI.AC

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#214535#2377. 二进制nodgd1002609ms1348kbC++112.0kb2024-11-19 21:29:302024-11-19 23:02:48

answer

#include <bits/stdc++.h>

using namespace std;

typedef unsigned long long u64;
const int BUFFER_SIZE = 1 << 20;
char rb[BUFFER_SIZE], *rp = rb, *rt = rb;
inline char read_char() {
    return rp == rt ? (rt = rb + fread(rb, 1, BUFFER_SIZE, stdin), rp = rb, *rp ++) : *rp ++;
}
inline u64 read_int() {
    u64 x = 0;
    char ch = read_char(), flag = 0;
    while (ch != '-' && (ch < '0' || ch > '9')) {
        ch = read_char();
    }
    if (ch == '-') {
        flag = 1;
        ch = read_char();
    }
    for (x = 0; ch >= '0' && ch <= '9'; ch = read_char()) {
        x = x * 10 + (ch - '0');
    }
    return flag ? -x : x;
}

u64 c[70][70];
void init() {
    c[0][0] = 1;
    for (int i = 1; i <= 64; i ++) {
        c[i][0] = 1;
        for (int j = 1; j <= i; j ++) {
            c[i][j] = c[i - 1][j - 1] + c[i - 1][j];
        }
    }
}
u64 get_f(u64 N, int K) {
    if (N == 0) return 0;
    int h = 0;
    for (; h < 64 && 1ull << h <= N; h ++);
    u64 m = 0;
    int k = K;
    for (int i = h - 1; i >= 0 && k >= 1; i --) {
        if (N >> i & 1) {
            k --;
        } else {
            m += c[i][k - 1];
        }
    }
    k = K - 1;
    for (int i = h - 1; i >= 0 && k >= 0; i --) {
        if (i == 0 || (N >> i - 1 & 1)) {
            m += c[i][k];
            k --;
        }
    }
    return m;
}

int main() {
    init();
    for (int T = read_int(); T --; ) {
        u64 M = read_int();
        int K = read_int();
        if (M > c[64][K - 1]) {
            printf("0 0\n");
        } else {
            u64 nl = 0, nr = 0;
            for (int i = 63; i >= 0; i --) {
                if (get_f(nl | 1ull << i, K) < M) {
                    nl |= 1ull << i;
                }
                if (get_f(nr | 1ull << i, K) <= M) {
                    nr |= 1ull << i;
                }
            }
            printf("%llu %llu\n", nl + 1, nr - nl);
        }
    }
    return 0;
}

Details

小提示:点击横条可展开更详细的信息

Test #1:

score: 10
Accepted
time: 56ms
memory: 1220kb

input:

10000
1 1
1 1
2 1
1 1
1 1
1 1
6 1
4 1
1 1
5 1
3 1
1 1
3 1
1 1
1 1
3 1
5 1
4 1
1 1
4 1
5 1
1 1
3 1
3 ...

output:

1 18446744073709551615
1 18446744073709551615
0 0
1 18446744073709551615
1 18446744073709551615
1 18...

result:

ok 10000 lines

Test #2:

score: 10
Accepted
time: 169ms
memory: 1228kb

input:

10000
42 2
58 2
1 1
64 2
1 1
29 2
3 1
46 2
1 1
62 2
33 2
1 1
46 2
1 1
1 2
52 2
52 2
1 1
6 1
5 1
4 1
...

output:

2199023255553 2199023255552
144115188075855873 144115188075855872
1 18446744073709551615
92233720368...

result:

ok 10000 lines

Test #3:

score: 10
Accepted
time: 228ms
memory: 1236kb

input:

10000
1 1
5 1
11 2
1967 3
314 3
1 1
2 1
3 2
1 1
482 3
1376 3
5 1
518 3
7 2
1264 3
5 1
1 1
43 2
688 3...

output:

1 18446744073709551615
0 0
1025 1024
9223372036854784001 8192
33562625 8192
1 18446744073709551615
0...

result:

ok 10000 lines

Test #4:

score: 10
Accepted
time: 236ms
memory: 1236kb

input:

10000
6 2
67 2
4 1
3 1
10 2
1444 3
1730 3
1808 3
36 2
4 1
1489 3
18 2
1317 3
30 2
33 2
43 2
822 3
63...

output:

33 32
0 0
0 0
0 0
513 512
18014398509486081 4096
576460752303685633 262144
1152921642045800449 13743...

result:

ok 10000 lines

Test #5:

score: 10
Accepted
time: 332ms
memory: 1232kb

input:

10000
1 10
1 23
1 21
1 57
1 19
1 53
1 12
1 41
1 35
1 5
1 5
1 40
1 64
1 56
1 21
1 37
1 4
1 29
1 23
1 ...

output:

512 256
4194304 2097152
1048576 524288
72057594037927936 36028797018963968
262144 131072
45035996273...

result:

ok 10000 lines

Test #6:

score: 10
Accepted
time: 241ms
memory: 1232kb

input:

10000
3 30
1 58
8 31
3 8
7 34
1 52
4 37
5 55
1 51
1 57
3 16
10 9
5 12
7 5
9 34
3 12
6 30
8 47
1 19
9...

output:

939524096 67108864
144115188075855872 72057594037927936
2139095040 4194304
224 16
17045651456 671088...

result:

ok 10000 lines

Test #7:

score: 10
Accepted
time: 250ms
memory: 1232kb

input:

10000
1 50
9 35
1 45
5 47
8 25
9 64
7 58
1 17
7 26
3 26
10 51
5 47
1 31
5 51
1 54
9 9
1 29
7 8
5 59
...

output:

562949953421312 281474976710656
34292629504 33554432
17592186044416 8796093022208
136339441844224 21...

result:

ok 10000 lines

Test #8:

score: 10
Accepted
time: 429ms
memory: 1344kb

input:

10000
96279085620 55
21919 62
1 1
410991310 58
128257342884936 16
32 2
1926983496109 53
273781151035...

output:

18156752275605815288 4
18445618173802577408 256
1 18446744073709551615
18410697675914600240 8
929614...

result:

ok 10000 lines

Test #9:

score: 10
Accepted
time: 339ms
memory: 1348kb

input:

10000
609397314 58
83938839055331732 41
1929 3
106050747439191010 28
79727454070513347 25
2092718359...

output:

18446743916937871359 32769
8902485001267827531 2
4611686155866341377 137438953472
137152836541070556...

result:

ok 10000 lines

Test #10:

score: 10
Accepted
time: 329ms
memory: 1344kb

input:

10000
318262090679371113 39
11268952008014 52
488797365448018117 30
163471567770312245 41
1954343992...

output:

12110134414455758655 17
18385939706301365182 1
5437006568074494642 1
14807428564216957558 1
35239777...

result:

ok 10000 lines

Extra Test:

score: 0
Extra Test Passed