# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
217684 | KoalaMuch | 중앙값 배열 (balkan11_medians) | C++14 | 115 ms | 13560 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
const int N = 2e5+5;
int f[N];
set< int > s;
int ans[N];
int a[N];
int cur = 1;
void upd(int i)
{
while(i<N) ++f[i],i+=i&-i;
}
int get(int i,int ret = 0)
{
while(i) ret+=f[i],i-=i&-i;
return ret;
}
void add(int v)
{
ans[cur] = v;
s.erase(s.find(v));
upd(v+1);
cur++;
}
int main()
{
int n;
scanf("%d",&n);
for(int i=1;i<=n;i++) scanf("%d",&a[i]);
for(int i=1;i<2*n;i++) s.insert(i);
for(int i=1;i<=n;i++)
{
if(s.count(a[i])) add(a[i]);
while(get(a[i])!=i-1) add(*s.begin());
while(cur-get(a[i]+1)!=i) add(*(--s.end()));
}
for(int i=1;i<2*n;i++) printf("%d ",ans[i]);
return 0;
}
/*
13 10 3 8 8 10 10 11 11 10
13 1 10 3 2 8 20 4 19 5 18 6
*/
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |