QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#473198 | #8565. Basic Blooms | ucup-team2307 | TL | 0ms | 0kb | C++20 | 2.2kb | 2024-07-11 23:00:41 | 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";
}
}
詳細信息
Test #1:
score: 0
Time Limit Exceeded
input:
3 1 2 1 10 15 2000