QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#276539#7881. Computational Complexityucup-team088TL 924ms30672kbC++178.8kb2023-12-05 22:36:352023-12-05 22:36:36

Judging History

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

  • [2023-12-05 22:36:36]
  • 评测
  • 测评结果:TL
  • 用时:924ms
  • 内存:30672kb
  • [2023-12-05 22:36:35]
  • 提交

answer

#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<cassert>
#include<complex>
#include<numeric>
#include<array>
#include<chrono>
using namespace std;

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
//ll mod = 1;
constexpr ll mod = 998244353;
//constexpr ll mod = 1000000007;
const int mod17 = 1000000007;
const ll INF = (ll)mod17 * mod17;
typedef pair<int, int>P;

#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define all(v) (v).begin(),(v).end()
typedef pair<ll, ll> LP;

using ld = double;
typedef pair<ld, ld> LDP;
const ld eps = 1e-10;
const ld pi = acosl(-1.0);

template<typename T>
void chmin(T& a, T b) {
    a = min(a, b);
}
template<typename T>
void chmax(T& a, T b) {
    a = max(a, b);
}
template<typename T>
vector<T> vmerge(vector<T>& a, vector<T>& b) {
    vector<T> res;
    int ida = 0, idb = 0;
    while (ida < a.size() || idb < b.size()) {
        if (idb == b.size()) {
            res.push_back(a[ida]); ida++;
        }
        else if (ida == a.size()) {
            res.push_back(b[idb]); idb++;
        }
        else {
            if (a[ida] < b[idb]) {
                res.push_back(a[ida]); ida++;
            }
            else {
                res.push_back(b[idb]); idb++;
            }
        }
    }
    return res;
}
template<typename T>
void cinarray(vector<T>& v) {
    rep(i, v.size())cin >> v[i];
}
template<typename T>
void coutarray(vector<T>& v) {
    rep(i, v.size()) {
        if (i > 0)cout << " "; cout << v[i];
    }
    cout << "\n";
}
ll mod_pow(ll x, ll n, ll m = mod) {
    if (n < 0) {
        ll res = mod_pow(x, -n, m);
        return mod_pow(res, m - 2, m);
    }
    if (abs(x) >= m)x %= m;
    if (x < 0)x += m;
    //if (x == 0)return 0;
    ll res = 1;
    while (n) {
        if (n & 1)res = res * x % m;
        x = x * x % m; n >>= 1;
    }
    return res;
}
//mod should be <2^31
struct modint {
    int n;
    modint() :n(0) { ; }
    modint(ll m) {
        if (m < 0 || mod <= m) {
            m %= mod; if (m < 0)m += mod;
        }
        n = m;
    }
    operator int() { return n; }
};
bool operator==(modint a, modint b) { return a.n == b.n; }
bool operator<(modint a, modint b) { return a.n < b.n; }
modint operator+=(modint& a, modint b) { a.n += b.n; if (a.n >= mod)a.n -= (int)mod; return a; }
modint operator-=(modint& a, modint b) { a.n -= b.n; if (a.n < 0)a.n += (int)mod; return a; }
modint operator*=(modint& a, modint b) { a.n = ((ll)a.n * b.n) % mod; return a; }
modint operator+(modint a, modint b) { return a += b; }
modint operator-(modint a, modint b) { return a -= b; }
modint operator*(modint a, modint b) { return a *= b; }
modint operator^(modint a, ll n) {
    if (n == 0)return modint(1);
    modint res = (a * a) ^ (n / 2);
    if (n % 2)res = res * a;
    return res;
}

ll inv(ll a, ll p) {
    return (a == 1 ? 1 : (1 - p * inv(p % a, a)) / a + p);
}
modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); }
modint operator/=(modint& a, modint b) { a = a / b; return a; }
const int max_n = 1 << 20;
modint fact[max_n], factinv[max_n];
void init_f() {
    fact[0] = modint(1);
    for (int i = 0; i < max_n - 1; i++) {
        fact[i + 1] = fact[i] * modint(i + 1);
    }
    factinv[max_n - 1] = modint(1) / fact[max_n - 1];
    for (int i = max_n - 2; i >= 0; i--) {
        factinv[i] = factinv[i + 1] * modint(i + 1);
    }
}
modint comb(int a, int b) {
    if (a < 0 || b < 0 || a < b)return 0;
    return fact[a] * factinv[b] * factinv[a - b];
}
modint combP(int a, int b) {
    if (a < 0 || b < 0 || a < b)return 0;
    return fact[a] * factinv[a - b];
}

ll gcd(ll a, ll b) {
    a = abs(a); b = abs(b);
    if (a < b)swap(a, b);
    while (b) {
        ll r = a % b; a = b; b = r;
    }
    return a;
}
template<typename T>
void addv(vector<T>& v, int loc, T val) {
    if (loc >= v.size())v.resize(loc + 1, 0);
    v[loc] += val;
}
/*const int mn = 2000005;
bool isp[mn];
vector<int> ps;
void init() {
    fill(isp + 2, isp + mn, true);
    for (int i = 2; i < mn; i++) {
        if (!isp[i])continue;
        ps.push_back(i);
        for (int j = 2 * i; j < mn; j += i) {
            isp[j] = false;
        }
    }
}*/

//[,val)
template<typename T>
auto prev_itr(set<T>& st, T val) {
    auto res = st.lower_bound(val);
    if (res == st.begin())return st.end();
    res--; return res;
}

//[val,)
template<typename T>
auto next_itr(set<T>& st, T val) {
    auto res = st.lower_bound(val);
    return res;
}
using mP = pair<modint, modint>;
mP operator+(mP a, mP b) {
    return { a.first + b.first,a.second + b.second };
}
mP operator+=(mP& a, mP b) {
    a = a + b; return a;
}
mP operator-(mP a, mP b) {
    return { a.first - b.first,a.second - b.second };
}
mP operator-=(mP& a, mP b) {
    a = a - b; return a;
}
LP operator+(LP a, LP b) {
    return { a.first + b.first,a.second + b.second };
}
LP operator+=(LP& a, LP b) {
    a = a + b; return a;
}
LP operator-(LP a, LP b) {
    return { a.first - b.first,a.second - b.second };
}
LP operator-=(LP& a, LP b) {
    a = a - b; return a;
}
P operator-(P a, P b) {
    return { a.first - b.first,a.second - b.second };
}
P operator+(P a, P b) {
    return { a.first + b.first,a.second + b.second };
}

mt19937 mt(time(0));

const string drul = "DRUL";
string senw = "SENW";
//DRUL,or SENW
//int dx[4] = { 1,0,-1,0 };
//int dy[4] = { 0,1,0,-1 };

//------------------------------------

vector<int> vf = { 2,3,5,7 };
vector<int> vg = { 2,3,4,5 };

const int bb = 20;
const int bl = 1 << bb;
ll m;

vector<ll> xs[50];
vector<ll> rvs[50];

const int sz = 100;
void init() {
    map<ll, ll> mp;
    vector<int> vv;
    for (int v1 : vf)for (int v2 : vg)vv.push_back(v1 * v2);
    mp[1] = 1;
    for (int i = bb; i < 50; i++) {
        ll x = (1ll << i);
        while (x / (*mp.begin()).first >= sz) {
            LP p = *mp.begin(); mp.erase(mp.begin());
            for (int v : vv) {
                ll nv = p.first * v;
                mp[nv] += p.second;
                if (mp[nv] >= m)mp[nv] -= m;
            }
        }
        rvs[i].push_back(0);
        for (auto p : mp) {
            ll las = rvs[i].back() + p.second;
            if (las >= m)las -= m;
            rvs[i].push_back(las);
            xs[i].push_back(p.first);
        }
    }
}

using T = __int128;

void solve() {
    int f0, g0, t; cin >> f0 >> g0 >> t >> m;
    init();
    vector<ll> mf(bl);
    vector<ll> mg(bl);
    mf[0] = f0;
    mg[0] = g0;
    rep1(i, 9) {
        for (int v : vf) {
            mf[i] += mg[i / v];
        }
        chmax(mf[i], (ll)i);
        for (int v : vg) {
            mg[i] += mf[i / v];
        }
        chmax(mg[i], (ll)i);
    }
    rep(i, 10) {
        mf[i] %= m;
        mg[i] %= m;
    }
    for (int i = 10; i < bl; i++) {
        for (int v : vf) {
            mf[i] += mg[i / v];
            if (mf[i] >= m)mf[i] -= m;
        }
        for (int v : vg) {
            mg[i] += mf[i / v];
            if (mg[i] >= m)mg[i] -= m;
        }
    }
    auto query = [&](ll x)->LP {
        if (x < bl)return { mf[x],mg[x] };
        LP res = { 0,0 };
        int chk = -1;
        per(i, 50)if (x & (1ll << i)) {
            chk = i; break;
        }
        int cr = xs[chk].size();
        for (int d = 1; d < 2 * sz;d++) {
            ll le = x / (d + 1);
            le++;
            int cl = lower_bound(all(xs[chk]), le) - xs[chk].begin();
            ll val = rvs[chk][cr] - rvs[chk][cl];
            if (val < 0)val += m;
            res.first += (T)val * (T)mf[d] % (T)m;
            if (res.first >= m)res.first -= m;
            res.second += (T)val * (T)mg[d] % (T)m;
            if (res.second >= m)res.second -= m;
            cr = cl;
        }
        assert(cr == 0);
        return res;
    };
    rep(_, t) {
        ll x; cin >> x;
        LP p = query(x);
        cout << p.first << " " << p.second << "\n";
    }
}

signed main() {
    //ios::sync_with_stdio(false);
    //cin.tie(0);
    //cout << fixed<<setprecision(10);
    //init_f();
    //init();
    //while(true)
    //expr();
    //expr2();
    //int t; cin >> t; rep(i, t)
    solve();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 44ms
memory: 30604kb

input:

1958 920 10 100000000000
0
1
2
3
10
100
200
1000
19580920
20232023

output:

1958 920
3680 7832
10592 9554
17504 11276
50294 64826
784112 893714
1894550 1905470
12057866 12979424
71481494756 48626708512
28127864908 7251681354

result:

ok 20 numbers

Test #2:

score: 0
Accepted
time: 47ms
memory: 30664kb

input:

0 0 10 100000000000
0
1
2
3
4
10
20
30
40
100

output:

0 0
1 1
2 2
3 3
4 4
11 12
25 26
41 41
55 58
162 172

result:

ok 20 numbers

Test #3:

score: 0
Accepted
time: 55ms
memory: 30648kb

input:

2023 2023 10 2023
0
1
2
3
4
5
6
7
8
9

output:

0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0

result:

ok 20 numbers

Test #4:

score: 0
Accepted
time: 71ms
memory: 30668kb

input:

36092 30559 2149 729566623185
909730017626
961811467628
978809456383
494310140318
760462959632
726343527430
220697276132
366336227300
456813204361
569783542145
13854148170
51526515764
564416233246
876430686824
862897449267
956440673661
512777546436
728860125927
799238602356
978766770799
47962348351
...

output:

192287632545 510282654057
513694515018 658644741565
90751152870 6088748556
138070013247 301112114677
224113421002 105290451187
630454127249 196841848259
546918129568 526274849982
226761501362 157889210040
135623074930 620463814922
78467045157 602244472172
51639549042 411354142414
329188915935 306494...

result:

ok 4298 numbers

Test #5:

score: 0
Accepted
time: 115ms
memory: 30560kb

input:

46012 72474 6895 931299293479
635558333906
151352929427
186830308154
201652909474
130684521091
862625793178
335372663856
565394770762
609752364488
636658378167
568072145317
23602174799
74849827839
567735061723
964475612065
721588322843
526921882143
141483206690
794896616456
923141155683
443983986019...

output:

737640936783 269480550026
785950579990 586907405473
274405996613 356240054012
164145774405 803378519477
613956922400 426121843045
509646717167 788278629379
95131481441 672600899832
720839818877 52329269906
131977527669 257593035330
737640936783 269480550026
202443098753 171133839273
188615102144 605...

result:

ok 13790 numbers

Test #6:

score: 0
Accepted
time: 924ms
memory: 30672kb

input:

4625 65696 87448 104757899185
324541097749
340894391228
353710640194
913290645927
500906082550
994613091630
486893604015
755863379632
795242109754
670982629049
89739557323
995677833835
622128974870
291590021762
74643709454
491030939322
504220665415
590951839890
749414110824
908656060298
831415689095...

output:

24017028596 61020984279
90036018081 8518714361
4807132724 94915889679
60642395760 99169995073
45912197521 30663794937
26807208137 73005099296
31855861883 38442189712
61377861921 69296474844
15633158436 24561226404
83188091024 101278210525
92283972576 51782451279
22904017080 27746280119
46615471334 7...

result:

ok 174896 numbers

Test #7:

score: 0
Accepted
time: 300ms
memory: 30604kb

input:

14545 18504 24898 310785536775
50369414029
493590300593
553141557375
616338447787
866832676714
135190324674
601568991739
991767475529
948181269880
701011912636
639662587174
967753492870
160818187307
982894396663
184811806844
288729173645
518365001123
3574920653
699636637896
885581030321
227437326762...

output:

230379585588 282893684496
13911364238 39284517930
176790841557 274445952454
193216065450 156787491642
209030903098 129334601749
303968485891 121048097813
281524501935 227151375068
113606190940 153251759384
52704408619 125469600129
282450949147 185742976542
283723332110 113117774598
35391811596 23685...

result:

ok 49796 numbers

Test #8:

score: 0
Accepted
time: 105ms
memory: 30536kb

input:

24465 60420 5451 512518207068
743647145169
687426729690
724316856711
323681216943
237054238172
271472590422
716244379463
186531051694
101120430005
772181715954
161329999180
939829151905
671251781902
706749356702
290684936938
58171790124
528214369534
411903034120
690999684701
866800967640
62345896443...

output:

459924162645 318783416538
339019744008 78457535841
220446603579 257208701322
484581216738 249822897402
339783439530 427811175228
16082994351 231701822103
139456487361 111068628870
409702155636 141745699002
350279528034 52998807225
34751698464 318301237488
354335881755 315047176536
293154215637 12022...

result:

ok 10902 numbers

Test #9:

score: 0
Accepted
time: 144ms
memory: 30548kb

input:

58732 77988 10197 718545844658
432629909013
876968191491
923747773891
31023986099
607275799632
403459888874
826624799890
385589595156
249764622836
797916032244
711253029031
911904810940
218530928931
398053731601
400853034329
827614406604
505513152806
824526114884
645517179069
852315872255
1518563480...

output:

24000605268 693906447722
525784005798 714879350432
36422110278 667430950574
542153388742 693441524642
362698623376 431263731428
672885760590 97526477814
391490140074 590187631066
328145721424 601650408696
195995642958 617957874512
710138473080 616425385720
122228033978 1244962196
629811143468 197577...

result:

ok 20394 numbers

Test #10:

score: 0
Accepted
time: 840ms
memory: 30648kb

input:

22238 38788 74071 415988077246
383064772058
462095580167
177796182736
526444376691
553790727170
341399532741
434214439467
93665007089
8304450603
715899864226
581669048092
416564857486
796877611087
243428789606
100626765568
394142066971
253575121111
895217901037
415120242068
471521631858
970528271113...

output:

385279906044 258911594936
22906585374 73540222996
57816276602 201337940164
7149938072 174502276630
209805777078 77501184158
57919629614 274052543450
126817027564 101901346578
112656720460 197320817058
354605200408 34739504608
46029199082 30272239080
71552593352 181566346300
377248315820 100880109630...

result:

ok 148142 numbers

Test #11:

score: 0
Accepted
time: 902ms
memory: 30600kb

input:

32158 91598 78816 622015714836
72047535902
655932009263
381522067212
229492178551
915422354038
481976765785
544594859895
288428583255
165538578025
745929147812
135887045238
388640516521
344156758116
930438197210
206499895662
163584683449
267719456819
312135949096
365342769140
457036536473
3622549414...

output:

210074081370 27113743842
259753958536 98110597916
120975103772 293399465790
194692867960 22758588982
525481257566 596282347744
425811249644 466839902174
570537420584 570043937800
99647769876 444393829062
510257855410 587819161518
106048452974 319224577026
588389038572 356369734726
379782897354 43256...

result:

ok 157632 numbers

Test #12:

score: -100
Time Limit Exceeded

input:

66425 33512 92074 828043352426
802170819478
845473471064
548402399253
941129915004
285643915496
613964064237
659270247619
524332679152
318477738151
817098951130
653259489949
360716175556
854590352711
658588124545
316667993052
928732332633
245018240090
724759029859
324155230804
438256473792
753981611...

output:

571418482429 265649138476
22819138341 417543158364
153077693089 319889825969
617869129685 210757061376
617468843391 631998922716
809093498986 137138398929
735211697119 537435604204
203539232394 77766921856
275785833762 548878412771
345019591447 786348488828
568177254727 496265684109
570040097867 769...

result: