QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#276532#7881. Computational Complexityucup-team088WA 69ms30668kbC++178.8kb2023-12-05 22:33:382023-12-05 22:33:38

Judging History

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

  • [2023-12-05 22:33:38]
  • 评测
  • 测评结果:WA
  • 用时:69ms
  • 内存:30668kb
  • [2023-12-05 22:33:38]
  • 提交

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 = 30;
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;
        }
        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: 58ms
memory: 30608kb

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: 50ms
memory: 30636kb

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: 69ms
memory: 30624kb

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: -100
Wrong Answer
time: 63ms
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
300430782213 45866167388
51639549042 411354142414
329188915935 306494...

result:

wrong answer 19th numbers differ - expected: '78467045157', found: '300430782213'