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>
#define all(x) x.begin(), x.end()
#define sz(x) (int) x.size()
#define endl '\n'
#define pb push_back
#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ii = pair<int,int>;
using iii = tuple<int,int,int>;
const int inf = 2e9+1;
const int mod = 1e9+9;
const int maxn = 1e5+100;
template<typename X, typename Y> bool ckmin(X& x, const Y& y) { return (y < x) ? (x=y,1):0; }
template<typename X, typename Y> bool ckmax(X& x, const Y& y) { return (x < y) ? (x=y,1):0; }
#include "gondola.h"
int valid(int n,int v[]){
vector<ii>v2;
map<int,bool>mp;
int mn = inf, idx = -1;
for(int i=0;i<n;++i){
if(mp[v[i]]==1)return 0;
mp[v[i]] = 1;
if(ckmin(mn,v[i]))idx = i;
}
if(mn>=n)return 1;
for(int i=idx;i<n;++i)if(v[i]<=n)v2.pb({v[i],i-idx});
for(int i=0;i<idx;++i)if(v[i]<=n)v2.pb({v[i],n-idx+i});
for(int i=1;i<sz(v2);++i){
if(v2[i].first-v2[i-1].first!=v2[i].second-v2[i-1].second)return 0;
}
return 1;
}
//----------------------
int replacement(int n, int gondolaSeq[], int replacementSeq[])
{
priority_queue<ii,vector<ii>,greater<ii>>pq;
int mn = inf, idx = 0;
for(int i=0;i<n;++i)if(ckmin(mn,gondolaSeq[i]))idx = i;
if(mn>n)mn = 1;
pq.push({gondolaSeq[idx],mn});
for(int i=(idx+1)%n;i!=idx;i=(i+1)%n){
if(mn>n)mn = 0;
pq.push({gondolaSeq[i],++mn});
}
idx = 0;
int act = n+1;
while(!pq.empty()){
auto [target,current] = pq.top();pq.pop();
if(target==current)continue;
replacementSeq[idx++] = current;
pq.push({target,act++});
}
return idx;
}
//----------------------
ll fastexp(ll b,ll e){
if(e==0)return 1ll;
if(e==1)return b;
ll sqr = fastexp(b,e/2), resp = (sqr*sqr)%mod;
if(e&1)return (resp*b)%mod;
return resp;
}
int countReplacement(int n, int inputSeq[])
{
vector<int>big;
if(!valid(n,inputSeq))return 0;
for(int i=0;i<n;++i){
if(inputSeq[i]>n)big.pb(inputSeq[i]);
}
sort(all(big));
ll res = 1, last = n;
for(int i=0;i<sz(big);++i){
res = (res*fastexp(ll(sz(big)-i),ll(big[i]-last-1)))%mod, last = big[i];
}
return res;
}
// int v[maxn], resp[maxn];
// int main(){_
// int n;cin>>n;
// for(int i=0;i<n;++i)cin>>v[i];
// int k = replacement(n,v,resp);
// cout<<k<<endl;
// for(int i=0;i<k;++i)cout<<resp[i]<<" \n"[i==k-1];
// }
# | 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... |