QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#116776#5547. Short Functionberarchegas#WA 1ms3508kbC++172.7kb2023-06-30 03:50:292023-06-30 03:50:30

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-06-30 03:50:30]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3508kb
  • [2023-06-30 03:50:29]
  • 提交

answer

#include <bits/stdc++.h>
 
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
 
mt19937 rng((int) chrono::steady_clock::now().time_since_epoch().count());
    
const int MOD = 998244353;
const int MAXN = 1e5 + 5;
const ll INF = 2e18;

int v[MAXN], n, k;

int fexp(ll b, int e, int mod) {
    ll ans = 1;
    while (e) {
        if (e&1) ans = (ans * b) % mod;
        b = (b * b) % mod;
        e >>= 1;
    }
    return ans;
}

pll fexp2(ll b, int e, int x) {
    if (!e) {
        return {0, 1};
    }
    pll at = fexp2(b, e / 2, x);
    ll pri = at.first * at.first % (MOD - 1);
    pri = (pri * x) % (MOD - 1);
    pri = (pri + 2ll * at.first * at.second) % (MOD - 1);
    ll sec = at.second * at.second;
    pri = (pri + sec / x) % (MOD - 1);
    sec %= x;
    if (e & 1) {
        sec *= 2;
        pri = (2 * pri + sec / x) % (MOD - 1);
        sec %= x;
    }
    return {pri, sec};
}

vector<int> simulate(int rounds) {
    vector<int> a(n), b(n);
    for (int i = 0; i < n; i++) a[i] = v[i];
    b = a;
    for (int i = 0; i < rounds; i++) {
        a = b;
        for (int j = 0; j < n; j++) {
            b[j] = (1ll * a[j] * a[(j + (1ll << i)) % n]) % MOD;
        }
    }
    return b;
}

int mul(ll a, ll b) {
    return (a * b) % MOD;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> n >> k;
    ll tudo = 1;
    for (int i = 0; i < n; i++) {
        cin >> v[i];
        tudo = (tudo * v[i]) % MOD;
    }
    int cnt = 0, x = n;
    while (x % 2 == 0) {
        cnt++;
        x /= 2;
    }
    if (x == 1) {
        // potencia de 2
        if (k < cnt) {
            // simular o processo
            vector<int> ans = simulate(k);
            for (int x : ans) cout << x << ' ';
            cout << '\n';
            return 0;
        }
        int ans = fexp(tudo, fexp(2, k - cnt, MOD - 1), MOD);
        for (int i = 0; i < n; i++) {
            cout << ans << ' ';
        }
        cout << '\n';
        return 0;
    }
    
    vector<int> ans(n);
    int qtd = fexp(2, k, n);
    int elevate = fexp2(2, k, n).first;
    cout << qtd << ' ' << elevate << '\n';
    vector<int> pref(2 * n + 1);
    pref[0] = 1;
    int at = 1;
    for (int i = 0; i < 2 * n; i++) {
        if (i < n)
            pref[at] = (1ll * pref[at - 1] * v[i]) % MOD;
        else 
            pref[at] = (1ll * pref[at - 1] * v[i - n]) % MOD;
        at++;
    }
    at = 1;
    for (int i = 0; i < n; i++) {
        cout << mul(mul(pref[at + qtd - 1], fexp(pref[at - 1], MOD - 2, MOD)), fexp(tudo, elevate, MOD)) << ' ';
        at++;
    }
    cout << '\n';
    return 0;
}

詳細信息

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 3508kb

input:

5 2
1 2 3 4 5

output:

4 0
24 120 60 40 30 

result:

wrong answer 1st numbers differ - expected: '24', found: '4'