#include "gondola.h"
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=2.5e5+10;
set<int> imam;
int valid(int n, int inputSeq[]){
int tren=-1;
for(int i=0;i<n;i++){
if(imam.find(inputSeq[i])!=imam.end()) return 0;
imam.emplace(inputSeq[i]);
if(inputSeq[i]>n){
if(tren!=-1) tren++;
if(tren>n) tren=1;
continue;
}
if(tren==-1) tren=inputSeq[i];
else{
if(inputSeq[i]!=tren) return 0;
}
tren++;
if(tren>n) tren=1;
}
return 1;
}
//----------------------
int treba[maxn];
int replacement(int n, int gondolaSeq[], int replacementSeq[]){
int l=0;
int tren=-1;
int maxi=INT_MIN;
int mini=INT_MAX;
for(int i=0;i<n;i++) maxi=max(maxi,gondolaSeq[i]);
for(int i=0;i<n;i++) mini=min(mini,gondolaSeq[i]);
int gde=-1;
if(mini>n) tren=1;
for(int j=0;j<2*n;j++){
int i=j%n;
if(gondolaSeq[i]>n){
if(tren!=-1){
if(gondolaSeq[i]==maxi) gde=tren;
treba[gondolaSeq[i]]=tren;
tren++;
if(tren>n) tren=1;
}
continue;
}
if(tren==-1) tren=gondolaSeq[i];
tren++;
if(tren>n) tren=1;
}
for(int i=n+1;i<=maxi;i++){
if(treba[i]!=0){
if(i==maxi) replacementSeq[l++]=gde;
else replacementSeq[l++]=treba[i];
}else{
replacementSeq[l++]=gde;
gde=i;
}
}
return l;
}
//----------------------
const int mod=1e9+9;
int mul(int a,int b){
if(ll(a)*ll(b)>=mod) return ll(a)*ll(b)%mod;
return a*b;
}
int pwr(int a,int b){
int ret=1;
while(b){
if(b&1) ret=mul(ret,a);
b>>=1;
a=mul(a,a);
}
return ret;
}
int countReplacement(int n, int inputSeq[]){
int res=1;
if(!valid(n,inputSeq)) return 0;
int mini=INT_MAX;
for(int i=0;i<n;i++) mini=min(mini,inputSeq[i]);
int klk=0;
set<int> koji;
for(int i=0;i<n;i++){
if(inputSeq[i]>n){
klk++;
koji.emplace(inputSeq[i]);
}
}
int prosli=n;
for(auto i:koji){
res=mul(res,pwr(klk,i-prosli-1));
klk--;
prosli=i;
}
if(mini>n) res=mul(res,n);
return res;
}
/*
9
4
1 2 7 6
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
15 ms |
2124 KB |
Output is correct |
7 |
Correct |
10 ms |
652 KB |
Output is correct |
8 |
Correct |
31 ms |
3804 KB |
Output is correct |
9 |
Correct |
9 ms |
1484 KB |
Output is correct |
10 |
Correct |
39 ms |
4472 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
15 ms |
2120 KB |
Output is correct |
7 |
Correct |
10 ms |
588 KB |
Output is correct |
8 |
Correct |
31 ms |
3900 KB |
Output is correct |
9 |
Correct |
11 ms |
1484 KB |
Output is correct |
10 |
Correct |
44 ms |
4504 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
6 ms |
460 KB |
Output is correct |
14 |
Correct |
0 ms |
204 KB |
Output is correct |
15 |
Correct |
10 ms |
588 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
10 ms |
588 KB |
Output is correct |
12 |
Correct |
11 ms |
588 KB |
Output is correct |
13 |
Correct |
14 ms |
1400 KB |
Output is correct |
14 |
Correct |
10 ms |
588 KB |
Output is correct |
15 |
Correct |
21 ms |
2636 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
9 |
Correct |
57 ms |
6728 KB |
Output is correct |
10 |
Correct |
45 ms |
5404 KB |
Output is correct |
11 |
Correct |
16 ms |
2380 KB |
Output is correct |
12 |
Correct |
26 ms |
2848 KB |
Output is correct |
13 |
Correct |
5 ms |
844 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
9 |
Correct |
55 ms |
6612 KB |
Output is correct |
10 |
Correct |
43 ms |
5324 KB |
Output is correct |
11 |
Correct |
20 ms |
2380 KB |
Output is correct |
12 |
Correct |
25 ms |
2940 KB |
Output is correct |
13 |
Correct |
4 ms |
844 KB |
Output is correct |
14 |
Correct |
83 ms |
8524 KB |
Output is correct |
15 |
Correct |
84 ms |
9524 KB |
Output is correct |
16 |
Correct |
13 ms |
2024 KB |
Output is correct |
17 |
Correct |
53 ms |
6488 KB |
Output is correct |
18 |
Correct |
27 ms |
3780 KB |
Output is correct |