結果
| 問題 | No.8133 Reversed |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-04-01 23:08:57 |
| 言語 | C++23 (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 2,474 bytes |
| 記録 | |
| コンパイル時間 | 4,909 ms |
| コンパイル使用メモリ | 384,408 KB |
| 実行使用メモリ | 394,756 KB |
| 最終ジャッジ日時 | 2026-04-01 23:09:13 |
| 合計ジャッジ時間 | 14,739 ms |
|
ジャッジサーバーID (参考情報) |
judge2_0 / judge1_1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 4 TLE * 2 |
ソースコード
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
using ll = __int128_t;
// using mint = modint998244353;
// using mint = modint1000000007;
template <typename T> using vec = vector<T>;
template <typename T> using pa = pair<T, T>;
template <typename T> using mipq = priority_queue<T, vec<T>, greater<T>>;
#define REP(_1, _2, _3, _4, name, ...) name
#define REP1(i, n) for (auto i = decay_t<decltype(n)>{}; (i) < (n); ++(i))
#define REP2(i, l, r) for (auto i = (l); (i) < (r); ++(i))
#define REP3(i, l, r, d) for (auto i = (l); (i) < (r); i += (d))
#define rep(...) REP(__VA_ARGS__, REP3, REP2, REP1)(__VA_ARGS__)
#define rrep(i, r, l) for (int i = (r); i >= (l); --i)
template <typename T> bool chmax(T &a, const T &b) { return (a < b ? a = b, true : false); }
template <typename T> bool chmin(T &a, const T &b) { return (a > b ? a = b, true : false); }
constexpr int INF = 1 << 30;
constexpr ll LINF = 1LL << 60;
constexpr int mov[4][2] = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};
void solve();
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout << fixed << setprecision(15);
int T = 1;
// cin >> T;
while (T--) solve();
}
constexpr ll MOD = 7e9 + 1;
ll pow10[20];
unordered_map<long long, long long> memo;
ll rev(ll n) {
string s = to_string((long long)n);
ranges::reverse(s);
return stoll(s);
}
long long calc(long long n) {
assert(n >= 0);
if (memo.contains(n)) return memo[n];
ll res = 0;
if (n < 100) {
rep(i, 1, n + 1) {
res += rev(i);
}
} else {
string s = to_string((long long)n);
int L = s.size();
res = 45;
rep(i, 2, L) {
res += 45 * pow10[i - 1] % MOD * (pow10[i - 1] - pow10[i - 2]) % MOD;
res %= MOD;
}
ll x = n / 10, y = pow10[L - 2] - 1;
res += 10 * calc(x - 1);
res %= MOD;
res += 45 * pow10[L - 1] % MOD * (x - 1 - y) % MOD;
res %= MOD;
ll v = n % 10;
res += (v + 1) * rev(x);
res += v * (v + 1) / 2 * pow10[L - 1];
res %= MOD;
}
memo[n] = res;
return res;
}
void solve() {
pow10[0] = 1;
rep(i, 1, 20) {
pow10[i] = pow10[i - 1] * 10 % MOD;
}
int N;
cin >> N;
rep(i, N) {
long long l, r;
cin >> l >> r;
ll res = (calc(r) - calc(l - 1) + MOD) % MOD;
cout << (long long)res << '\n';
}
}