#include "gondola.h"
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define pll pair <ll,ll>
#define fi first
#define se second
#define MP make_pair
#define sz(a) (ll((a).size()))
#define BIT(mask,i) (((mask) >> (i))&1)
#define MASK(i) (1LL << (i))
int valid(int n, int a[])
{
set <ll> s;
for (ll i = 0,expected = -n;i < n;i ++,expected=expected+1>n?1:expected+1){
if (s.insert(a[i]).se==0)return 0;
if (a[i] > n)continue;
if (expected < 0)expected = a[i];
if (expected != a[i])return 0;
}
return 1;
}
//----------------------
int replacement(int n, int a[], int ans[])
{
ll ptr = 0;
vector <ll> b(n);
iota(b.begin(),b.end(),1);
for (ll i = 0;i < n;i ++){
if (a[i] <= n){
b[i] = a[i];
for (ll j = i + 1;j < n;j ++){
b[j] = b[j-1]+1;
if (b[j] > n)b[j] = 1;
}
for (ll j = i - 1;j >= 0;j--){
b[j] = b[j+1]-1;
if (b[j]==0)b[j] = n;
}
break;
}
}
vector <pll> all;
for (ll i = 0;i < n;i ++){
if (a[i] > n){
all.push_back(MP(a[i],b[i]));
}
}
sort(all.begin(),all.end());
ll last = n;
for (auto x:all){
last++;
ans[ptr++]=x.se;
for (ll i = last+1;i<=x.fi;i++)ans[ptr++]=i-1;
last = x.fi;
}
return ptr;
}
//----------------------
const ll MOD = 1e9 + 9;
ll p(ll x,ll y){
ll res = 1;
// cout<<x<<' '<<y<<'\n';
for (;y;y>>=1,x=x*x%MOD)if (y&1)res=res*x%MOD;
return res;
}
int countReplacement(int n, int a[])
{
if (!valid(n,a))return 0;
bool ok = 0;
vector <ll> all;
for (ll i = 0;i < n;i ++){
if (a[i] <= n){
ok = 1;
}
else{
all.push_back(a[i]);
}
}
ll res = 1;
if (!ok){
for (ll i = 1;i <= n; i++)res = res*i%MOD;
}
sort(all.begin(),all.end());
ll last = n;
for (ll j = 0;j < sz(all);j ++){
// cout<<sz(all)-j<<' '<<all[j]-last-1<<' '<<p(sz(all)-j,all[j]-last-1)<<'\n';
res = res*p(sz(all)-j,all[j]-last-1)%MOD;
last = all[j];
}
return res;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
416 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
11 ms |
2468 KB |
Output is correct |
7 |
Correct |
5 ms |
604 KB |
Output is correct |
8 |
Correct |
12 ms |
4032 KB |
Output is correct |
9 |
Correct |
4 ms |
1372 KB |
Output is correct |
10 |
Correct |
16 ms |
4568 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
11 ms |
2140 KB |
Output is correct |
7 |
Correct |
6 ms |
604 KB |
Output is correct |
8 |
Correct |
12 ms |
3932 KB |
Output is correct |
9 |
Correct |
4 ms |
1624 KB |
Output is correct |
10 |
Correct |
17 ms |
4664 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
3 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
5 ms |
568 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
392 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
356 KB |
Output is correct |
11 |
Correct |
7 ms |
1372 KB |
Output is correct |
12 |
Correct |
5 ms |
1372 KB |
Output is correct |
13 |
Correct |
8 ms |
1660 KB |
Output is correct |
14 |
Correct |
5 ms |
1116 KB |
Output is correct |
15 |
Correct |
13 ms |
2376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
444 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
440 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
344 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
444 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
22 ms |
4508 KB |
Output is correct |
10 |
Correct |
17 ms |
3932 KB |
Output is correct |
11 |
Correct |
8 ms |
1628 KB |
Output is correct |
12 |
Correct |
9 ms |
1884 KB |
Output is correct |
13 |
Incorrect |
2 ms |
604 KB |
Output isn't correct |
14 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
34 ms |
4484 KB |
Output is correct |
10 |
Correct |
18 ms |
3796 KB |
Output is correct |
11 |
Correct |
6 ms |
1628 KB |
Output is correct |
12 |
Correct |
7 ms |
1884 KB |
Output is correct |
13 |
Incorrect |
2 ms |
600 KB |
Output isn't correct |
14 |
Halted |
0 ms |
0 KB |
- |