UOJ Logo

NOI.AC

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#165226#2909. numberplatelet100408ms5776kbC++113.4kb2022-11-09 17:42:372022-11-09 17:42:38

answer

#include <bits/stdc++.h>
#define rep(i, l, r) for(int i = (l); i <= (r); i++)
#define per(i, r, l) for(int i = (r); i >= (l); i--)
#define mem(a, b) memset(a, b, sizeof a)
#define For(i, l, r) for(int i = (l), i##e = (r); i < i##e; i++)
#define pb push_back

using namespace std;
using u32 = uint32_t;
using u64 = uint64_t;
using ll = long long;

struct IO {
    static const int SZ = 1 << 17;
    char inBuf[SZ], *in1, *in2;
    inline __attribute((always_inline))
    u64 read() {
        if(__builtin_expect(in1 > inBuf + SZ - 32, 0)) {
            auto len = in2 - in1;
            memcpy(inBuf, in1, len);
            in1 = inBuf, in2 = inBuf + len;
            in2 += fread(in2, 1, SZ - len, stdin);
            if(in2 != inBuf + SZ) *in2 = 0;
        }
        u64 res = 0;
        char c;
        while((c = *in1++) < 48);
        while(res = res * 10 + c - 48, (c = *in1++) >= 48);
        return res;
    }
    char outBuf[SZ], *out;
    inline __attribute((always_inline))
    void write(u64 x) {
        if(__builtin_expect(out > outBuf + SZ - 32, 0))
            fwrite(outBuf, 1, out - outBuf, stdout), out = outBuf;
        if(!x) return *out++ = 48, void();
        alignas(2) const char* digits =
        "0001020304050607080910111213141516171819"
        "2021222324252627282930313233343536373839"
        "4041424344454647484950515253545556575859"
        "6061626364656667686970717273747576777879"
        "8081828384858687888990919293949596979899";
        alignas(2) static char buf[20];
        char* p = buf + 20;
        while(x >= 10) memcpy(p -= 2, digits + x % 100 * 2, 2), x /= 100;
        if(x) *--p = 48 + x;
        auto len = buf + 20 - p;
        memcpy(out, p, len), out += len;
    }
    IO() {
        in1 = inBuf;
        in2 = in1 + fread(in1, 1, SZ, stdin);
        out = outBuf;
    }
    ~IO() { fwrite(outBuf, 1, out - outBuf, stdout); }
} IO;

const int B = 1e5;

uint8_t sum[B + 8];
u64 ten[12], inv[12];
u64 f[10][11][92][100];

inline u64 pop(u64 x) {
    return sum[x / B] + sum[x % B];
}
inline u64 idiv(u64 x, int i) {
    // return x / ten[i];
    return i ? x * (__uint128_t)inv[i] >> 64 : x;
}
inline u64 mod(u64 x, int i) {
    // return x % ten[i];
    return x * inv[i] * (__uint128_t)ten[i] >> 64;
}
int main() {
    cin.tie(0)->sync_with_stdio(0);
    rep(i, 1, B) sum[i] = sum[i / 10] + i % 10;
    rep(i, 0, 10) ten[i] = i ? ten[i - 1] * 10 : 1, inv[i] = ~0ULL / ten[i] + 1;
    rep(i, 0, 2) rep(j, 1, i == 2 ? 1 : 9) rep(k, 0, 90) For(l, !k, ten[i]) {
        u64 x = l;
        while(x < j * ten[i]) x += k + sum[x];
        f[i][j][k][l] = x - l;
    }
    rep(i, 2, 9) {
        rep(j, 1, 9) rep(k, 0, (9 - i) * 9 + 10 - j) rep(l, !k, 99) {
            auto x = l + f[i][j][k][l];
            f[i][j + 1][k][l] = f[i][j][k][l] + (x < (j + 1) * ten[i] ? f[i][1][k + j][x - j * ten[i]] : 0);
        }
        if(i != 9) memcpy(f[i + 1][1], f[i][10], sizeof f[0][0]);
    }
    u64 q = IO.read(), x, y;
    while(q--) {
        x = IO.read(), y = IO.read() + 1;
        int i = 2;
        while(1) {
            auto hi = idiv(x, i), k = 10 - hi % 10;
            if(hi + k > idiv(y, i)) break;
            x += f[i][k][pop(hi)][mod(x, i)], i++;
        }
        while(x < y) {
            auto hi = idiv(x, i);
            x += f[i][(idiv(y, i) - hi) % 10][pop(hi)][mod(x, i)], i--;
        }
        cout << x << '\n';
    }
}

详细

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

Subtask #1:

score: 20
Accepted

Test #1:

score: 20
Accepted
time: 74ms
memory: 5776kb

input:

500000
1 1
1 2
1 3
1 4
1 5
1 6
1 7
1 8
1 9
1 10
1 11
1 12
1 13
1 14
1 15
1 16
1 17
1 18
1 19
1 20
1 ...

output:

2
4
4
8
8
8
8
16
16
16
16
16
16
16
16
23
23
23
23
23
23
23
28
28
28
28
28
38
38
38
38
38
38
38
38
38...

result:

ok 500000 lines

Test #2:

score: 0
Accepted
time: 81ms
memory: 5776kb

input:

500000
92 99927
119 99453
481 99268
29 99908
267 99547
835 99500
955 99099
734 99774
306 99883
729 9...

output:

99941
99454
99274
99941
99555
99520
99112
99775
99900
99657
99978
100010
99545
99245
99775
99907
997...

result:

ok 500000 lines

Subtask #2:

score: 25
Accepted

Test #3:

score: 25
Accepted
time: 82ms
memory: 5772kb

input:

500000
1 1
1 2
1 3
1 4
1 5
1 6
1 7
1 8
1 9
1 10
1 11
1 12
1 13
1 14
1 15
1 16
1 17
1 18
1 19
1 20
1 ...

output:

2
4
4
8
8
8
8
16
16
16
16
16
16
16
16
23
23
23
23
23
23
23
28
28
28
28
28
38
38
38
38
38
38
38
38
38...

result:

ok 500000 lines

Subtask #3:

score: 25
Accepted

Test #4:

score: 25
Accepted
time: 3ms
memory: 5632kb

input:

50
4587480273 4587480273
428862505 500400481
6920415626 7358620174
7787875953 7787884613
4542304779 ...

output:

4587480321
500400482
7358620210
7787884620
4542307848
4676070172
909798356
3555627285
9508855574
511...

result:

ok 50 lines

Subtask #4:

score: 30
Accepted

Test #5:

score: 30
Accepted
time: 168ms
memory: 5772kb

input:

500000
1 1
1 2
1 3
1 4
1 5
1 6
1 7
1 8
1 9
1 10
1 11
1 12
1 13
1 14
1 15
1 16
1 17
1 18
1 19
1 20
1 ...

output:

2
4
4
8
8
8
8
16
16
16
16
16
16
16
16
23
23
23
23
23
23
23
28
28
28
28
28
38
38
38
38
38
38
38
38
38...

result:

ok 500000 lines