QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#133533#4937. Permutation TransformationPanC_ake#WA 7ms6304kbC++201.9kb2023-08-02 10:46:322023-08-02 10:47:41

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-08-02 10:47:41]
  • 评测
  • 测评结果:WA
  • 用时:7ms
  • 内存:6304kb
  • [2023-08-02 10:46:32]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define int long long 

const int mod = 998244353;
const int N = 200050;
const int inf = 0x3f3f3f3f3f3f3f3f;

vector<int> minp(N), primes;

void seive(int n) {
    for (int i = 2; i <= n; ++i) {
        if (!minp[i]) {
            minp[i] = i;
            primes.push_back(i);
        }
        for (auto p : primes) {
            if (i * p > n) break;
            minp[i * p] = p;
            if (p == minp[i]) break;
        }
    }
}

int fa[N];

int find(int x) {
    return x == fa[x] ? x : fa[x] = find(fa[x]);
}

void merge(int x, int y) {
    x = find(x), y = find(y);
    if (x != y) fa[x] = y;
}

int ksm(int a, int b) {
    int ans = 1;
    while (b) {
        if (b & 1) ans = ans * a % mod;
        a = a * a % mod;
        b >>= 1;
    }    
    return ans;
}


void solve() {
    int n;
    cin >> n;

    seive(n);

    for (int i = 1; i <= n; ++i) fa[i] = i;
    vector<int> a(n + 1);
    for (int i = 1; i <= n; ++i) {
        cin >> a[i];
        merge(a[i], i);
    }

    map<int, int> leader;
    for (int i = 1; i <= n; ++i) {
        leader[find(i)]++;
    }

    int two = 0;
    map<int, int> ans;
    for (auto [id, len] : leader) {
        int k = len, t = 0;
        while (k % 2 == 0) t++, k /= 2;
        two = max(two, t);
        k--;
        map<int, int> cnt;
        while (k > 1) {
            int p = minp[k];
            cnt[p]++;
            k /= p;
        }

        for (auto [x, y] : cnt) {
            ans[x] = max(ans[x], y);
        }
    }

    int res = 1;
    for (auto [x, y] : ans) {
        res = res * ksm(x, y) % mod;
    }
    cout << (res + two) % mod << '\n';
}

signed main() {
    ios::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    int t = 1;
    while(t--) solve();
}

詳細信息

Test #1:

score: 100
Accepted
time: 2ms
memory: 4572kb

input:

5
3 5 1 2 4

output:

3

result:

ok single line: '3'

Test #2:

score: 0
Accepted
time: 0ms
memory: 4544kb

input:

8
7 5 1 6 8 2 3 4

output:

4

result:

ok single line: '4'

Test #3:

score: 0
Accepted
time: 2ms
memory: 4492kb

input:

1
1

output:

1

result:

ok single line: '1'

Test #4:

score: -100
Wrong Answer
time: 7ms
memory: 6304kb

input:

100000
20864 34918 58550 1465 75674 30743 27235 88900 47488 50029 46054 84871 20330 72228 16506 44561 92519 97750 82891 60324 90508 39290 24663 38077 90189 30671 95476 64027 70888 90749 22566 8525 33675 16635 23392 97636 35788 89625 41966 78051 94034 15407 26545 83799 2233 10873 56946 71566 19045 44...

output:

32660679

result:

wrong answer 1st lines differ - expected: '216333199', found: '32660679'