QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#378203 | #8565. Basic Blooms | ucup-team2894# | AC ✓ | 334ms | 12572kb | C++20 | 2.7kb | 2024-04-06 09:38:41 | 2024-04-06 09:38:41 |
Judging History
answer
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<(b);++i)
using namespace std;
using pii = pair<int,int>;
using ll = long long;
using pll = pair<ll,ll>;
using vi = vector<int>;
using ld = long double;
#define all(x) (x).begin(), (x).end()
const int maxn = 1e6+10, inf = 1e9+100;
const ll linf = 1e18+100;
const int mod = 998244353;
const ld eps = 1e-9;
const ld PI = acos(-1.L);
vector<ll> ans;
pii cst[17];
ll modpow(ll a,ll b){
ll ans =1;
for(a%=mod;b;b>>=1,a=a*a%mod)if(b&1)ans=ans*a%mod;
return ans;
}
ll inv(ll x){return modpow(x,mod-2);}
ll iva[17];
ll modeval(ll base, pii st) {
return (modpow(base, st.first + 1) - 1) * iva[base - 1] % mod * st.second % mod;
}
ll smeval(ll base, pii st) {
ll ans = 0;
for(ll p = st.second, i = 0; i <= st.first; i++) {
if(i != 0) p *= base;
ans += p;
}
return ans;
}
ld lga[17];
ld apeval(ll base, pii st) {
return lga[base] * (st.first + 1) - lga[base - 1] + lga[st.second];
}
void solvee(){
ll l, r;
cin >> l >> r;
ll res = (ans[r] - ans[l-1]) % mod;
if(res < 0) res += mod;
cout << res << "\n";
}
void solve(){
ans.push_back(0);
for(int i=2;i<=16;i++){
cst[i] = {0,1};
iva[i] = inv(i);
lga[i] = log((ld)i);
}
iva[1] = 1;
lga[1] = 0;
using T = pair<ld,int>;
priority_queue<T,vector<T>,greater<T>> pq;
for(int i=2;i<=16;i++)pq.push({(ld)0,i});
bool small = true;
ll lv = -1;
ld lfv = -1;
while(ans.size() < maxn) {
auto [val, base] = pq.top();
pq.pop();
// cerr << val << " " << base << " " << cst[base].first << " " << cst[base].second << endl;
if(val > log((ld)linf)) small = false;
if(small) {
ll ev = smeval(base, cst[base]);
// cerr << ev << endl;
assert(lv <= ev);
if(ev != lv) {
lv = ev;
ans.push_back(modeval(base,cst[base]));
// cerr << "NEW " << ans.back() << endl;
}
}
else {
if(abs(val-lfv) > eps) {
lfv = val;
ans.push_back(modeval(base,cst[base]));
// cerr << "NEW " << ans.back() << endl;
}
}
cst[base].second ++;
if(cst[base].second == base) {
cst[base].first ++;
cst[base].second = 1;
}
ld v = apeval(base,cst[base]);
if(v <= log((ld)linf)) {
v = log((ld)smeval(base,cst[base]));
}
pq.push({v,base});
}
// for(int i=1;i<=1000;i++) cerr << ans[i] << endl;
for(int i=1;i<ans.size();i++)ans[i] = (ans[i-1] + ans[i]) % mod;
int tc;
cin >> tc;
while(tc--){
solvee();
}
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout<<fixed;
cout.precision(20);
cerr << fixed;
cerr.precision(5);
solve();
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 116ms
memory: 12380kb
input:
3 1 2 1 10 15 2000
output:
3 55 736374621
result:
ok 3 number(s): "3 55 736374621"
Test #2:
score: 0
Accepted
time: 132ms
memory: 11740kb
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 ...
output:
957904590 358359691 31524403 519690359 208321031 477204717 835715447 186583689 847423322 760952087 25753603 241428916 832623523 232679133 847423322 11425904 640652773 663756612 767901835 356898792 503593019 495288401 265039242 832623523 793754988 389398856 758928836 349243444 158978749 356898792 873...
result:
ok 100000 numbers
Test #3:
score: 0
Accepted
time: 334ms
memory: 12572kb
input:
1000000 561662 731870 560627 798415 497930 613164 210084 556894 479283 902738 271881 288854 467622 971733 55854 157477 310152 415183 146385 874852 140599 526659 438420 629148 733746 924626 84146 436790 275793 457537 466464 541539 661070 696519 534866 688272 190259 412401 206392 354525 2344 217676 51...
output:
387682849 91353801 759238022 175113502 143631299 488887729 201615869 359127675 954541571 806609754 254074751 589282709 523407089 298821716 593042756 268635027 495659009 878948937 741148909 716887807 31798813 425888650 765930054 831198164 372500280 694558761 918178838 919393601 661100143 134966024 37...
result:
ok 1000000 numbers
Extra Test:
score: 0
Extra Test Passed