#include <bits/stdc++.h>
#include "gondola.h"
#define mp make_pair
#define mt make_tuple
#define ff first
#define ss second
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll INFL = (1LL<<62)-1;
const int INF = (1<<30)-1;
const int MAXN = 0;
const int MOD = 1e9 + 9;
int valid(int n, int v[]){
int cur = -1;
unordered_set<int> s;
for(int i = 0; i < n; i++){
if(s.count(v[i]))
return 0;
s.insert(v[i]);
if(cur==-1){
if(v[i] <= n)
cur = v[i];
}
if(cur!=-1){
if(v[i] <= n){
if(cur!=v[i])
return 0;
}
cur++;
if(cur==n+1)
cur-=n;
}
}
return 1;
}
int replacement(int n, int v[], int resp[]){
int vproper[n];
int refid = -1, refv;
int r;
map<int,int> m;
for(int i = 0; i < n; i++){
if(v[i] > n){
m.insert({v[i],i});
} else if(refid==-1){
refid = i;
refv = v[i]-1;
}
}
if(refid==-1){
refv = 0;
refid = 0;
}
refid-=refv;
for(int i = 0; i < n; i++){
vproper[i] = (i-refid+n)%n + 1;
}
int ptr = 0;
for(int i = n+1; i <=( m.empty() ? 0 : m.rbegin()->first); i++){
if(m.count(i)){
resp[ptr++] = vproper[m[i]];
vproper[m[i]] = i;
m.erase(i);
}else {
resp[ptr++] = vproper[m.rbegin()->second];
vproper[m.rbegin()->second] = i;
}
//cerr << (m.empty()) << endl;
}
return ptr;
}
inline long long power(ll a, ll b){
ll ret = 1;
while(b>0){
if(b&1){
ret *= a;
ret%=MOD;
}
a*=a;
a%=MOD;
b>>=1;
}
return ret;
}
int countReplacement(int n, int v[]){
if(!valid(n,v))
return 0;
set<int> s;
bool none = 1;
for(int i = 0; i < n; i++){
if(v[i] > n)
s.insert(v[i]);
else none = 0;
}
ll resp = 1;
int cur = n+1;
while(!s.empty()){
auto it = s.begin();
resp*= power(s.size(), *it-cur);
resp%=MOD;
cur = *it+1;
s.erase(it);
}
if(none){
resp*=n;
resp%= MOD;
}
return resp;
}
/*int main(){
int n;
cin >> n;
int v[n];
int v2[n];
for(int i = 0; i < n; i++)
cin >> v[i];
int a = replacement(n,v,v2);
//cout << a << '\n';
for(int i = 0; i < a; i++){
cout << v2[i] << ' ';
}
}*/
Compilation message
gondola.cpp: In function 'int replacement(int, int*, int*)':
gondola.cpp:43:9: warning: unused variable 'r' [-Wunused-variable]
43 | int r;
| ^
# |
Verdict |
Execution time |
Memory |
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 |
# |
Verdict |
Execution time |
Memory |
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 |
6 |
Correct |
9 ms |
2104 KB |
Output is correct |
7 |
Correct |
12 ms |
588 KB |
Output is correct |
8 |
Correct |
16 ms |
3928 KB |
Output is correct |
9 |
Correct |
5 ms |
1356 KB |
Output is correct |
10 |
Correct |
21 ms |
4180 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
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 |
6 |
Correct |
9 ms |
2036 KB |
Output is correct |
7 |
Correct |
11 ms |
588 KB |
Output is correct |
8 |
Correct |
17 ms |
3928 KB |
Output is correct |
9 |
Correct |
5 ms |
1356 KB |
Output is correct |
10 |
Correct |
19 ms |
4212 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
5 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
12 ms |
588 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
256 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 |
# |
Verdict |
Execution time |
Memory |
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 |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
2 ms |
436 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
2 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
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 |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
11 ms |
844 KB |
Output is correct |
12 |
Correct |
12 ms |
916 KB |
Output is correct |
13 |
Correct |
26 ms |
2544 KB |
Output is correct |
14 |
Correct |
11 ms |
844 KB |
Output is correct |
15 |
Correct |
31 ms |
2892 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
208 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
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 |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
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 |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
45 ms |
4036 KB |
Output is correct |
10 |
Correct |
36 ms |
3032 KB |
Output is correct |
11 |
Correct |
13 ms |
1396 KB |
Output is correct |
12 |
Correct |
16 ms |
1552 KB |
Output is correct |
13 |
Correct |
4 ms |
588 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
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 |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
41 ms |
3928 KB |
Output is correct |
10 |
Correct |
33 ms |
2904 KB |
Output is correct |
11 |
Correct |
14 ms |
1368 KB |
Output is correct |
12 |
Correct |
16 ms |
1668 KB |
Output is correct |
13 |
Correct |
4 ms |
588 KB |
Output is correct |
14 |
Correct |
58 ms |
5288 KB |
Output is correct |
15 |
Correct |
64 ms |
6012 KB |
Output is correct |
16 |
Correct |
11 ms |
1368 KB |
Output is correct |
17 |
Correct |
42 ms |
4568 KB |
Output is correct |
18 |
Correct |
28 ms |
2488 KB |
Output is correct |