This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#include <gondola.h>
#define taskname "test"
#define fi first
#define se second
#define pb push_back
#define faster ios_base::sync_with_stdio(0); cin.tie(0);
using namespace std;
using ll = long long;
using pii = pair <int, int>;
using pil = pair <int, ll>;
using pli = pair <ll, int>;
using pll = pair <ll, ll>;
using ull = unsigned ll;
mt19937 Rand(chrono::steady_clock::now().time_since_epoch().count());
ll min(const ll &a, const ll &b){
return (a < b) ? a : b;
}
ll max(const ll &a, const ll &b){
return (a > b) ? a : b;
}
const ll Mod = 1000000009;
const ll Mod2 = 999999999989;
const int maxN = 25e4 + 1;
int mp[maxN];
int n;
ll power(int x, int y){
if (y == 0) return 1;
if (y == 1) return x;
ll t = power(x, y / 2);
if (y % 2) return t * t % Mod * x % Mod;
else return t * t % Mod;
}
int valid(int N, int inputSeq[]){
n = N;
int pivot, cnt = 0, tem = INT_MAX;
for (int i = 0; i < n; ++i){
if (mp[inputSeq[i]]) return 0;
mp[inputSeq[i]] = 1;
if (inputSeq[i] > n) ++cnt;
if (tem > inputSeq[i]){
tem = inputSeq[i];
pivot = i;
}
}
if (cnt == n) return 1;
//pivot is where the number one is supposed to be at
pivot = ((pivot - tem + 1) + n) % n;
for (int i = pivot; i < pivot + n; ++i){
if (inputSeq[i % n] <= n && inputSeq[i % n] != i - pivot + 1){
return 0;
}
}
return 1;
}
int replacement(int N, int gondolaSeq[], int replacementSeq[]){
n = N;
int pivot = n - 1, tem = n, maxx = 0;
for (int i = 0; i < n; ++i){
if (tem > gondolaSeq[i]){
tem = gondolaSeq[i];
pivot = i;
}
maxx = max(maxx, gondolaSeq[i]);
mp[gondolaSeq[i]] = i + 1;
}
pivot = ((pivot - tem + 1) + n) % n;
vector <int> a(n);
vector <int> b;
for (int i = n + 1; i <= maxx; ++i){
if (!mp[i]) b.pb(i);
}
for (int i = pivot; i < pivot + n; ++i){
a[i % n] = i - pivot + 1;
}
vector <int> ans;
while (!b.empty()){
int k = b.back();
b.pop_back();
ans.pb(k);
gondolaSeq[mp[maxx] - 1] = k;
mp[k] = mp[maxx];
--maxx;
}
while (maxx > n){
int k = a[mp[maxx] - 1];
ans.pb(k);
//gondolaSeq[mp[maxx] - 1] = k;
--maxx;
}
for (int i = 0; i < ans.size(); ++i) replacementSeq[i] = ans[ans.size() - i - 1];
return ans.size();
}
int countReplacement(int N, int inputSeq[]){
n = N;
int pivot, cnt = 0, tem = INT_MAX;
map <int, int> mp;
vector <int> a;
ll ans = 1;
for (int i = 0; i < n; ++i){
if (mp[inputSeq[i]]) return 0;
mp[inputSeq[i]] = 1;
if (inputSeq[i] > n){
++cnt;
a.pb(inputSeq[i]);
}
if (tem > inputSeq[i]){
tem = inputSeq[i];
pivot = i;
}
}
if (cnt == n){
ans = n;
}
//pivot is where the number one is supposed to be at
pivot = ((pivot - tem + 1) % n + n) % n;
for (int i = pivot; i < pivot + n; ++i){
if (inputSeq[i % n] <= n && inputSeq[i % n] != i - pivot + 1){
return 0;
}
}
sort(a.begin(), a.end());
int last = n;
for (int i = 0; i < a.size(); ++i){
ans = ans * power(a.size() - i, a[i] - last - 1) % Mod;
last = a[i];
}
return ans;
}
Compilation message (stderr)
gondola.cpp: In function 'int replacement(int, int*, int*)':
gondola.cpp:97:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
97 | for (int i = 0; i < ans.size(); ++i) replacementSeq[i] = ans[ans.size() - i - 1];
| ~~^~~~~~~~~~~~
gondola.cpp: In function 'int countReplacement(int, int*)':
gondola.cpp:131:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
131 | for (int i = 0; i < a.size(); ++i){
| ~~^~~~~~~~~~
gondola.cpp: In function 'int valid(int, int*)':
gondola.cpp:53:21: warning: 'pivot' may be used uninitialized in this function [-Wmaybe-uninitialized]
53 | pivot = ((pivot - tem + 1) + n) % n;
| ~~~~~~^~~~~
gondola.cpp: In function 'int countReplacement(int, int*)':
gondola.cpp:123:21: warning: 'pivot' may be used uninitialized in this function [-Wmaybe-uninitialized]
123 | pivot = ((pivot - tem + 1) % n + n) % n;
| ~~~~~~^~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |