QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#473198#8565. Basic Bloomsucup-team2307TL 0ms0kbC++202.2kb2024-07-11 23:00:412024-07-11 23:00:41

Judging History

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

  • [2024-07-11 23:00:41]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:0kb
  • [2024-07-11 23:00:41]
  • 提交

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 = MOD;
#define me (*this)
    Big() {}
    Big(auto val) { pb(val); }
    auto operator<=>(const Big& oth) const {
        if (auto res = sz(me) <=> sz(oth); res != 0) return res;
        for (int i = sz(me) - 1; i >= 0; i--)
            if (auto res = me[i] <=> oth[i]; res != 0) return res;
        return 0 <=> 0;
    }
    Big& operator+=(int r) {
//        for (int i = 0; r; i++) {
//            if (i == size()) pb(0);
//            me[i] += r;
//            if (r = me[i] >= BASE) me[i] -= BASE;
//        }
        front()+=r;
        return me;
    }
    Big& operator*=(int oth) {
        int carry=0;
        for(int&el:me)
        {
            el*=oth;
            el+=carry;
            carry=el/BASE;
            el%=BASE;
        }
        if(carry)
            pb(carry);
        return me;
    }
};

struct Seq
{
    int base,dig;
    Big num;
    Seq(int base,int dig):base(base),dig(dig),num{dig} {}
    void next()
    {
        num*=base;
        num+=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
Time Limit Exceeded

input:

3
1 2
1 10
15 2000

output:


result: