#include "gondola.h"
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 250005;
const int mod=1e9+9;
ll power(ll a,ll n){
ll res=1;
while(n){
if(n&1) res=(1LL*res*a)%mod;
a=(a*a)%mod;
n>>=1;
}
return res;
}
map<int,int> mp;
int valid(int n, vector<int> p){
int start=-1;
for(int i=0;i<n;i++){
if(mp[p[i]]) return 0;
mp[p[i]]=1;
if(p[i]<=n){
int curr=(i-p[i]+n)%n;
if(start==-1) start=curr;
else if(start!=curr) return 0;
}
}
return 1;
}
// --------------------------------------------------------------
int replacement(int n, vector<int> p, vector<int> res){
int start=0;
deque<int> arr(n);
for(int i=0; i < n;i++){
if(p[i]<=n) start=(i-p[i]+n)%n;
arr[i]=p[i];
}
while(start){
start--;
int temp=arr.front();
arr.pop_front();
arr.push_back(temp);
}
vector<pair<int,int>> curr;
for(int i=0; i < n;i++){
if(arr[i]>n) curr.push_back({arr[i],i});
}
int size=0;
sort(curr.begin(),curr.end());
res.resize(curr.size());
int del=n;
for(auto [val,i] : curr){
res[size++]=i+1;del++;
while(del<val) res[size++]=del++;
}
return size;
}
// --------------------------------------------------------------
int countReplacement(int n, vector<int> p){
if(!valid(n,p)) return 0;
vector<int> arr;
int res=1,a=n;
for(int i=0;i<n;i++){
if(p[i]<=n) a--;
else arr.push_back(p[i]);
}
if(a==n) res=n;
int pre=n;
sort(arr.begin(),arr.end());
for(int x:arr){
res=ll(res)*power(a,x-pre-1)%mod;
pre=x;
a--;
}
return res;
}
Compilation message
/usr/bin/ld: /tmp/ccGSStQZ.o: in function `main':
grader.cpp:(.text.startup+0xb6): undefined reference to `valid'
/usr/bin/ld: grader.cpp:(.text.startup+0x108): undefined reference to `countReplacement'
/usr/bin/ld: grader.cpp:(.text.startup+0x132): undefined reference to `replacement'
collect2: error: ld returned 1 exit status