QOJ.ac
QOJ
The 2nd Universal Cup Finals is coming! Check out our event page, schedule, and competition rules!
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#133515 | #4937. Permutation Transformation | whsyhyyh# | WA | 1ms | 3692kb | C++14 | 1.4kb | 2023-08-02 10:29:43 | 2023-08-02 10:29:45 |
Judging History
answer
#pragma GCC optimize("Ofast","unroll-loops","omit-frame-pointer","inline")
#pragma GCC option("arch=native","tune=native","no-zero-upper")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2")
#pragma GCC optimize(3)
#include<bits/stdc++.h>
#define N 100010
#define LL long long
#define mod 998244353
#define rep(i,l,r) for(int i=l;i<=r;i++)
#define drep(i,r,l) for(int i=r;i>=l;i--)
using namespace std;
int rd() {
int res=0,f=1;char ch=getchar();
while(ch<'0'||ch>'9') {if(ch=='-') f*=-1;ch=getchar();}
while(ch>='0'&&ch<='9') res=(res<<1)+(res<<3)+(ch^48),ch=getchar();
return res*f;
}
int n,a[N],b[N],m;
bool vis[N];int pri[N],tot,pre[N],mx[N];
void Deal_first() {
rep(i,2,n) {
if(!vis[i]) pri[++tot]=i,pre[i]=tot;
for(int j=1;j<=tot&&i*pri[j]<=n;j++) {
vis[i*pri[j]]=1,pre[i*pri[j]]=j;
if(i%pri[j]==0) break;
}
}
}
void dfs(int x,int cnt) {
vis[x]=1;
if(!vis[a[x]]) dfs(a[x],cnt+1);
else b[++m]=cnt;
}
int main() {
n=rd();
Deal_first();
rep(i,1,n) a[i]=rd(),vis[i]=0;
rep(i,1,n) if(!vis[i]) dfs(i,1);
LL ans=1;
rep(i,1,m) {
if(b[i]&1) {
b[i]--;
while(b[i]>1) {
int tmp=pre[b[i]],cnt=0;
while(b[i]%pri[tmp]==0) b[i]/=pri[tmp],cnt++;
mx[tmp]=max(mx[tmp],cnt);
}
}
else ans=max(ans,1ll*b[i]-1);
}
LL res=1;
rep(i,1,tot) {
while(mx[i]--) res=res*pri[i]%mod;
}
printf("%lld",(res+ans)%mod);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3580kb
input:
5 3 5 1 2 4
output:
3
result:
ok single line: '3'
Test #2:
score: -100
Wrong Answer
time: 1ms
memory: 3692kb
input:
8 7 5 1 6 8 2 3 4
output:
5
result:
wrong answer 1st lines differ - expected: '4', found: '5'