QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#133525 | #4937. Permutation Transformation | nameless_story# | TL | 1ms | 5580kb | C++20 | 1.7kb | 2023-08-02 10:40:16 | 2023-08-02 10:40:20 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define N 120000
const int mod=998244353;
int f[N],vis[N],ok[N],gg[N],g[N],h[N];
void go(vector<int> &p){
map<vector<int>,int> dd;
int num=0;
while (1){
if (dd[p]) break;
++num;
dd[p]=1;
auto q=p;
for (int i=0;i<q.size();++i){
p[i]=q[q[i]-1];
}
for (int x:p) cerr<<x<<' '; cerr<<endl;
}
cerr<<num<<endl;
}
int main(){
ios::sync_with_stdio(0); cin.tie(0);
int n; cin>>n;
g[1]=1;
for (int i=2;i<=n;++i){
g[i]=i&1?0:g[i/2];
if (i&1){
int x=2;
while (x!=1){
x=x*2%i;
++g[i];
}
++g[i];
}
h[i]=i&1?0:h[i/2]+1;
}
for (int i=1;i<=n;++i){
int x; cin>>x;
// int x=p[i-1]; cerr<<x<<',';
f[i]=x;
}
// go(p);
long long ans=1;
int tmp=0;
for (int i=1;i<=n;++i){
if (vis[i]) continue;
int x=i;
int cnt=0;
while (!vis[x]){
vis[x]=1;
++cnt;
x=f[x];
}
tmp=max(tmp,h[cnt]);
// cerr<<cnt<<endl;
ok[g[cnt]]=1;
}
for (int i=2;i<=n;++i){
if (gg[i]) continue;
for (int j=i*2;j<=n;j+=i){
gg[j]=1;
if (ok[j]){
int x=j,cnt=0;
while (x%i==0){
++cnt;
x/=i;
}
ok[i]=max(ok[i],cnt);
}
}
for (;ok[i];--ok[i]) ans=ans*i%mod;
}
cout<<(ans+tmp)%mod<<'\n';
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3540kb
input:
5 3 5 1 2 4
output:
3
result:
ok single line: '3'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3472kb
input:
8 7 5 1 6 8 2 3 4
output:
4
result:
ok single line: '4'
Test #3:
score: 0
Accepted
time: 1ms
memory: 5580kb
input:
1 1
output:
1
result:
ok single line: '1'
Test #4:
score: -100
Time Limit Exceeded
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...