QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#379674 | #8565. Basic Blooms | ucup-team206# | TL | 1ms | 3736kb | C++17 | 1.6kb | 2024-04-06 18:14:14 | 2024-04-06 18:14:16 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,s,t) for(int i=(s),_t=(t); i<=_t; ++i)
#define DOR(i,s,t) for(int i=(s),_t=(t); i>=_t; --i)
typedef double db;
typedef long long ll;
const int N=500000+50;
const int Mod=998244353;
const ll INF=1e17;
struct node {
int b,k,l;
ll v;
ll value() const{
ll x=0;
FOR(i,1,l) {
x=x*b+k;
if(x>=INF) return INF;
}
return x;
}
db Log() const {
return log(k)-log(b-1)+l*log(b);
}
};
int cmp(node a,node b) {
ll va=a.value(),vb=b.value();
if(va<INF || vb<INF) {
return va<vb?-1:va>vb;
}
db la=a.Log(),lb=b.Log();
if(fabs(la-lb)<1e-9 && a.v==b.v) return 0;
return la<lb?-1:la>lb;
}
bool operator <(node a,node b) {
return cmp(a,b)>0;
}
ll solve(int n) {
if(!n) return 0;
priority_queue<node> Q;
FOR(b,2,16) {
FOR(k,1,b-1) {
Q.push({b,k,1,k});
}
}
ll res=0;
node las={0,0,0};
int m=0;
while(m<n) {
auto x=Q.top();
// cerr << x.b << ' ' << x.k << ' ' << x.l << ' ' << x.v << endl;
Q.pop();
if(las.b==0 || cmp(las,x)!=0) {
res=(res+x.v)%Mod;
++m;
}
las=x;
Q.push({x.b,x.k,x.l+1,(x.v*x.b+x.k)%Mod});
}
return res;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int T;
cin >> T;
while(T--) {
int l,r;
cin >> l >> r;
ll res=(solve(r)-solve(l-1))%Mod;
if(res<0) res+=Mod;
cout << res << '\n';
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3736kb
input:
3 1 2 1 10 15 2000
output:
3 55 736374621
result:
ok 3 number(s): "3 55 736374621"
Test #2:
score: -100
Time Limit Exceeded
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 ...