#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#pragma GCC optimize("O3,unroll-loops")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define all(v) v.begin(), v.end()
#define pb push_back
#define ss second
#define ff first
#define vt vector
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef pair<int, int> pii;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
const int inf = 1e9;
const int mod = 1e9+9;
const int maxn = 1e5 + 1;
#include "gondola.h"
int valid(int n, int a[]){
set<int> s;
for(int i = 0; i < n; i++){
if(a[i] <= n){
int j = (i + 1) % n, o = a[i] % n + 1;
s.clear();
while(j != i){
if((a[j] <= n && a[j] != o) || s.find(a[j]) != s.end())return 0;
s.insert(a[j]);
j = (j + 1) % n;
o = o % n + 1;
}
return 1;
}
if(s.find(a[i]) != s.end())return 0;
s.insert(a[i]);
}
return 1;
}
int replacement(int n, int a[], int out[]){
pii b[n];
for(int i = 0; i < n; i++){
if(a[i] <= n){
int x = a[i] % n + 1, j = (i + 1) % n, o = 1;
while(j != i){
b[o] = {a[j], x};
x = x % n + 1;
j = (j + 1) % n;
o++;
}
break;
}
else if(i == n - 1){
for(int j = 0; j < n; j++)b[j] = {a[j], j + 1};
}
}
sort(b, b + n);
int x = b[n - 1].ff - n;
for(int i = n + 1, j = 0, o = 0; j < n; j++){
if(b[j].ff == b[j].ss)continue;
while(b[j].ff != b[j].ss){
out[o++] = b[j].ss;
b[j].ss = i;
i++;
}
}
return x;
}
int pw(int x, int y){
int ret = 1;
while(y){
if(y & 1)ret = 1ll * ret * x % mod;
x = 1ll * x * x % mod;
y >>= 1;
}
return ret;
}
int countReplacement(int n, int a[]){
set<int> s;
for(int i = 0; i < n; i++){
if(a[i] <= n){
int j = (i + 1) % n, o = a[i] % n + 1;
s.clear();
while(j != i){
if((a[j] <= n && a[j] != o) || s.find(a[j]) != s.end())return 0;
s.insert(a[j]);
j = (j + 1) % n;
o = o % n + 1;
}
break;
}
if(s.find(a[i]) != s.end())return 0;
s.insert(a[i]);
}
vt<int> hv;
for(int i = 0; i < n; i++){
if(a[i] > n){
hv.pb(a[i]);
}
}
if(hv.empty())return 1;
sort(all(hv));
int sz = hv.size(), ret = pw(sz, hv[0] - n - 1);
for(int i = 1; i < sz; i++){
ret = 1ll * ret * pw(sz - i, hv[i] - hv[i - 1] - 1) % mod;
}
if(hv.size() == n)ret = 1ll * ret * n % mod;
return ret;
}
//void solve() {
//int n;
//cin >> n;
//int a[n];
//for(int i = 0; i < n; i++){
//cin >> a[i];
//}
//cout << countReplacement(n, a);
//}
//int main() {
//ios_base::sync_with_stdio(0);
//cin.tie(0);
//int times = 1;
////cin >> times;
//for(int i = 1; i <= times; i++) {
//solve();
//}
//return 0;
//}
Compilation message
gondola.cpp: In function 'int countReplacement(int, int*)':
gondola.cpp:108:15: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
108 | if(hv.size() == n)ret = 1ll * ret * n % mod;
| ~~~~~~~~~~^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
600 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
360 KB |
Output is correct |
6 |
Correct |
10 ms |
2140 KB |
Output is correct |
7 |
Correct |
7 ms |
604 KB |
Output is correct |
8 |
Correct |
19 ms |
3932 KB |
Output is correct |
9 |
Correct |
6 ms |
1624 KB |
Output is correct |
10 |
Correct |
26 ms |
4548 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
11 ms |
2148 KB |
Output is correct |
7 |
Correct |
7 ms |
604 KB |
Output is correct |
8 |
Correct |
20 ms |
3932 KB |
Output is correct |
9 |
Correct |
6 ms |
1372 KB |
Output is correct |
10 |
Correct |
26 ms |
4564 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
344 KB |
Output is correct |
13 |
Correct |
3 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
9 ms |
856 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
416 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 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 |
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 |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
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 |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
544 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
9 ms |
1116 KB |
Output is correct |
12 |
Correct |
11 ms |
1372 KB |
Output is correct |
13 |
Correct |
11 ms |
1416 KB |
Output is correct |
14 |
Correct |
8 ms |
1112 KB |
Output is correct |
15 |
Correct |
16 ms |
2132 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
360 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
1016 KB |
Output is correct |
9 |
Correct |
33 ms |
4528 KB |
Output is correct |
10 |
Correct |
27 ms |
3932 KB |
Output is correct |
11 |
Correct |
10 ms |
1628 KB |
Output is correct |
12 |
Correct |
12 ms |
1900 KB |
Output is correct |
13 |
Correct |
3 ms |
604 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 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 |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
33 ms |
4496 KB |
Output is correct |
10 |
Correct |
26 ms |
4032 KB |
Output is correct |
11 |
Correct |
12 ms |
1624 KB |
Output is correct |
12 |
Correct |
12 ms |
2136 KB |
Output is correct |
13 |
Correct |
3 ms |
604 KB |
Output is correct |
14 |
Correct |
42 ms |
6100 KB |
Output is correct |
15 |
Correct |
54 ms |
6616 KB |
Output is correct |
16 |
Correct |
8 ms |
1624 KB |
Output is correct |
17 |
Correct |
30 ms |
4700 KB |
Output is correct |
18 |
Correct |
16 ms |
2904 KB |
Output is correct |