QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#473132#8565. Basic Bloomsucup-team2307WA 1645ms8188kbC++204.0kb2024-07-11 22:11:352024-07-11 22:11:36

Judging History

你现在查看的是最新测评结果

  • [2024-07-11 22:11:36]
  • 评测
  • 测评结果:WA
  • 用时:1645ms
  • 内存:8188kb
  • [2024-07-11 22:11:35]
  • 提交

answer

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

using ll = long long;
//#define int ll
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
using pii = pair<int, int>;
using vi = vector<int>;
#define fi first
#define se second
#define pb push_back

const int MOD=998244353;

struct Big: vector<signed> {
    static const int BASE = 1e9;
#define me (*this)
    Big() {}
    Big(auto val) { while (val) pb(val % BASE), val /= BASE; }
    Big(const string& s) {
        for (int i = sz(s); i > 0; i -= 9)
            pb(stoi(i < 9 ? s.substr(0, i) : s.substr(i - 9, 9)));
    }
    auto get(int i) const { return i < sz(me) ? me[i] : 0; }
    friend ostream& operator<<(ostream& out, const Big& v) {
        bool f = true;
        for (int i = sz(v) - 1; i >= 0; i--)
            if (v[i] || !f)
                out << setw(f ? 0 : 9) << setfill('0') << v[i],
                f = false;
        if (!f) out << 0;
        return out;
    }
    auto operator<=>(const Big& oth) const {
        for (int i = max(sz(me), sz(oth)) - 1; i >= 0; i--)
            if (auto res = me.get(i) <=> oth.get(i); res != 0) return res;
        return 0 <=> 0;
    }
    Big& operator+=(const auto& oth) {
        for (int i = 0, r = 0; i < sz(oth) || r; i++) {
            if (i == size()) pb(0);
            me[i] += r + oth.get(i);
            if (r = me[i] >= BASE) me[i] -= BASE;
        }
        return me;
    }
    Big& operator-=(const auto& oth) {
        for (int i = 0, r = 0; i < sz(oth) || r; i++) {
            assert (i < size());
            me[i] -= r + oth.get(i);
            if (r = me[i] < 0) me[i] += BASE;
        }
        return me;
    }
    Big& operator*=(int oth) {
        for (int i = 0, r = 0; i < sz(me) || r; i++) {
            if (i == size()) pb(0);
            ll cur = me[i] * ll(oth) + r;
            me[i] = cur % BASE;
            r = cur / BASE;
        }
        return me;
    }
    Big operator*(const Big& oth) const {
        Big c; c.resize(sz(me) + sz(oth));
        rep(i, 0, sz(me))
            for (int j = 0, r = 0; j < sz(oth) || r; ++j) {
                ll cur = c[i + j] + me[i] * ll(oth.get(i)) + r;
                c[i + j] = cur % BASE;
                r = cur / BASE;
            }
        return c;
    }
    int divmod(int oth) {
        int r = 0;
        for (int i = sz(me) - 1; i >= 0; i--) {
            ll cur = me[i] + (ll) r * BASE;
            me[i] = cur / oth;
            r = cur % oth;
        }
        return r;
    }
    Big& operator/=(int oth) { divmod(oth); return me; }
#define def(op, expr) friend auto operator op(Big a, const auto&b) { return a expr(b); }
    def(+, +=) def(-, -=) def(*, *=) def(/, /=) def(%, .divmod)
    Big& operator*=(const auto& oth) { return me = me * oth; }
};

struct Small {
    Big::value_type val;
    Small(Big::value_type val) : val(val) { assert(val < Big::BASE); }
    static int size() { return 1; }
    auto get(int i) const { return i ? 0 : val; }
};

struct Seq
{
    int base,dig;
    Big num;
    Seq(int base,int dig):base(base),dig(dig),num{dig} {}
    void next()
    {
        num*=base;
        num+=Small(dig);
    }
    friend bool operator<(const Seq&x,const Seq&y)
    {
        return x.num>y.num;
    }
};

const int N=1e6+100;

signed main() {
    cin.tie(0)->sync_with_stdio(0);
    cin.exceptions(cin.failbit);

    priority_queue<Seq> pq;
    for(int base=2;base<=16;base++)
        for(int dig=1;dig<base;dig++)
            pq.emplace(base,dig);

    vector<int> nums{0};
    Big prv;
    while(nums.size()<=N)
    {
        Seq cur=pq.top();
        pq.pop();
        if(cur.num!=prv)
            prv=cur.num,
            nums.pb({prv.front()});
        cur.next();
        pq.push(cur);
    }
    for(int i=1;i<sz(nums);i++)
        (nums[i]+=nums[i-1])%=MOD;
    int t;
    cin>>t;
    while(t--)
    {
        int l,r;
        cin>>l>>r;
        cout<<(nums[r]-nums[l-1]+MOD)%MOD<<"\n";
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 1645ms
memory: 8188kb

input:

3
1 2
1 10
15 2000

output:

3
55
241011427

result:

wrong answer 3rd numbers differ - expected: '736374621', found: '241011427'