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 "gondola.h"
#include <bits/stdc++.h>
#define DEBUG 1
using namespace std;
namespace output{
void __(short x){cout<<x;}
void __(unsigned x){cout<<x;}
void __(int x){cout<<x;}
void __(long long x){cout<<x;}
void __(unsigned long long x){cout<<x;}
void __(double x){cout<<x;}
void __(long double x){cout<<x;}
void __(char x){cout<<x;}
void __(const char*x){cout<<x;}
void __(const string&x){cout<<x;}
void __(bool x){cout<<(x?"true":"false");}
template<class S,class T>
void __(const pair<S,T>&x){__(DEBUG?"(":""),__(x.first),__(DEBUG?", ":" "),__(x.second),__(DEBUG?")":"");}
template<class T>
void __(const vector<T>&x){__(DEBUG?"{":"");bool _=0;for(const auto&v:x)__(_?DEBUG?", ":" ":""),__(v),_=1;__(DEBUG?"}":"");}
template<class T>
void __(const set<T>&x){__(DEBUG?"{":"");bool _=0;for(const auto&v:x)__(_?DEBUG?", ":" ":""),__(v),_=1;__(DEBUG?"}":"");}
template<class T>
void __(const multiset<T>&x){__(DEBUG?"{":"");bool _=0;for(const auto&v:x)__(_?DEBUG?", ":" ":""),__(v),_=1;__(DEBUG?"}":"");}
template<class S,class T>
void __(const map<S,T>&x){__(DEBUG?"{":"");bool _=0;for(const auto&v:x)__(_?DEBUG?", ":" ":""),__(v),_=1;__(DEBUG?"}":"");}
void pr(){cout<<"\n";}
template<class S,class... T>
void pr(const S&a,const T&...b){__(a);if(sizeof...(b))__(' ');pr(b...);}
}
using namespace output;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<double,double> pdd;
typedef pair<ld,ld> pld;
typedef vector<int> vi;
typedef vector<ll> vl;
#define pb push_back
#define fox(i,x,y) for(int i=(x);i<=(y);i++)
#define foxr(i,x,y) for(int i=(y);i>=(x);i--)
int valid(int n,int *arr){
set<int> S;
for(int i=0;i<n;i++) S.insert(arr[i]);
if(S.size()!=n) return 0;
int mn=1<<30, st=-1;
for(int i=0;i<n;i++){
if(arr[i]>n) continue;
if(arr[i]<mn){
mn = arr[i];
st = (i-arr[i]+1+n)%n;
}
}
if(st==-1) return 1;
int f = 1;
for(int i=0;i<n;i++){
if(arr[(i+st)%n]>n) continue;
if(arr[(i+st)%n]!=i+1) f=0;
}
return f;
}
int replacement(int n,int *arr,int *rep){
vi seq; seq.resize(n);
int mn=1<<30, st=0;
for(int i=0;i<n;i++){
if(arr[i]>n) continue;
if(arr[i]<mn){
mn = arr[i];
st = (i-arr[i]+1+n)%n;
}
}
map<int,int> op;
int lst=n+1, sz=0;
for(int i=0;i<n;i++){
seq[i]=i+1;
if(arr[(st+i)%n]>n) op[arr[(st+i)%n]]=i;
}
for(auto v : op){
while(lst<v.first) rep[sz++]=seq[v.second],seq[v.second]=lst,lst++;
lst = v.first+1;
rep[sz++]=seq[v.second], seq[v.second]=v.first;
}
return sz;
}
int mod = 1e9+9;
int qpow(int b,int exp){
if(exp<=0) return 1;
else if(exp&1) return 1LL*b*qpow(b,exp-1)%mod;
else{int r=qpow(b,exp>>1); return 1LL*r*r%mod;}
}
int countReplacement(int n,int *arr){
if(!valid(n,arr)) return 0;
map<int,int> op;
int rem = 0, ans = 1;
for(int i=0;i<n;i++){
if(arr[i]>n){
rem++;
op[arr[i]]=i;
}
}
if(rem==n) ans *= n;
int lst = n+1;
for(auto v : op){
ans = 1LL*ans*qpow(rem,v.first-lst)%mod;
rem--; lst = v.first+1;
}
return ans;
}
Compilation message (stderr)
gondola.cpp: In function 'int valid(int, int*)':
gondola.cpp:51:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if(S.size()!=n) return 0;
~~~~~~~~^~~
# | 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... |