結果
| 問題 | No.3441 Sort Permutation 2 |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-02-06 21:28:04 |
| 言語 | C++14 (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 162 ms / 2,000 ms |
| コード長 | 700 bytes |
| 記録 | |
| コンパイル時間 | 944 ms |
| コンパイル使用メモリ | 93,776 KB |
| 実行使用メモリ | 7,848 KB |
| 最終ジャッジ日時 | 2026-02-06 21:28:13 |
| 合計ジャッジ時間 | 6,240 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 41 |
ソースコード
#include<iostream>
#include<vector>
#include<algorithm>
#include<cassert>
using namespace std;
int gcd(int a,int b)
{
while(b)
{
int t=a%b;
a=b;
b=t;
}
return a;
}
int N,P[2<<17];
bool vis[2<<17];
int ans[2<<17];
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
cin>>N;
for(int i=1;i<=N;i++)cin>>P[i];
for(int i=1;i<=N;i++)if(!vis[i])
{
vector<int>U;
int u=i;
while(!vis[u])
{
vis[u]=true;
U.push_back(u);
u=P[u];
}
sort(U.begin(),U.end());
int g=0;
for(int j=1;j<U.size();j++)g=gcd(g,U[j]-U[j-1]);
for(int k=1;k*k<=g;k++)if(g%k==0)
{
ans[k]+=U.size()-1;
if(k*k<g)ans[g/k]+=U.size()-1;
}
}
for(int k=1;k<=N-1;k++)cout<<ans[k]<<"\n";
}