QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#472913 | #8565. Basic Blooms | ucup-team2307 | RE | 1ms | 3892kb | C++20 | 3.7kb | 2024-07-11 20:17:34 | 2024-07-11 20:17:39 |
Judging History
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*=Big(base);
num+=Big(dig);
}
friend bool operator<(const Seq&x,const Seq&y)
{
return x.num>y.num;
}
};
const int N=2e3+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])%=Big::BASE;
int t;
cin>>t;
while(t--)
{
int l,r;
cin>>l>>r;
cout<<(nums[r]-nums[l-1]+Big::BASE)%Big::BASE<<"\n";
}
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 3892kb
input:
3 1 2 1 10 15 2000
output:
3 55 736374621
result:
ok 3 number(s): "3 55 736374621"
Test #2:
score: -100
Runtime Error
input:
100000 26 99975 57 99944 28 99973 62 99939 71 99930 25 99976 53 99948 60 99941 73 99928 72 99929 30 99971 7 99994 3 99998 35 99966 73 99928 68 99933 83 99918 37 99964 63 99938 17 99984 34 99967 74 99927 6 99995 3 99998 23 99978 91 99910 39 99962 85 99916 82 99919 17 99984 61 99940 31 99970 44 99957 ...