#include "gondola.h"
#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define fr first
#define sc second
long long d=-1,pwk,dv=1e9+9;
map<long long,bool> vtd;
pair<long long,long long> as[100069];
long long pw(long long x,long long y)
{
if(!y)
{
return 1;
}
pwk=pw(x,y/2);
pwk=pwk*pwk%dv;
if(y%2)
{
pwk=pwk*x%dv;
}
return pwk;
}
int valid(int n,int a[])
{
long long i,k;
for(i=0;i<n;i++)
{
if(vtd[a[i]])
{
return 0;
}
vtd[a[i]]=1;
if(a[i]<=n)
{
k=(a[i]+n-i-1)%n+1;
if(d+1&&k!=d)
{
return 0;
}
d=k;
}
}
return 1;
}
int replacement(int n,int a[],int sq[])
{
long long i,k=n,l,zs=0;
valid(n,a);
d+=2*(d==-1);
for(i=0;i<n;i++)
{
as[i]={a[i],i};
}
sort(as,as+n);
for(i=0;i<n;i++)
{
if(as[i].fr>n)
{
for(;k<as[i].fr;k++)
{
l=k;
if(k==n||(i&&k==as[i-1].fr))
{
l=(d+as[i].sc-1)%n+1;
}
sq[zs]=l;
zs++;
}
}
}
return zs;
}
int countReplacement(int n,int a[])
{
long long i,l=n,z=1;
if(!valid(n,a))
{
return 0;
}
if(d==-1)
{
z=z*n%dv;
}
sort(a,a+n);
for(i=0;i<n;i++)
{
if(a[i]>n)
{
z=z*pw(n-i,a[i]-l-1)%dv;
l=a[i];
}
}
return z;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
1 ms |
2392 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2648 KB |
Output is correct |
6 |
Correct |
12 ms |
5212 KB |
Output is correct |
7 |
Correct |
11 ms |
3164 KB |
Output is correct |
8 |
Correct |
24 ms |
7484 KB |
Output is correct |
9 |
Correct |
7 ms |
3932 KB |
Output is correct |
10 |
Correct |
30 ms |
8500 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
1 ms |
2392 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
11 ms |
5216 KB |
Output is correct |
7 |
Correct |
7 ms |
3208 KB |
Output is correct |
8 |
Correct |
26 ms |
7432 KB |
Output is correct |
9 |
Correct |
7 ms |
3932 KB |
Output is correct |
10 |
Correct |
28 ms |
8512 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
1 ms |
2400 KB |
Output is correct |
13 |
Correct |
4 ms |
2736 KB |
Output is correct |
14 |
Correct |
1 ms |
2400 KB |
Output is correct |
15 |
Correct |
8 ms |
3168 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2400 KB |
Output is correct |
2 |
Correct |
1 ms |
2408 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2400 KB |
Output is correct |
5 |
Correct |
1 ms |
2408 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2408 KB |
Output is correct |
2 |
Correct |
1 ms |
2504 KB |
Output is correct |
3 |
Correct |
1 ms |
2408 KB |
Output is correct |
4 |
Correct |
1 ms |
2408 KB |
Output is correct |
5 |
Correct |
1 ms |
2660 KB |
Output is correct |
6 |
Correct |
1 ms |
2408 KB |
Output is correct |
7 |
Correct |
1 ms |
2408 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2392 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2392 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
11 |
Correct |
28 ms |
8188 KB |
Output is correct |
12 |
Correct |
44 ms |
9112 KB |
Output is correct |
13 |
Correct |
23 ms |
5564 KB |
Output is correct |
14 |
Correct |
36 ms |
8212 KB |
Output is correct |
15 |
Correct |
21 ms |
4900 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2496 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2392 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2392 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
46 ms |
7636 KB |
Output is correct |
10 |
Correct |
27 ms |
6844 KB |
Output is correct |
11 |
Correct |
13 ms |
3932 KB |
Output is correct |
12 |
Correct |
14 ms |
4292 KB |
Output is correct |
13 |
Correct |
4 ms |
2908 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2480 KB |
Output is correct |
9 |
Correct |
34 ms |
7812 KB |
Output is correct |
10 |
Correct |
27 ms |
6732 KB |
Output is correct |
11 |
Correct |
10 ms |
3928 KB |
Output is correct |
12 |
Correct |
13 ms |
4444 KB |
Output is correct |
13 |
Correct |
3 ms |
2908 KB |
Output is correct |
14 |
Correct |
51 ms |
8788 KB |
Output is correct |
15 |
Correct |
54 ms |
9488 KB |
Output is correct |
16 |
Correct |
10 ms |
3648 KB |
Output is correct |
17 |
Correct |
34 ms |
7156 KB |
Output is correct |
18 |
Correct |
19 ms |
5012 KB |
Output is correct |