제출 #368554

#제출 시각아이디문제언어결과실행 시간메모리
368554cpp219medians (balkan11_medians)C++14
100 / 100
125 ms12268 KiB
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define fs first
#define sc second
using namespace std;
const ll N = 2e5 + 9;
const ll inf = 1e16 + 7;
typedef pair<int,int> LL;
vector<ll> ans;
set<ll> s;
ll n,b[N],was[N];

void Out(){
    for (auto i : s) cout<<i<<" ";
}

void DE(){
    ans.push_back(*prev(s.end())); s.erase(prev(s.end()));
    ans.push_back(*prev(s.end())); s.erase(prev(s.end()));
}

void DS(){
    ans.push_back(*s.begin()),s.erase(s.begin());
    ans.push_back(*s.begin()),s.erase(s.begin());
}

int main(){
    //ios_base::sync_with_stdio(0);
    //cin.tie(0); cout.tie(0);
    #define task "test"
    if (fopen(task".INP","r")){
        freopen(task".INP","r",stdin);
        //freopen(task".OUT","w",stdout);
    }
    cin>>n;
    for (ll i = 1;i <= 2*n - 1;i++) s.insert(i);
    for (ll i = 1;i <= n;i++) cin>>b[i],s.erase(b[i]);
    ans.push_back(b[1]); was[b[1]] = 1;
    for (ll i = 2;i <= n;i++){
        if (!was[b[i]]) ans.push_back(b[i]); //Out(); cout<<" x ";
        if (was[b[i]]){
            if (b[i - 1] > b[i]) DS();
            if (b[i - 1] < b[i]) DE();
            if (b[i - 1] == b[i]){
                ans.push_back(*s.begin()),s.erase(s.begin());
                ans.push_back(*prev(s.end())),s.erase(prev(s.end()));
            }
        }
        else if (b[i - 1] > b[i]) ans.push_back(*s.begin()),s.erase(s.begin());
        else if (b[i - 1] < b[i]) ans.push_back(*prev(s.end())),s.erase(prev(s.end()));
        was[b[i]] = 1; //Out(); cout<<"\n";
    }
    //exit(0);
    //for (auto i : s) cout<<i<<" "; exit(0);
    for (auto i : ans) cout<<i<<" ";
}

컴파일 시 표준 에러 (stderr) 메시지

medians.cpp: In function 'int main()':
medians.cpp:33:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   33 |         freopen(task".INP","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...