This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <stdio.h>
#include <assert.h>
#include "gondola.h"
//~ int gondolaSequence[100001];
//~ int replacementSequence[250001];
#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 = 500005;
const lo mod = 1000000009;
int m,k,flag,t,vis[li],visit[li],c[li];
int cev;
string s;
vector<int> v;
inline lo mul(lo x,lo y){
return (x%mod)*(y%mod)%mod;
}
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<int> 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){
if(i>=a[i]-1)con=i-(a[i]-1);
else con=i+1+(n-a[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];
}
}
cev=0;
lo mx=0;
for(int i=0;i<n;i++){
if(a[i]!=i+1)cev++;
mx=max(mx,(lo)a[i]);
vis[a[i]]=1;
}
lo carp=1;
if(con==-1)carp=mul(carp,n);
for(int i=n+1;i<=mx;i++){
if(vis[i]){cev--;continue;}
//~ cout<<cev<<endl;
carp=mul(carp,cev);
}
if(valid(n,a)==0)carp=0;
return carp;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |