結果

問題 No.8133 ‮Reversed‪
コンテスト
ユーザー KumaTachiRen
提出日時 2026-03-30 20:13:20
言語 C++23
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
WA  
実行時間 -
コード長 1,333 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 2,731 ms
コンパイル使用メモリ 331,320 KB
実行使用メモリ 337,592 KB
最終ジャッジ日時 2026-04-01 20:56:57
合計ジャッジ時間 4,060 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge1_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 2 WA * 4
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
using namespace std;

#define rep(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rrep(i, a, b) for (int i = (int)(b) - 1; i >= (int)(a); i--)

using ll = long long;
using i128 = __int128_t;

constexpr ll MOD = 7000000001;

constexpr int K = 19;
ll pow10[K];
i128 mpow10[K];

// [1,N)
ll f(ll N)
{
    i128 ret = 0;
    rep(k, 0, K)
    {
        if (k + 1 < K && pow10[k + 1] <= N) ret += mpow10[k] * mpow10[k] * 45 % MOD;
        else
        {
            i128 x = 0;
            rrep(l, 0, k + 1)
            {
                int c = l == k;
                int d = N / pow10[l] % 10;
                ret += x * (d - c) * mpow10[l] % MOD;
                ret += ((d - c) * (c + d - 1) / 2) * mpow10[k - l] * mpow10[l] % MOD;
                ret += mpow10[l] * (mpow10[l] - 1) * 5 * mpow10[k - l] * (d - c) % MOD;
                x += d * mpow10[k - l];
            }
            break;
        }
    }
    return ret;
}

int main()
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);

    pow10[0] = 1;
    rep(i, 1, K) pow10[i] = pow10[i - 1] * 10;
    mpow10[0] = 1;
    rep(i, 1, K) mpow10[i] = pow10[i] % MOD;

    int T;
    cin >> T;
    while (T--) {
        ll L, R;
        cin >> L >> R;
        ll ans = (f(R + 1) - f(L) + MOD) % MOD;
        cout << ans << "\n";
    }
}
0