QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#459022 | #8835. Goodman | ucup-team3659# | WA | 1ms | 7776kb | C++17 | 768b | 2024-06-29 21:22:47 | 2024-06-29 21:22:48 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
int a[1000005],p[1000005],ans[1000005];
bool f[1000005];
void test()
{
int n;
cin>>n;
for(int i=1;i<=n;i++)
f[i]=0;
for(int i=1;i<=n;i++)
cin>>a[i],p[a[i]]=i;
int cnt=0;
for(int i=1;i<=n;i++)
{
if(f[i])
continue;
int num=0;
while(!f[i])
{
f[i]=1;
i=p[i];
num++;
}
for(int j=1;j<num;j++)
ans[cnt+j]=cnt+j+1;
ans[cnt+num]=cnt+1;
cnt+=num;
}
for(int i=1;i<=n;i++)
cout<<ans[i]<<" ";
cout<<"\n";
}
signed main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t;
cin>>t;
for(int i=1;i<=t;i++)
test();
}
/*
q*p^(-1)*q^(-1)=id
{1,6,2,5,3,4}*{6,5,4,3,2,1}*{1,3,5,6,4,2}={2,1,4,3,6,5}
q*p*q^{-1}[x]=y;
q[y]=p[q[x]]
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 7776kb
input:
2 4 1 2 3 4 6 6 5 4 3 2 1
output:
1 2 3 4 2 1 4 3 6 5
result:
wrong answer Jury found better answer than participant (test case 2)