#include <bits/stdc++.h>
#include <gondola.h>
using namespace std;
#define FOR(i, a, b) for(int i = a; i <= b; i++)
int diff(int n, int a, int b){
if(b >= a) return b - a;
else return (n - a) + b;
}
int valid(int n, int inputSeq[]){
pair<int, int> prev = make_pair(-1, 0);
set<int> s;
FOR(i, 0, n - 1){
if(inputSeq[i] <= n){
if(prev.first == -1){
prev = make_pair(i, inputSeq[i]);
}else{
if((((prev.second + diff(n, prev.first, i)) % n) == 0 ? n : ((prev.second + diff(n, prev.first, i)) % n)) != inputSeq[i]) return 0;
prev = make_pair(i, inputSeq[i]);
}
}else{
if(s.find(inputSeq[i]) != s.end()) return 0;
s.insert(inputSeq[i]);
}
}
return 1;
}
int replacement(int n, int gondolaSeq[], int replacementSeq[]){
int idx = -1, mx = -1;
vector<pair<int, int> > v;
FOR(i, 0, n - 1){
if(gondolaSeq[i] <= n){
idx = gondolaSeq[i] - i;
if(idx <= 0) idx += n;
}else{
v.push_back(make_pair(gondolaSeq[i], i));
}
mx = max(mx, gondolaSeq[i]);
}
sort(v.begin(), v.end());
if(idx == -1) idx = 1;
set<int> s;
FOR(i, 0, (int)(v.size() - 2)) {
s.insert(v[i].first);
replacementSeq[v[i].first - n - 1] = ((idx + v[i].second) % n == 0) ? n : ((idx + v[i].second) % n);
}
if(v.size()){
int prev = ((idx + v[v.size() - 1].second) % n == 0) ? n : ((idx + v[v.size() - 1].second) % n);
FOR(i, n + 1, mx) {
if(s.find(i) == s.end()) {
replacementSeq[i - (n + 1)] = prev;
prev = i;
}
}
}
return mx - n;
}
int countReplacement(int n, int inputSeq[]){
if(!valid(n, inputSeq)) return 0;
ll r = 1;
int c = 0, mx = -1;
set<int> s;
bool fct = true;
FOR(i, 0, n - 1){
if(inputSeq[i] <= n) fct = false;
else{
c++, s.insert(inputSeq[i]);
}
}
int c2 = 0;
FOR(i, n + 1, mx){
if(s.find(i) == s.end()){
r = (r * (ll)(c - c2)) % MOD;
}else{
c2++;
}
}
if(fct){
FOR(i, 1, n) r = (r * (ll)i) % MOD;
}
return r;
}
Compilation message
gondola.cpp: In function 'int countReplacement(int, int*)':
gondola.cpp:67:5: error: 'll' was not declared in this scope
67 | ll r = 1;
| ^~
gondola.cpp:81:13: error: 'r' was not declared in this scope
81 | r = (r * (ll)(c - c2)) % MOD;
| ^
gondola.cpp:81:38: error: 'MOD' was not declared in this scope
81 | r = (r * (ll)(c - c2)) % MOD;
| ^~~
gondola.cpp:87:22: error: 'r' was not declared in this scope
87 | FOR(i, 1, n) r = (r * (ll)i) % MOD;
| ^
gondola.cpp:87:35: error: expected ')' before 'i'
87 | FOR(i, 1, n) r = (r * (ll)i) % MOD;
| ~ ^
| )
gondola.cpp:89:12: error: 'r' was not declared in this scope
89 | return r;
| ^