답안 #990746

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
990746 2024-05-31T07:12:16 Z perchuts Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++17
0 / 100
2187 ms 64440 KB
#include <bits/stdc++.h>

using namespace std;

const int maxn = 1e6 + 5;

int seg[4*maxn], w[maxn];

void upd(int i, int l, int r, int x, int k) {
	if (l == r) {
		seg[i] = max(seg[i], k + w[l]);
		return;
	}
	int md = (l + r) / 2;
	if (x <= md) upd(2*i, l, md, x, k);
	else upd(2*i+1, md+1, r, x, k);
	seg[i] = max(seg[2*i], seg[2*i+1]);
}

int query(int i, int l, int r, int x, int y) {
	if (r < x || y < l) return 0;
	if (x <= l && r <= y) return seg[i];
	int md = (l + r) / 2;
	return max(query(2*i, l, md, x, y), query(2*i+1, md+1, r, x, y));
}

int main() {
	int n, q, xx = 0; cin >> n >> q;
	for (int i = 0; i < n; ++i) cin >> w[i];
	using iii = tuple<int,int,int, int>;
	vector<iii> queries(q);
	for (auto& [r, l, k, id] : queries) cin >> l >> r >> k, id = xx++;
	sort(begin(queries), end(queries));
	vector<int> ans(q);
	int pt = 1;
	stack<int> st;
	for (auto [r, l, k, id] : queries) {
		while (pt <= r) {
			while (!st.empty() && w[st.top()] <= w[pt]) st.pop();
			if (!st.empty()) {
				upd(1, 1, n, st.top(), w[pt]);
			}
			st.push(pt++);
		}
		ans[id] = (query(1, 1, n, l, r) <= k);
	}
	for (int i = 0; i < q; ++i) cout << ans[i] << endl;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 1 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 1 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2187 ms 64440 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 197 ms 9464 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 1 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 1 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -