QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#378566#8565. Basic Bloomsucup-team1055#AC ✓1324ms119368kbC++204.2kb2024-04-06 13:33:582024-04-06 13:34:00

Judging History

你现在查看的是最新测评结果

  • [2024-04-06 13:34:00]
  • 评测
  • 测评结果:AC
  • 用时:1324ms
  • 内存:119368kb
  • [2024-04-06 13:33:58]
  • 提交

answer

#include <bits/stdc++.h>

#define rep(i,s,n) for(int i = int(s); i < int(n); i++)
#define rrep(i,s,n) for(int i = int(n) - 1; i >= int(s); i--)
#define all(v) (v).begin(), (v).end();

using ll = long long;
using ld = long double;
using ull = unsigned long long;

bool chmin(auto &a, auto b) {
    if(a <= b) return false;
    a = b;
    return true;
}

bool chmax(auto &a, auto b) {
    if(a >= b) return false;
    a = b;
    return true;
}

using namespace std;

template<ll m> struct modint {
    using mint = modint;
    ll a ;
    modint(ll x=0):a((x%m)%m){}
    static constexpr ll mod(){
        return m;
    }
    ll val() const{
        return a;
    }
    ll& val() {
        return a;
    }
    mint pow(ll n) const{
        mint res = 1;
        mint x = a;
        while(n){
            if (n&1) res*=x;
            x*=x;
            n>>=1;
        }
        return res;
    }
    mint inv() const {
        return pow(m-2);
    }
    mint& operator+=(const mint rhs){
        a+=rhs.a;
        if (a>=m)a-=m;
        return *this;
    }
    mint& operator-=(const mint rhs){
        if (a<rhs.a)a+=m;
        a-=rhs.a;
        return *this;
    }
    mint& operator*=(const mint rhs){
        a  = a*rhs.a%m;
        return *this;
    }
    mint& operator/=(mint rhs){
        *this *=rhs.inv();
        return *this;
    }
    friend mint operator+(const mint& lhs, const mint& rhs){
        return mint(lhs) += rhs;
    }
    friend mint operator-(const mint& lhs, const mint& rhs){
        return mint(lhs) -= rhs;
    }
    friend mint operator*(const mint& lhs, const mint& rhs){
        return mint(lhs) *= rhs;
    }
    friend mint operator/(const mint& lhs, const mint& rhs){
        return mint(lhs) /= rhs;
    }
    mint operator+()const {
        return *this;
    }
    mint operator-() const {
        return mint()-*this;
    }
    friend bool operator==(const modint &lhs, const modint &rhs){
        return lhs.a == rhs.a;
    }
    friend bool operator!=(const modint &lhs, const modint &rhs){
        return !(lhs==rhs);
    }
    
};

bool isprime(ll n){
    if (n == 1) return false;
    for (ll i=2; i*i<=n; i++){
        if (n%i == 0) return false;
    }
    return true;
}

int main() {
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);

    int tmp = 0;
    typedef modint<998244353> mint;

    random_device seed_gen;
    mt19937 engine(seed_gen());
    uniform_int_distribution<int> dist((int)7e8, (int)9e8);

    int mod_sub;
    do{
        mod_sub = dist(engine);
    }while(!isprime(mod_sub));

    map<ll,pair<double,int>> mp;

    for (int b=2; b<=16; b++){
        for (int c=1; c<b; c++){
            ll tar_sub = 0;
            mint tar = 0;
            bool mode = 0;
            for (int x=1; x<=100000000; x++){
                if (tar_sub * b + c >= mod_sub) mode = 1;
                tar_sub = (tar_sub * b + c) % mod_sub;
                tar = tar * b + c;
                if(log10(b) * x > 10000){
                    break;
                }
                ll HASH = (tar_sub << 32LL) | tar.val();
                if (mode){
                    mp[HASH] = pair(log10(b) * x  - log10(b-1) + log10(c), mod_sub);
                }else{
                    mp[HASH] = pair(log10(b) * x  - log10(b-1) + log10(c), tar_sub);
                }
            }
        }
    }

    //cout << (int)mp.size() << '\n';
    const ll mask = (1LL<<32)-1;

    vector<ll> smaller;
    vector<pair<double,ll>> larger;
    for (auto [x, y]: mp){
        if (y.second < mod_sub) smaller.push_back(y.second);
        else larger.push_back(pair(y.first, x&mask));
    }

    sort(smaller.begin(), smaller.end());
    sort(larger.begin(), larger.end());

    vector<mint> cons;
    
    for (ll x: smaller) cons.push_back(x);
    for (auto [x, y]: larger){
        //if (x < 20) cout << x << ' ' << y << '\n';
        cons.push_back(y);
    }

    int m = cons.size();
    vector<mint> rui(m + 1);
    rep(i,0,m){
        rui[i+1] = rui[i] + cons[i];
    }

    int q; cin >> q;
    while(q--){
        int l, r; cin >> l >> r;
        l--;
        cout << (rui[r] - rui[l]).val() << '\n';
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1275ms
memory: 119252kb

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: 1128ms
memory: 119368kb

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: 1324ms
memory: 119160kb

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