답안 #973370

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

const int INF = 1e9;

struct SGT {
	int n;
	vector<int> mx, mn, diff;
	SGT(int _n) {
		n = _n;
		mx.resize(4 * n), diff.resize(4 * n, 0);
	}
	void build(int node, int l, int r, vector<int> &a) {
		if (l == r) mx[node] = a[l];
		else {
			int mid = (l + r) / 2;
			build(2 * node, l, mid, a);
			build(2 * node + 1, mid + 1, r, a);
			mx[node] = max(mx[2 * node], mx[2 * node + 1]);
		}
	}
	void update(int node, int l, int r, int L, int R, int x) {
		if (R < l or r < L) return;
		else if (L <= l and r <= R) {
			diff[node] = max(diff[node], mx[node] - x);
		} else {
			int mid = (l + r) / 2;
			update(2 * node, l, mid, L, R, x);
			update(2 * node + 1, mid + 1, r, L, R, x);
			diff[node] = max(diff[node], max(diff[2 * node], diff[2 * node + 1]));
		}
	}
	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 diff[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() {
	SGT sgt = SGT(n);
	sgt.build(1, 0, n - 1, a);
	stack<int> st;
	ans.resize(m);
	for (int r = 0; r < n; r++) {
		while (not st.empty() and a[st.top()] > a[r]) st.pop();
		// cout << "PUSH " << (st.empty() ? 0 : st.top() + 1) << ' ' << r << endl;
		sgt.update(1, 0, n - 1, (st.empty() ? 0 : st.top() + 1), r, a[r]);
		st.push(r);
		for (int qi : r2q[r]) {
			auto [l, k] = q[qi];
			// cout << "BRO " << l << ' ' << r << ' ' << sgt.query(1, 0, n - 1, l, r) << endl;
			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 1 ms 600 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 1 ms 600 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1135 ms 88868 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 70 ms 9040 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 1 ms 600 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 1 ms 600 KB Output isn't correct
4 Halted 0 ms 0 KB -