답안 #72121

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
72121 2018-08-26T05:23:23 Z @younha_holic(#2227, jun6873, rkm0959) 박스런 (FXCUP3_box) C++17
17 / 100
1000 ms 872 KB
#include <bits/stdc++.h>
using namespace std;

const int maxn = 1<<19;
int n, a[maxn], b[maxn];

typedef pair<int, int> pint;
#define x first
#define y second

void xfill(int s, int e, int l, int r) {
	if (s>e) return;
	int m = (s+e)/2, k = max(m, l);

	deque<pint> dq;
	for (int i=k-m+1; i<=k; i++) {
		while (!dq.empty() and dq.back().x < a[i]) dq.pop_back();
		dq.emplace_back(a[i], i);
	}
	while (k+1<=r) {
		pint x = dq.front();
		if (a[k+1] > x.x) break;
		k++;
		if (dq.front().y < k-m+1) dq.pop_front();
		while (!dq.empty() and dq.back().x < a[k]) dq.pop_back();
		dq.emplace_back(a[k], k);
	}
	if (k>r) k = r;
	b[m] = k;

	if (s<e) {
		int m = (s+e)/2;
		xfill(s, m-1, l, k);
		xfill(m+1, e, k, r);
	}
}

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);

	cin >> n;
	for (int i=1; i<=n; i++) cin >> a[i];

	xfill(1, n, 1, n);

	for (int i=1; i<=n; i++) {
		if (b[i] == n) cout << -1 << ' ';
		else cout << b[i] - i + 1 << ' ';
	}

}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 3 ms 484 KB Output is correct
3 Correct 2 ms 484 KB Output is correct
4 Correct 2 ms 484 KB Output is correct
5 Correct 2 ms 492 KB Output is correct
6 Correct 3 ms 540 KB Output is correct
7 Correct 3 ms 556 KB Output is correct
8 Correct 3 ms 556 KB Output is correct
9 Correct 3 ms 556 KB Output is correct
10 Correct 2 ms 600 KB Output is correct
11 Correct 2 ms 600 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 3 ms 484 KB Output is correct
3 Correct 2 ms 484 KB Output is correct
4 Correct 2 ms 484 KB Output is correct
5 Correct 2 ms 492 KB Output is correct
6 Correct 3 ms 540 KB Output is correct
7 Correct 3 ms 556 KB Output is correct
8 Correct 3 ms 556 KB Output is correct
9 Correct 3 ms 556 KB Output is correct
10 Correct 2 ms 600 KB Output is correct
11 Correct 2 ms 600 KB Output is correct
12 Correct 7 ms 600 KB Output is correct
13 Correct 75 ms 664 KB Output is correct
14 Execution timed out 1058 ms 872 KB Time limit exceeded
15 Halted 0 ms 0 KB -