#include <stdio.h>
#include <assert.h>
#include "gondola.h"
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target ("avx2")
#include <bits/stdc++.h>
using namespace std;
typedef long long lo;
typedef pair< lo,lo > PII;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define FOR for(int i=1;i<=n;i++)
#define mid ((start+end)/2)
#define ort ((bas+son)/2)
const lo MAX = -1000000000000000000;
const lo MIN = 1000000000000000000;
const lo inf = 1000000000000000000;
const lo KOK = 100000;
const lo LOG = 30;
const lo li = 5000005;
lo mod = 1000000009;
int m,k,flag,t,vis[li],visit[li],c[li];
int cev;
string s;
vector<lo> v;
lo mul(lo x,lo y){
return (x%mod)*(y%mod)%mod;
}
lo fp(lo x,lo y){
if(y==0)return 1;
if(y==1)return x;
lo q=fp(x,y/2);
q=mul(q,q);
if(y%2)q=mul(q,x);
return q;
}
int valid(int n, int a[]){
int con=-1;
for(int i=0;i<n;i++){
if(a[i]<=n && con==-1){
if(i>=a[i]-1)con=i-(a[i]-1);
else con=i+1+(n-a[i]);
}
else if(a[i]<=n){
int con1=0;
if(i>=a[i]-1)con1=i-(a[i]-1);
else con1=i+1+(n-a[i]);
if(con1!=con)flag=1;
}
}
sort(a,a+n);
for(int i=1;i<n;i++){
if(a[i]==a[i-1])flag=1;
}
if(flag)return 0;
return 1;
}
//----------------------
int replacement(int n, int a[], int replacementSequence[]){
int con=-1;
for(int i=0;i<n;i++){
if(a[i]<=n && con==-1){
if(i>=a[i]-1)con=i-(a[i]-1);
else con=i+1+(n-a[i]);
}
}
FOR v.pb(i);
vector<lo> vec=v;
//~ for(int i=0;i<n;i++){
//~ int at=i-con;
//~ if(at<0)at+=n;
//~ v[at]=vec[i];
//~ }
for(int i=0;i<n;i++){
c[i]=a[i];
}
if(~con){
for(int i=0;i<n;i++){
int at=i-con;
if(at<0)at+=n;
a[at]=c[i];
}
}
for(int i=0;i<n;i++){
//~ if(a[i]<=n){visit[i]=1;continue;}
vis[a[i]]=(i);
}
int maxi=n;
int len=0;
for(int i=0;i<(int)v.size();i++){
//~ if(visit[i]==1)continue;
if(v[i]==a[i])continue;
//~ cout<<v[i]<<" : : "<<b[i]<<endl;
//~ if(vis[i]==)
if(vis[maxi+1]==0){
replacementSequence[len++]=v[i];
v[i]=++maxi;
i--;
}
else{
replacementSequence[len++]=v[vis[maxi+1]];
visit[vis[maxi+1]]=1;
v[vis[maxi+1]]=maxi+1;
maxi++;
i--;
}
}
return len;
}
int countReplacement(int n, int a[]){
int con=-1;
for(int i=0;i<n;i++){
if(a[i]<=n && con==-1){
//~ cout<<"**\n";
if(i>=a[i]-1)con=i-(a[i]-1);
else con=i+1+(n-a[i]);
}
}
lo carp=valid(n,a);
if(con==-1)carp=mul(carp,n);
cev=0;
//~ lo mx=0;
for(int i=0;i<n;i++){
if(a[i]>n)cev++;
//~ mx=max(mx,(lo)a[i]);
//~ vis[a[i]]=1;
}
//~ cout<<cev<<endl;
sort(a,a+n);
if(a[0]>n)v.pb(a[0]-n-1);
for(int i=1;i<n;i++){
if(a[i]<=n)continue;
v.pb(max(0,a[i]-max(n,a[i-1])-1));
}
for(int i=0;i<(int)v.size();i++){
carp=mul(carp,fp(cev,v[i]));
cev--;
}
//~ cout<<cev<<endl;
//~ carp--;
return carp;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
4 ms |
384 KB |
Output is correct |
4 |
Correct |
4 ms |
384 KB |
Output is correct |
5 |
Correct |
4 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
4 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
4 ms |
384 KB |
Output is correct |
6 |
Correct |
12 ms |
512 KB |
Output is correct |
7 |
Correct |
22 ms |
640 KB |
Output is correct |
8 |
Correct |
17 ms |
640 KB |
Output is correct |
9 |
Correct |
9 ms |
384 KB |
Output is correct |
10 |
Correct |
21 ms |
640 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
4 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
4 ms |
384 KB |
Output is correct |
6 |
Correct |
11 ms |
512 KB |
Output is correct |
7 |
Correct |
22 ms |
640 KB |
Output is correct |
8 |
Correct |
16 ms |
640 KB |
Output is correct |
9 |
Correct |
9 ms |
384 KB |
Output is correct |
10 |
Correct |
21 ms |
640 KB |
Output is correct |
11 |
Correct |
5 ms |
384 KB |
Output is correct |
12 |
Correct |
5 ms |
384 KB |
Output is correct |
13 |
Correct |
12 ms |
512 KB |
Output is correct |
14 |
Correct |
4 ms |
384 KB |
Output is correct |
15 |
Correct |
24 ms |
640 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
4 ms |
384 KB |
Output is correct |
4 |
Correct |
4 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
384 KB |
Output is correct |
7 |
Correct |
5 ms |
384 KB |
Output is correct |
8 |
Correct |
5 ms |
384 KB |
Output is correct |
9 |
Correct |
5 ms |
384 KB |
Output is correct |
10 |
Correct |
5 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
4 ms |
384 KB |
Output is correct |
5 |
Correct |
4 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
384 KB |
Output is correct |
7 |
Correct |
6 ms |
384 KB |
Output is correct |
8 |
Correct |
5 ms |
384 KB |
Output is correct |
9 |
Correct |
5 ms |
384 KB |
Output is correct |
10 |
Correct |
5 ms |
384 KB |
Output is correct |
11 |
Correct |
17 ms |
2676 KB |
Output is correct |
12 |
Correct |
18 ms |
2932 KB |
Output is correct |
13 |
Correct |
18 ms |
2280 KB |
Output is correct |
14 |
Correct |
16 ms |
2548 KB |
Output is correct |
15 |
Correct |
25 ms |
3068 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
256 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
4 ms |
384 KB |
Output is correct |
6 |
Correct |
4 ms |
384 KB |
Output is correct |
7 |
Correct |
4 ms |
384 KB |
Output is correct |
8 |
Correct |
4 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
4 ms |
256 KB |
Output is correct |
6 |
Correct |
5 ms |
384 KB |
Output is correct |
7 |
Correct |
4 ms |
256 KB |
Output is correct |
8 |
Correct |
5 ms |
384 KB |
Output is correct |
9 |
Correct |
24 ms |
1276 KB |
Output is correct |
10 |
Correct |
20 ms |
1276 KB |
Output is correct |
11 |
Correct |
11 ms |
800 KB |
Output is correct |
12 |
Correct |
12 ms |
896 KB |
Output is correct |
13 |
Correct |
6 ms |
512 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
4 ms |
384 KB |
Output is correct |
5 |
Correct |
4 ms |
384 KB |
Output is correct |
6 |
Correct |
4 ms |
384 KB |
Output is correct |
7 |
Correct |
5 ms |
384 KB |
Output is correct |
8 |
Correct |
5 ms |
384 KB |
Output is correct |
9 |
Correct |
24 ms |
1268 KB |
Output is correct |
10 |
Correct |
21 ms |
1276 KB |
Output is correct |
11 |
Correct |
10 ms |
768 KB |
Output is correct |
12 |
Correct |
12 ms |
768 KB |
Output is correct |
13 |
Correct |
6 ms |
512 KB |
Output is correct |
14 |
Correct |
31 ms |
1776 KB |
Output is correct |
15 |
Correct |
34 ms |
2808 KB |
Output is correct |
16 |
Correct |
10 ms |
896 KB |
Output is correct |
17 |
Correct |
24 ms |
1780 KB |
Output is correct |
18 |
Correct |
15 ms |
1452 KB |
Output is correct |