QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#472914 | #8565. Basic Blooms | ucup-team2307 | TL | 0ms | 0kb | C++20 | 3.7kb | 2024-07-11 20:18:24 | 2024-07-11 20:18:24 |
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)
#define shrink(x) while (!x.empty() && !x.back()) x.pop_back();
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)));
shrink(me);
}
friend ostream& operator<<(ostream& out, const Big& v) {
out << (v.empty() ? 0 : v.back());
for (int i = sz(v) - 2; i >= 0; i--)
out << setw(9) << setfill('0') << v[i];
return out;
}
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 strong_ordering::equal;
}
#define pm(op,inv,cmp,end) \
Big& operator op(const auto& oth) { \
for (int i = 0, r = 0; i < sz(oth) || r; i++) { \
if (i == size()) end(0); \
me[i] op r + (i < sz(oth) ? oth[i] : 0); \
if (r = me[i] cmp) me[i] inv BASE; \
} \
shrink(me); return me; \
}
pm(+=, -=, >= BASE, pb)
pm(-=, +=, < 0, assert)
Big operator*(const auto& 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(j < sz(oth) ? oth[j] : 0) + r;
c[i + j] = cur % BASE;
r = cur / BASE;
}
shrink(c); 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;
}
shrink(me); 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(%, .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 operator[](int) const { return val; }
};
struct Seq
{
int base,dig;
Big num;
Seq(int base,int dig):base(base),dig(dig),num{dig} {}
void next()
{
num*=Small(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
Time Limit Exceeded
input:
3 1 2 1 10 15 2000