# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
26760 | RayaBurong25_1 | 중앙값 배열 (balkan11_medians) | C++14 | 39 ms | 3068 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <stdio.h>
int B[100005];
int Used[200005];
int Fen[200005];
int min, max;
int N;
int Query(int pos)
{
int sum = 0;
for (; pos > 0; pos -= pos&-pos)
sum += Fen[pos];
return sum;
}
void Update(int pos)
{
Used[pos] = 1;
for (; pos <= N; pos += pos&-pos)
Fen[pos]++;
}
int main()
{
scanf("%d", &N);
min = 1;
max = 2*N - 1;
int i, r, cnt;
for (i = 0; i < N; i++)
scanf("%d", &B[i]);
for (i = 0; i < N; i++)
{
// printf("i%d ", i);
cnt = 0;
if (!Used[B[i]])
{
Used[B[i]] = 1;
Update(B[i]);
printf("%d ", B[i]);
cnt++;
}
r = Query(B[i]);
// printf("//%d//", r);
if (i == 0)
continue;
if (cnt == 1)
{
if (r < i + 1)
{
while (Used[min])
min++;
Used[min] = 1;
Update(min);
printf("%d ", min);
}
else
{
while (Used[max])
max--;
Used[max] = 1;
Update(max);
printf("%d ", max);
}
}
else
{
if (r == i - 1)
{
while (Used[min])
min++;
Used[min] = 1;
Update(min);
printf("%d ", min);
while (Used[min])
min++;
Used[min] = 1;
Update(min);
printf("%d ", min);
}
else if (r == i)
{
while (Used[min])
min++;
Used[min] = 1;
Update(min);
printf("%d ", min);
while (Used[max])
max--;
Used[max] = 1;
Update(max);
printf("%d ", max);
}
else
{
while (Used[max])
max--;
Used[max] = 1;
Update(max);
printf("%d ", max);
while (Used[max])
max--;
Used[max] = 1;
Update(max);
printf("%d ", max);
}
}
}
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |