QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#133594 | #4937. Permutation Transformation | Vengeful_Spirit# | WA | 11ms | 26768kb | C++20 | 1.6kb | 2023-08-02 11:37:04 | 2023-08-02 11:37:08 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int N=1e6+5;
#define int long long
const int mo=998244353;
int vs[N], pr[N], sz[N], nm[N];
void init() {
for(int i = 2; i < N; ++i) {
if(!vs[i]) pr[++pr[0]] = i, vs[i] = i, nm[i] = pr[0];
for(int j = 1; j <= pr[0] && i * pr[j] < N; ++j) {
vs[i * pr[j]] = pr[j];
if(i % pr[j] == 0) break;
}
}
}
int qpow(int a,int b){
int res=1;
for(;b;b>>=1,a=a*a%mo){
if(b&1){
res=res*a%mo;
}
}
return res;
}
int vis[N],c[N],a[N];
void dfs(int x,int &cnt){
vis[x]=1;
cnt++;
if(!vis[a[x]])
dfs(a[x],cnt);
}
mt19937 rnd(0);
signed main(){
init();
int n;
scanf("%lld",&n);
for(int i=1;i<=n;i++){
a[i]=i;
}
for(int i=1;i<=n;i++){
scanf("%lld",&a[i]);
}
int cnt=0;
for(int i=1;i<=n;i++){
if(!vis[i])dfs(i,c[++cnt]);
}
int ans=0,gc=-1,mul=1;
for(int i=1;i<=cnt;i++){
int res=0;
while(c[i]%2==0){
c[i]/=2;
res++;
}
ans=max(ans,res);
// cout<<c[i]<<endl;
if(c[i]!=1){
// if(gc==-1)gc=mul=c[i]-1;
// else {gc=gcd(gc,c[i]-1);
// mul=mul*(c[i]-1)%mo;
// mul=mul*qpow(gc,mo-2)%mo;
// }
int x = c[i] - 1;
// cerr << x << " ";
for(; vs[x]; ) {
int pos = 0, tmp = vs[x];
for(; vs[x] == tmp; x /= vs[x]) ++pos;
// cerr << tmp << " " << pos << "\n";
sz[nm[tmp]] = max(sz[nm[tmp]], pos);
}
// cout<<gc<<' '<<mul<<endl;
}
}
for(int i = 1; i <= pr[0]; ++i) mul = 1ll * mul * qpow(pr[i], sz[i]) % mo;
ans = (ans + mul) % mo;
printf("%lld\n",ans);
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 10ms
memory: 24100kb
input:
5 3 5 1 2 4
output:
3
result:
ok single line: '3'
Test #2:
score: 0
Accepted
time: 3ms
memory: 22328kb
input:
8 7 5 1 6 8 2 3 4
output:
4
result:
ok single line: '4'
Test #3:
score: 0
Accepted
time: 10ms
memory: 20384kb
input:
1 1
output:
1
result:
ok single line: '1'
Test #4:
score: -100
Wrong Answer
time: 11ms
memory: 26768kb
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'