#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define first X
#define second Y
#define eb emplace_back
#define ALL(i) i.begin(),i.end()
#define SZ(i) int(i.size())
#ifdef tmd
#define debug(...) fprintf(stderr,"#%d-(%s)=",__LINE__,#__VA_ARGS__);_do(__VA_ARGS__);
template<typename T> void _do (T &&x) {cerr<<x<<endl;}
template<typename T, typename ...S> void _do(T &&x, S &&...y) {cerr<<x<<",";_do(y...);}
template<typename IT> ostream &__printRng (ostream& os, IT bg, IT ed) {
for (IT it=bg; it!=ed; it++) {
if (it == bg) os << "{" << *it;
else os << "," << *it;
}
return os << "}";
}
template<typename T> ostream &operator << (ostream& os, const vector<T> &vec) {
return __printRng(os,ALL(vec));
}
#else
#define debug(...)
#endif
#include "gondola.h"
int lvalid(int n, int inputSeq[])
{
vector<int> sm;
set<int> val;
for (int i=0; i<n; i++) {
if (inputSeq[i] <= n) {
sm.push_back(inputSeq[i]);
}
val.insert(inputSeq[i]);
}
if (SZ(val) != n) return 0;
int st = min_element(ALL(sm)) - sm.begin();
for (int i=0; i<SZ(sm)-1; i++) {
if (sm[(st+i)%SZ(sm)] >= sm[(st+i+1)%SZ(sm)]) {
debug(i, st);
return 0;
}
}
return 1;
}
int valid(int n, int inputSeq[])
{
vector<int> sm;
set<int> val;
for (int i=0; i<n; i++) {
if (inputSeq[i] <= n) {
sm.push_back(inputSeq[i]);
val.insert(inputSeq[i]);
}
}
if (SZ(val) != n) return 0;
int st = min_element(ALL(sm)) - sm.begin();
for (int i=0; i<SZ(sm)-1; i++) {
if (inputSeq[(st+i)%SZ(sm)] >= inputSeq[(st+i+1)%SZ(sm)]) {
return 0;
}
}
return 1;
}
//----------------------
const int MAXN = 250005;
int replacement(int n, int gondolaSeq[], int rs[])
{
set<int> alive;
vector<int> fin, cur;
int off = 1;
for (int i=0; i<n; i++) {
fin.eb(gondolaSeq[i]);
if (fin.back() > n) alive.insert(i);
else off = (n+fin.back()-i) % n;
}
debug(off);
for (int i=0; i<n; i++) {
cur.eb((off + i - 1) % n + 1);
}
debug(cur);
int mx = *max_element(ALL(fin));
vector<int> pos(mx+1, -1);
for (int i=0; i<SZ(fin); i++) {
pos[fin[i]] = i;
}
int res = 0;
for (int i=n+1; i<=mx; i++) {
if (pos[i] == -1) {
int p = *alive.begin();
rs[res++] = cur[p];
cur[p] = i;
} else {
assert(alive.count(pos[i]));
alive.erase(pos[i]);
rs[res++] = cur[pos[i]];
cur[pos[i]] = i;
}
debug(cur);
}
return res;
}
//----------------------
const ll MOD = 1000000009;
ll mpow (ll bs, ll ep) {
ll ret = 1;
while (ep) {
if (ep&1) ret = ret * bs % MOD;
ep >>= 1;
bs = bs * bs % MOD;
}
return ret;
}
int countReplacement(int n, int inputSeq[])
{
if (lvalid(n, inputSeq) == 0) return 0;
int off = 1;
vector<int> fin;
int mul = n, alive = 0;
for (int i=0; i<n; i++) {
int x = inputSeq[i];
if (x > n) {
fin.eb(x);
}
if (x > n) alive++;
else mul = 1;
}
fin.eb(n);
sort(ALL(fin));
ll res = 1;
for (int i=1; i<SZ(fin); i++) {
int gap = fin[i] - fin[i-1];
res = res * mpow(alive, gap-1) % MOD;
alive--;
}
return res * mul % MOD;
}
Compilation message
gondola.cpp: In function 'int countReplacement(int, int*)':
gondola.cpp:133:9: warning: unused variable 'off' [-Wunused-variable]
133 | int off = 1;
| ^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
256 KB |
Output is correct |
3 |
Correct |
0 ms |
256 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
256 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
0 ms |
384 KB |
Output is correct |
6 |
Correct |
13 ms |
2428 KB |
Output is correct |
7 |
Correct |
34 ms |
4088 KB |
Output is correct |
8 |
Correct |
26 ms |
4212 KB |
Output is correct |
9 |
Correct |
8 ms |
1536 KB |
Output is correct |
10 |
Correct |
32 ms |
4848 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
256 KB |
Output is correct |
2 |
Correct |
1 ms |
324 KB |
Output is correct |
3 |
Correct |
1 ms |
256 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
0 ms |
256 KB |
Output is correct |
6 |
Correct |
13 ms |
2428 KB |
Output is correct |
7 |
Correct |
34 ms |
4080 KB |
Output is correct |
8 |
Correct |
26 ms |
4220 KB |
Output is correct |
9 |
Correct |
8 ms |
1536 KB |
Output is correct |
10 |
Correct |
30 ms |
4976 KB |
Output is correct |
11 |
Correct |
0 ms |
256 KB |
Output is correct |
12 |
Correct |
0 ms |
256 KB |
Output is correct |
13 |
Correct |
6 ms |
512 KB |
Output is correct |
14 |
Correct |
0 ms |
256 KB |
Output is correct |
15 |
Correct |
32 ms |
3964 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
256 KB |
Output is correct |
2 |
Correct |
0 ms |
256 KB |
Output is correct |
3 |
Correct |
0 ms |
256 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
256 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
0 ms |
256 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
2 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
256 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
256 KB |
Output is correct |
5 |
Correct |
1 ms |
256 KB |
Output is correct |
6 |
Correct |
0 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
2 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
13 ms |
1656 KB |
Output is correct |
12 |
Correct |
15 ms |
1912 KB |
Output is correct |
13 |
Correct |
36 ms |
3068 KB |
Output is correct |
14 |
Correct |
15 ms |
1656 KB |
Output is correct |
15 |
Correct |
35 ms |
3080 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
256 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
256 KB |
Output is correct |
2 |
Correct |
0 ms |
256 KB |
Output is correct |
3 |
Correct |
0 ms |
256 KB |
Output is correct |
4 |
Correct |
0 ms |
256 KB |
Output is correct |
5 |
Correct |
0 ms |
256 KB |
Output is correct |
6 |
Correct |
0 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
256 KB |
Output is correct |
8 |
Correct |
0 ms |
256 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
256 KB |
Output is correct |
2 |
Correct |
1 ms |
256 KB |
Output is correct |
3 |
Correct |
1 ms |
256 KB |
Output is correct |
4 |
Correct |
1 ms |
256 KB |
Output is correct |
5 |
Correct |
1 ms |
256 KB |
Output is correct |
6 |
Correct |
1 ms |
256 KB |
Output is correct |
7 |
Correct |
1 ms |
256 KB |
Output is correct |
8 |
Correct |
0 ms |
256 KB |
Output is correct |
9 |
Correct |
48 ms |
4088 KB |
Output is correct |
10 |
Correct |
33 ms |
3448 KB |
Output is correct |
11 |
Correct |
13 ms |
1408 KB |
Output is correct |
12 |
Correct |
16 ms |
1664 KB |
Output is correct |
13 |
Correct |
4 ms |
640 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
256 KB |
Output is correct |
4 |
Correct |
1 ms |
256 KB |
Output is correct |
5 |
Correct |
0 ms |
384 KB |
Output is correct |
6 |
Correct |
0 ms |
256 KB |
Output is correct |
7 |
Correct |
0 ms |
256 KB |
Output is correct |
8 |
Correct |
1 ms |
256 KB |
Output is correct |
9 |
Correct |
55 ms |
4088 KB |
Output is correct |
10 |
Correct |
42 ms |
3456 KB |
Output is correct |
11 |
Correct |
16 ms |
1408 KB |
Output is correct |
12 |
Correct |
16 ms |
1664 KB |
Output is correct |
13 |
Correct |
4 ms |
640 KB |
Output is correct |
14 |
Correct |
54 ms |
4600 KB |
Output is correct |
15 |
Correct |
67 ms |
5112 KB |
Output is correct |
16 |
Correct |
10 ms |
1152 KB |
Output is correct |
17 |
Correct |
43 ms |
3576 KB |
Output is correct |
18 |
Correct |
47 ms |
2168 KB |
Output is correct |