Submission #116492

#TimeUsernameProblemLanguageResultExecution timeMemory
116492Adhyyan1252medians (balkan11_medians)C++11
20 / 100
86 ms13868 KiB
#include<bits/stdc++.h> //https://oj.uz/problem/view/balkan11_mediansxx using namespace std; int main(){ ios::sync_with_stdio(false); cin.tie(0); int n; cin>>n; vector<int> b(n); for(int i = 0; i < n; i++) cin>>b[i]; vector<int> suffMax(n), suffMin(n); suffMax[n-1] = b[n-1]; suffMin[n-1] = b[n-1]; for(int i = n-2; i >= 0; i--){ suffMax[i] = max(suffMax[i+1], b[i]); suffMin[i] = min(suffMin[i+1], b[i]); } vector<int> a(2*n-1); vector<int> f(2*n); a[0] = b[0]; set<int> s; f[b[0]] = 1; for(int i = 1; i <= 2*n-1; i++){ if(i == b[0]) continue; s.insert(i); } for(int i = 1; i < n; i++){ if(b[i] > b[i-1]){ assert(s.size() > 0); auto it = s.end(); it--; if(f[b[i]] == 0){ // not inserted yet, insert now f[b[i]] = 1; f[*it] = 1; a[i*2-1] = b[i]; a[i*2] = *it; s.erase(it); s.erase(b[i]); }else{ f[*it] = 1; a[i*2-1] = *it; s.erase(it); assert(s.size() > 0); it = s.end(); it--; f[*it] = 1; a[i*2] = *it; s.erase(it); s.erase(b[i]); } }else if(b[i] < b[i-1]){ assert(s.size() > 0); auto it = s.begin(); if(f[b[i]] == 0){ // not inserted yet, insert now f[b[i]] = 1; f[*it] = 1; a[i*2-1] = b[i]; a[i*2] = *it; s.erase(it); }else{ f[*it] = 1; a[i*2-1] = *it; s.erase(it); assert(s.size() > 0); it = s.begin(); f[*it] = 1; a[i*2] = *it; s.erase(it); } }else if(b[i] == b[i-1]){ assert(s.size() > 0); auto it = s.end(); it--; f[*it] = 1; a[i*2-1] = *it; s.erase(it); assert(s.size() > 0); it = s.begin(); f[*it] = 1; a[i*2] = *it; s.erase(it); }else{ assert(false); } } for(int i = 0; i < a.size(); i++){ cout<<a[i]<<" "; } cout<<endl; }

Compilation message (stderr)

medians.cpp: In function 'int main()':
medians.cpp:97:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = 0; i < a.size(); i++){
                 ~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...