#include <bits/stdc++.h>
using namespace std;
#define int long long
const int mod = 1e9+7;
#include "gondola.h"
signed valid(signed n, signed S[]){
set<int> s; for(int i=0; i<n; i++) s.insert(S[i]); if (s.size()<n) return 0;
int ind = -1;
for (int i=0; i<n; i++) if (S[i] <= n) {ind = i; break;}
if (ind == -1) return 1;
int t = S[ind];
for (int i=ind+1; i!=ind; i++, i%=n){
t++; if (t==n+1) t = 1;
if (S[i] <= n && S[i] != t) return 0;
}
return 1;
}
signed replacement(signed n, signed S[], signed replacementSeq[]){
int ind = -1;
for (int i=0; i<n; i++) if (S[i] <= n) {ind = i; break;}
int bg = -1; map<int,int> tr;
if (ind == -1){
for (int i=0; i<n; i++){
tr[S[i]] = i+1; bg= max(bg,(int)S[i]);
}
} else {
int t = S[ind];
for (int i=(ind+1)%n; i!=ind; i++, i%=n){
t++; if (t==n+1) t = 1;
if (S[i] > n) {tr[S[i]] = t; bg=max(bg,(int)S[i]);}
}
}
if (bg==-1) return 0;
int bgm = tr[bg];
tr.erase(bg);
for (int i=n+1; i<=bg; i++){
if (tr.count(i)){
replacementSeq[i-(n+1)] = tr[i];
} else {
replacementSeq[i-(n+1)] = bgm;
bgm = i;
}
}
return (bg-(n+1) + 1);
}
signed countReplacement(signed n, signed S[]){
if (!valid(n,S)) return 0;
int res = 1;
set<int>tr; for (int i=0; i<n; i++) tr.insert(S[i]);
int bigger = 0;
for (int x: tr) if (x>=n+1) bigger++;
if (bigger == n) res *= n;
for (int i=n+1; i < 25e4+6; i++){
if (tr.count(i)){
bigger--; if (!bigger) return res;
} else {
res *= bigger; res %= mod;
}
}
return res;
}
Compilation message
gondola.cpp: In function 'int valid(int, int*)':
gondola.cpp:8:65: warning: comparison of integer expressions of different signedness: 'std::set<long long int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
8 | set<int> s; for(int i=0; i<n; i++) s.insert(S[i]); if (s.size()<n) return 0;
| ~~~~~~~~^~
/usr/bin/ld: /tmp/ccXbnnVT.o: in function `main':
grader.cpp:(.text.startup+0xb6): undefined reference to `valid'
/usr/bin/ld: grader.cpp:(.text.startup+0x108): undefined reference to `countReplacement'
/usr/bin/ld: grader.cpp:(.text.startup+0x132): undefined reference to `replacement'
collect2: error: ld returned 1 exit status