Submission #860479

#TimeUsernameProblemLanguageResultExecution timeMemory
860479Halym2007Hedgehog Daniyar and Algorithms (IZhO19_sortbooks)C++11
100 / 100
2833 ms100692 KiB
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 5;
const int NN = 1e7 + 5;
#define ff first
#define ss second
#define pb push_back
vector <pair <int, int>> v[N];
int a[N], k[N], ans[N], st[NN], jog;

void update (int ind, int l, int r, int pos, int val) {
	if (l == r) {
		st[ind] = max (st[ind], val);
		return;
	}
	if (pos <= (l + r) / 2) {
		update (ind * 2, l, (l + r) / 2, pos, val);
	}
	else {
		update (ind * 2 + 1, (l + r) / 2 + 1, r, pos, val);
	}
	st[ind] = max (st[ind * 2], st[ind * 2 + 1]);
}

void jogap (int ind, int l, int r, int x, int y) {
	if (x > r or l > y) return;
	if (x <= l and r <= y) {
		jog = max (jog, st[ind]);
		return;
	}
	jogap (ind * 2, l, (l + r) / 2, x, y);
	jogap (ind * 2 + 1, (l + r) / 2 + 1, r, x, y);
}


int main () {
//	freopen ("input.txt", "r", stdin);
	int n, m;
	cin >> n >> m;
	for (int i = 1; i <= n; ++i) {
		cin >> a[i];
	}
	for (int i = 1; i <= m; ++i) {
		int l, r;
		cin >> l >> r >> k[i];
		v[r].pb ({l, i});	
	}
//	cout << "sak";
//	return 0;
	stack <int> s;
	for (int i = 1; i <= n; ++i) {
		while (!s.empty() and a[s.top()] <= a[i]) s.pop();
		if (!s.empty()) {
			update (1, 1, n, s.top(), a[i] + a[s.top()]);
		}
		s.push (i);
		for (pair <int, int> x : v[i]) {
			// x bilen i aralyk
			jog = 0;
			jogap (1, 1, n, x.ff, i);
			if (k[x.ss] >= jog) {
				ans[x.ss] = 1;
			}
		}
	}
	for (int i = 1; i <= m; ++i) {
		cout << ans[i] << endl;
	}
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...