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 <bits/stdc++.h>
#include "gondola.h"
using namespace std;
typedef long long ll;
#define X first
#define Y second
const int MAXN = 3e5 + 10;
const int MOD = 1e9 + 9;
ll poww(ll x , ll y){
ll ans = 1;
for(; y ; y >>= 1 , x = x * x % MOD) if(y & 1) ans = ans * x % MOD;
return ans;
}
int fact[MAXN] , inv[MAXN] , res[MAXN];
map<int , int> mark;
int valid(int n, int inputSeq[]){
int ind = -1;
for(int i = 0 ; i < n ; i++){
if(mark[inputSeq[i]]) return 0;
mark[inputSeq[i]] = 1;
if(inputSeq[i] <= n) ind = i;
}
if(ind == -1){
for(int i = 0 ; i < n ; i++) res[i] = i + 1;
return 1;
}
for(int i = 0 ; i < n ; i++){
res[(ind + i) % n] = inputSeq[ind] + i;
if(res[(ind + i) % n] > n) res[(ind + i) % n] -= n;
}
for(int i = 0 ; i < n ; i++){
if(inputSeq[i] <= n && res[i] != inputSeq[i]) return 0;
}
return 1;
}
//----------------------
int replacement(int n, int gondolaSeq[], int replacementSeq[]){
if(valid(n , gondolaSeq) == 0) return -1;
vector<pair<int , int>> vec; int len = 0;
for(int i = 0 ; i < n ; i++){
if(gondolaSeq[i] > n) vec.push_back({gondolaSeq[i] , res[i]});
}
sort(vec.begin() , vec.end());
int prv = n;
for(auto &i : vec){
replacementSeq[len++] = i.Y;
for(int j = prv + 1 ; j < i.X ; j++) replacementSeq[len++] = j;
prv = i.X;
}
return len;
}
//----------------------
int countReplacement(int n, int inputSeq[]){
if(valid(n , inputSeq) == 0) return 0;
int k = 0; vector<int> vec;
for(int i = 0 ; i < n ; i++){
if(inputSeq[i] > n){
vec.push_back(inputSeq[i]); k++;
}
}
vec.push_back(n);
sort(vec.begin() , vec.end());
ll ans = 1;
for(int i = 0 ; i < k ; i++){
ans = ans * poww(k - i , vec[i + 1] - vec[i] - 1) % MOD;
}
return ans;
}
# | 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... |