QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#41761 | #3836. So I'll Max Out My Constructive Algorithm Skills | zhangchi | WA | 3ms | 3796kb | C++ | 776b | 2022-08-01 09:29:23 | 2022-08-01 09:29:24 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
int n,Q,q,mod=0,p[100005],b[100005],ans[10000005],check=0,cur;
void trans(){
mod++;
int t=0,butt;
int B=b[1];
int next=p[1];
while(t<n){
butt=b[next];
b[next]=B;
B=butt;
next=p[next];
t++;
}
//for(int i=1;i<=n;i++){
// printf("%d",b[i]);
//}
//printf("\n");
}
int main(){
scanf("%d%d",&n,&Q);
for(int i=1;i<=n;i++){
scanf("%d",&p[i]);
b[i]=i;
ans[0]+=i*i;
}
trans();
for(int i=1;i<=n;i++){
ans[1]+=b[i]*i;
}
cur=1;
while(check==0){
trans();
cur++;
for(int i=1;i<=n;i++){
ans[cur]+=b[i]*i;
}
if(ans[cur]==ans[0]){
check=1;
mod=cur;
}
}
for(int i=1;i<=Q;i++){
scanf("%d",&q);
q=q%mod;
printf("%d\n",ans[q]);
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 3ms
memory: 3796kb
input:
1 2 4 3 2 1
output:
1 1
result:
wrong output format Unexpected end of file - int32 expected