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 "gondola.h"
#include<bits/stdc++.h>
using namespace std;
int valid(int n, int inputSeq[]){
for(int i=0;i<n;i++) inputSeq[i]--;
map<int,int> used;
int pos0 = -1;
for(int i=0;i<n;i++){
if(inputSeq[i] < n) pos0 = (i - inputSeq[i] + n) % n;
if(used[inputSeq[i]]) return 0;
used[inputSeq[i]] = 1;
}
if(pos0 == -1) return 1;
for(int i=0;i<n;i++){
if(inputSeq[i] < n){
if((pos0 + inputSeq[i]) % n != i) return 0;
}
}
return 1;
}
//----------------------
int replacement(int n, int gondolaSeq[], int replacementSeq[]){
vector<int> pos(250000, -1);
int mx = 0;
for(int i=0;i<n;i++) gondolaSeq[i]--, pos[gondolaSeq[i]] = i, mx = max(mx, gondolaSeq[i]);
int pos0 = 0, ans = 0;
for(int i=0;i<n;i++){
if(gondolaSeq[i] < n) pos0 = (i - gondolaSeq[i] + n) % n;
}
/* for(int i=0;i<2*n;i++) cout<<pos[i]<<'\n'; */
int prev = n;
for(int i=n;i<=mx;i++){
if(pos[i] != -1){
replacementSeq[ans++] = (pos[i] - pos0 + n) % n + 1;
for(int j=prev;j<i;j++) replacementSeq[ans++] = j + 1;
prev = i+1;
}
}
return ans;
}
#define ll long long
//----------------------
const ll mod = 1000000009;
ll power(ll x,ll y){
ll ans = 1, mul = x;
while(y){
if(y&1) ans = ans * mul % mod;
mul = mul * mul % mod;
y>>=1;
}
return ans;
}
int countReplacement(int n, int inputSeq[]){
if(!valid(n, inputSeq)) return 0;
for(int i=0;i<n;i++) inputSeq[i]++;
set<ll> s;
bool has = 0;
for(int i=0;i<n;i++){
s.insert(inputSeq[i]);
if(inputSeq[i] <= n) has = 1;
}
while(!s.empty() && *s.begin() <= n) s.erase(s.begin());
ll prev = n+1, ans = 1;
if(!has) ans = n;
while(!s.empty()){
ll x = *s.begin(), siz = s.size();
s.erase(s.begin());
ans = ans * power(siz, x-prev) % mod;
prev = x + 1;
}
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... |