QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#404533 | #4937. Permutation Transformation | kevinyang# | WA | 11ms | 8520kb | C++17 | 1.9kb | 2024-05-04 05:01:42 | 2024-05-04 05:01:42 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define int long long
struct DisjointSet{
vector<int>parent,sz;
int size;
void init(int n){
size = n;
parent.resize(n+1); sz.resize(n+1);
for(int i = 1; i<=n; i++){
parent[i] = i;
sz[i] = 1;
}
}
int find(int x){
if(parent[x]==x)return x;
return find(parent[x]);
}
void Union(int x, int y){
x = find(x); y = find(y);
if(x==y)return;
if(sz[x]<sz[y]){
parent[x] = y;
sz[y]+=sz[x];
}
else{
parent[y] = x;
sz[x]+=sz[y];
}
}
};
const int mod = 998244353;
const int mxn = 100005;
const int N = 1e5 + 9;
int phi[N];
void totient() {
for (int i = 1; i < N; i++) phi[i] = i;
for (int i = 2; i < N; i++) {
if (phi[i] == i) {
for (int j = i; j < N; j += i) phi[j] -= phi[j] / i;
}
}
}
signed main(){
cin.tie(nullptr)->sync_with_stdio(false);
totient();
int n;
cin >> n;
vector<int>a(n+1);
for(int i = 1; i<=n; i++){
cin >> a[i];
}
DisjointSet ds;
ds.init(n+1);
for(int i = 1; i<=n; i++){
ds.Union(a[i],i);
}
set<int>s;
for(int i = 1; i<=n; i++){
s.insert(ds.find(i));
}
vector<int>factor(mxn);
vector<int>mx(mxn);
for(int i = 2; i<mxn; i++){
for(int j = i; j<mxn; j+=i){
if(!factor[j])factor[j] = i;
mx[j] = i;
}
}
vector<int>vals;
int extra = 0;
vector<int>dp(mxn);
for(int nxt: s){
map<int,int>hm;
int k = ds.sz[nxt];
if(k==1){
continue;
}
int cnt = 0;
while(k>1 && k%2==0){
k/=2;
cnt++;
}
extra = max(extra,cnt);
k = phi[k];
while(k>1){
hm[factor[k]]++;
k/=factor[k];
}
for(auto [a,b]: hm){
dp[a] = max(dp[a],b);
}
}
int ans = 1;
for(int i = 1; i<mxn; i++){
for(int j = 0; j<dp[i]; j++){
ans*=i;
ans%=mod;
}
}
ans+=extra;
ans%=mod;
cout << ans << '\n';
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 5ms
memory: 6188kb
input:
5 3 5 1 2 4
output:
3
result:
ok single line: '3'
Test #2:
score: 0
Accepted
time: 0ms
memory: 6200kb
input:
8 7 5 1 6 8 2 3 4
output:
4
result:
ok single line: '4'
Test #3:
score: 0
Accepted
time: 5ms
memory: 6332kb
input:
1 1
output:
1
result:
ok single line: '1'
Test #4:
score: -100
Wrong Answer
time: 11ms
memory: 8520kb
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:
200774942
result:
wrong answer 1st lines differ - expected: '216333199', found: '200774942'