답안 #973399

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
973399 2024-05-01T22:39:42 Z colossal_pepe Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++17
0 / 100
1029 ms 73296 KB
#include <bits/stdc++.h>
using namespace std;

const int INF = 1e9;

struct SGT {
	int n;
	vector<int> tree;
	SGT(int _n) {
		n = _n;
		tree.resize(4 * n, 0);
	}
	void update(int node, int l, int r, int idx, int x) {
		if (l == r) tree[node] = x;
		else {
			int mid = (l + r) / 2;
			if (idx <= mid) update(2 * node, l, mid, idx, x);
			else update(2 * node + 1, mid + 1, r, idx, x);
		}
	}
	int query(int node, int l, int r, int L, int R) {
		if (R < l or r < L) return 0;
		else if (L <= l and r <= R) return tree[node];
		else{
			int mid = (l + r) / 2;
			return max(query(2 * node, l, mid, L, R), query(2 * node + 1, mid + 1, r, L, R));
		}
	}
};

int n, m;
vector<int> a, ans;
vector<pair<int, int>> q;
vector<vector<int>> r2q;

void solve() {
	ans.resize(m);
	SGT sgt = SGT(n);
	stack<int> st;
	for (int r = 0; r < n; r++) {
		while (not st.empty() and a[st.top()] <= a[r]) st.pop();
		if (not st.empty()) sgt.update(1, 0, n - 1, st.top(), a[st.top()] + a[r]);
		st.push(r);
		for (int qi : r2q[r]) {
			auto [l, k] = q[qi];
			ans[qi] = 0;
			ans[qi] = (k >= sgt.query(1, 0, n - 1, l, r));
		}
	}
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin >> n >> m;
	a.resize(n);
	for (int &x : a) {
		cin >> x;
	}
	q.resize(m), r2q.resize(n);
	for (int i = 0; i < m; i++) {
		int l, r, k;
		cin >> l >> r >> k;
		l--, r--;
		q[i] = make_pair(l, k);
		r2q[r].push_back(i);
	}
	solve();
	for (int i = 0; i < m; i++) {
		cout << ans[i] << '\n';
	}
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1029 ms 73296 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 60 ms 7548 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -