답안 #202637

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
202637 2020-02-17T12:04:26 Z maruii Sushi (JOI16_sushi) C++14
0 / 100
81 ms 9464 KB
#include <bits/stdc++.h>
using namespace std;
const int B = 600;

int A[400005];
priority_queue<int> q[700];
vector<int> stk[700];
int naive(int s, int e, int v) {
	if (s > e) return v;
	int a = (s - 1) / B;
	priority_queue<int, vector<int>, greater<int>> pq;
	for (auto i : stk[a]) pq.push(i);
	stk[a].clear();
	for (int i = a * B + 1; i <= a * B + B; ++i) {
		pq.push(A[i]);
		A[i] = pq.top(); pq.pop();
	}
	while (q[a].size()) q[a].pop();
	for (int i = s; i <= e; ++i) if (v < A[i]) swap(v, A[i]);
	for (int i = a * B + 1; i <= a * B + B; ++i) q[i].push(A[i]);
	return v;
}
int query(int s, int e, int v) {
	int a = (s - 1) / B + 1;
	int b = (e - 1) / B;
	if (b < a) return naive(s, e, v);
	v = naive(s, a * B, v);
	for (int i = a; i < b; ++i) {
		stk[i].push_back(v);
		q[i].push(v);
		v = q[i].top(); q[i].pop();
	}
	v = naive(b * B + 1, e, v);
	return v;
}
int main() {
	ios_base::sync_with_stdio(0), cin.tie(0);
	int N, Q; cin >> N >> Q;
	for (int i = 1; i <= N; ++i) {
		cin >> A[i];
		q[(i - 1) / B].push(A[i]);
	}
	while (Q--) {
		int s, t, p; cin >> s >> t >> p;
		int res;
		if (s <= t) res = query(s, t, p);
		else res = query(1, t, query(s, N, p));
		printf("%d\n", res);
	}
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Runtime error 8 ms 888 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 81 ms 9464 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 8 ms 888 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -