이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "gondola.h"
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define F first
#define S second
#define pb push_back
#define endl "\n"
#define sz(x) (ll)x.size()
#define ins insert
typedef vector <ll> vi;
typedef pair <ll,ll> ii;
typedef vector <ii> vii;
#define dbg(x) cout<<#x<<": "<<x<<endl;
#define dbg2(x,y) cout<<#x<<": "<<x<<" "<<#y<<": "<<y<<endl;
#define dbg3(x,y,z) cout<<#x<<": "<<x<<" "<<#y<<": "<<y<<" "<<#z<<": "<<z<<endl;
void printVct(vi &v){
for (ll i =0; i<sz(v); i++){
cout<<v[i]<<" ";
}
cout<<endl;
}
//subtask 1 & 2 & 3
int valid(int n, int arr[]){
ll p = 0;
set <ll> st; st.ins(arr[0]);
for (ll i=1; i<n; i++){
if (arr[p] > arr[i]) p = i;
if (st.find(arr[i]) == st.end()){
st.ins(arr[i]);
}
else{
return 0;
}
}
if (arr[p] > n) return 1;
vi v;
for (ll i = p; i<n; i++){
if (arr[i] <= n) v.pb(arr[i]);
else v.pb(v.back()+1);
}
for (ll i =0; i<p; i++){
if (arr[i] <= n) v.pb(arr[i]);
else v.pb(v.back()+1);
}
for (ll i =1; i<n; i++){
if (v[i] != v[i-1] + 1){
return 0;
}
}
return 1;
}
//----------------------
//subtask 4,5,6
inline void add_to_ans(ll x, ll &ans_size, int ans[]){
ans[ans_size] = x;
ans_size++;
}
int replacement(int n, int arr[], int ans[])
{
ll ans_size = 0;
vii misplaced_sorted;
ll firstIdx = 0;
for (ll i=0; i<n; i++){
if (arr[i] == 1){
firstIdx = i;
}
if (arr[i] > n){
if (arr[firstIdx] != 1) firstIdx = i;
misplaced_sorted.pb(ii(arr[i], i));
}
}
sort(misplaced_sorted.begin(), misplaced_sorted.end());
vi rel_idx(n);
ll c = 1;
for (ll i =firstIdx; i<n; i++){
rel_idx[i] = c;
c++;
}
for (ll i =0; i<firstIdx; i++){
rel_idx[i] = c;
c++;
}
// dbg(firstIdx);
// printVct(rel_idx);
ll prev = n;
for (ll i =0; i<sz(misplaced_sorted); i++){
// dbg3(i, misplaced_sorted[i].F, misplaced_sorted[i].S);
add_to_ans(rel_idx[misplaced_sorted[i].S], ans_size, ans);
for (ll j = prev+1; j<misplaced_sorted[i].F; i++){
add_to_ans(j, ans_size, ans);
}
prev = misplaced_sorted[i].F;
}
// cout<<"ans: ";
// for (ll i=0; i<ans_size; i++){
// cout<<ans[i]<<" ";
// }
// cout<<endl;
return ans_size;
}
//----------------------
int countReplacement(int n, int inputSeq[])
{
return -3;
}
/*
1
5
1 2 3 4 5
*/
# | 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... |