제출 #35189

#제출 시각아이디문제언어결과실행 시간메모리
35189cheater2k중앙값 배열 (balkan11_medians)C++14
100 / 100
56 ms4552 KiB
#include <bits/stdc++.h>
using namespace std;

const int N = 200005;

int n, a[N], b[N];
int T[N];
bool used[N];

void upd(int x) { for(; x < N; x += x & -x) T[x]++; }
int get(int x) { int res = 0; for (; x > 0; x -= x & -x) res += T[x]; return res; }

int main() {
	scanf("%d", &n);
	for (int i = 1; i <= n; ++i) scanf("%d", b + i);

	int l = 1, r = 2 * n - 1;
	int pt = 0;
	for (int i = 1; i <= n; ++i) {
		if (!used[b[i]]) used[b[i]] = 1, a[++pt] = b[i], upd(b[i]);

		int med = b[i];
		while(pt < 2 * i - 1) {
			while(l <= 2 * n - 1 && used[l]) ++l;
			while(r >= 1 && used[r]) --r;
			int smaller = get(med - 1);
			if (smaller < i - 1) a[++pt] = l, upd(l), used[l++] = 1;
			else if (pt - smaller < i) a[++pt] = r, upd(r), used[r--] = 1;
		}
	}

	for (int i = 1; i <= 2 * n - 1; ++i) printf("%d ", a[i]);
	printf("\n");
}

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

medians.cpp: In function 'int main()':
medians.cpp:14:17: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &n);
                 ^
medians.cpp:15:49: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for (int i = 1; i <= n; ++i) scanf("%d", b + i);
                                                 ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...