Submission #1130912

#TimeUsernameProblemLanguageResultExecution timeMemory
1130912TsaganaHedgehog Daniyar and Algorithms (IZhO19_sortbooks)C++17
100 / 100
825 ms82892 KiB
#include<bits/stdc++.h>

#define IOS ios_base::sync_with_stdio(false);cin.tie();cout.tie();
#define all(x) x.begin(), x.end()
#define int long long
#define pq priority_queue
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define pp pop_back
#define F first
#define S second

using namespace std;

int n, m;
int a[1000001];
int f[1000001];
int ans[1000001];
vector<array<int, 3>> q[1000001];

void update(int i, int x) {
	for (; i; i -= i&-i) f[i] = max(x, f[i]);
}
int calc(int i) {
	int x = 0;
	for (; i <= n; i += i&-i) x = max(x, f[i]);
	return x;
}

void solve () {
	cin >> n >> m;
	a[0] = 1 << 30;
	for (int i = 1; i <= n; i++) cin >> a[i];
	for (int i = 0; i < m; i++) {
		int l, r, k;
		cin >> l >> r >> k;
		q[r].pb({l, k, i});
	}
	vector<int> t{0};
	for (int i = 1; i <= n; i++) {
		while (a[t.back()] <= a[i]) t.pp();
		if (t.back()) update(t.back(), a[t.back()] + a[i]);
		t.pb(i);
		for (auto [l, k, p]: q[i]) ans[p] = calc(l) <= k;
	}
	for (int i = 0; i < m; i++) cout << ans[i] << '\n';
}
signed main() {IOS solve(); return 0;}
#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...