ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#164646 | #2909. number | anti | 100 | 1722ms | 381032kb | C++11 | 2.9kb | 2022-11-05 11:40:55 | 2022-11-05 13:02:52 |
answer
#include<bits/stdc++.h>
#define ll long long
#define rep(i,a,n) for (int i=(a);i<=(n);i++)
#define per(i,a,n) for (int i=(n);i>=(a);i--)
#define inf 0x3f3f3f3f
#define infll 0x3f3f3f3f3f3f3f3f
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define pii pair<int,int>
#define fi first
#define se second
#define lowbit(i) ((i)&(-i))
#define all(x) x.begin(),x.end()
#define SZ(x) ((int)x.size())
using namespace std;
ll pw[111];
int sum[1000015], g[15][10015][91];
vector<pii> f[6][101];
int Sum(ll x) {
return x < pw[6] ? sum[x] : (Sum(x / 10) + x % 10);
}
namespace fastIO {
const int SZ = 1 << 20;
struct IO {
char buf[SZ], *p1, *p2;
char fub[SZ], *pp;
IO() : p1(buf), p2(buf), pp(fub) {}
~IO() {fwrite(fub, 1, pp - fub, stdout);}
char gc() {
if (p1 == p2) p2 = (p1 = buf) + fread(buf, 1, SZ, stdin);
return p1 == p2 ? ' ' : *p1++;
}
ll read() {
ll x = 0;
char ch = gc();
while (!isdigit(ch)) ch = gc();
while (isdigit(ch)) x = (x << 3) + (x << 1) + (ch - '0'), ch = gc();
return x;
}
void pc(char c) {
if (pp - fub == SZ) fwrite(fub, 1, SZ, stdout), pp = fub;
*pp++ = c;
}
void write(ll x) {
static int sta[25];
if(x < 0) pc('-'), x = -x;
int top = 0;
do {
sta[top++] = x % 10, x /= 10;
} while (x);
while (top) pc(sta[--top] + '0');
}
} io;
ll read() {return io.read();};
void write(ll x) {io.write(x);};
}
using namespace fastIO;
int main() {
pw[0] = 1;
rep(i, 1, 15) pw[i] = pw[i - 1] * 10ll;
rep(i, 0, pw[6] - 1) {
int x = i;
while (x) {
sum[i] += x % 10;
x /= 10;
}
}
rep(i, 0, 5) {
// i + 1 位
int m = (10 - i - 1) * 9;
rep(j, 0, m) {
f[i][j].resize(pw[i + 1]);
per(k, 0, pw[i + 1] - 1) {
int add = j + sum[k];
if (k + add >= pw[i + 1]) {
f[i][j][k] = mp((k + add) / pw[i + 1], (k + add) % pw[i + 1]);
} else {
f[i][j][k] = f[i][j][k + add];
}
}
}
}
rep(i, 0, pw[4] - 1) {
rep(j, 0, 90) {
g[0][i][j] = f[5][sum[i]][j].se;
}
}
rep(k, 1, 14) {
rep(i, 0, pw[4] - 1) if (i + (1 << k) < pw[4]){
rep(j, 0, 90) {
g[k][i][j] = g[k - 1][i + (1 << (k - 1))][g[k - 1][i][j]];
}
}
}
int q = read();
ll x, y;
while (q--) {
x = read(), y = read();
{
int ax = x / pw[6], ay = y / pw[6];
if (ax < ay) {
x = (ll) (ax + 1) * pw[6] + f[5][sum[ax]][x % pw[6]].se;
ax++;
int d = ay - ax;
per(j, 0, 14) {
if (d >> j & 1) {
x = (ll) (ax + (1 << j)) * pw[6] + g[j][ax][x % pw[6]];
ax += (1 << j);
}
}
}
}
per(i, 0, 4) {
int ax = x / pw[i + 1], ay = y / pw[i + 1];
while (ax < ay) {
int p, q;
tie(p, q) = f[i][Sum(ax)][x % pw[i + 1]];
ax += p;
x = (ll) ax * pw[i + 1] + q;
}
}
while (x <= y) {
x += Sum(x);
}
write(x);
io.pc('\n');
}
return 0;
}
详细
小提示:点击横条可展开更详细的信息
Subtask #1:
score: 20
Accepted
Test #1:
score: 20
Accepted
time: 273ms
memory: 381032kb
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: 451ms
memory: 381028kb
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: 349ms
memory: 381028kb
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: 129ms
memory: 378916kb
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: 520ms
memory: 381032kb
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