Submission #878851

# Submission time Handle Problem Language Result Execution time Memory
878851 2023-11-25T10:44:06 Z OAleksa Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++14
0 / 100
1241 ms 118164 KB
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define f first
#define s second
const int maxn = 1e6 + 69;
int n, q, a[maxn], st[4 * maxn], ans[maxn];
vector<tuple<int, int, int>> g[maxn];
void upd(int v, int tl, int tr, int l, int r, int x) {
	if (tl > r || tr < l)
		return;
	else if (tl >= l && tr <= r) 
		st[v] = max(st[v], x);
	else {
		int mid = (tl + tr) / 2;
		upd(v * 2, tl, mid, l, r, x);
		upd(v * 2 + 1, mid + 1, tr, l, r, x);
		st[v] = max(st[v * 2], st[v * 2 + 1]);
	}
}
int qry(int v, int tl, int tr, int l, int r) {
	if (tl > r || tr < l)
		return 0;
	else if (tl >= l && tr <= r)
		return st[v];
	else {
		int mid = (tl + tr) / 2;
		return max(qry(v * 2, tl, mid, l, r), qry(v * 2 + 1, mid + 1, tr, l, r));
	}
}
signed main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
   int tt = 1;
  	//cin >> tt;
   while (tt--) {
   	cin >> n >> q;
   	for (int i = 1;i <= n;i++)
   		cin >> a[i];
   	vector<int> stck;
   	for (int i = 1;i <= q;i++) {
   		int l, r, k;
   		cin >> l >> r >> k;
   		g[r].push_back({l, k, i});
   	}
   	for (int i = 1;i <= n;i++) {
   		while (!stck.empty() && a[stck.back()] <= a[i])
   			stck.pop_back();
   		if (!stck.empty()) 
   			upd(1, 1, n, stck.back(), i, a[i] + stck.back());
   		for (auto u : g[i]) {
   			int l, k, ind;
   			tie(l, k, ind) = u;
   			ans[ind] = (qry(1, 1, n, l, i) <= k);
   		}
   		stck.push_back(i);
   	}
   	for (int i = 1;i <= q;i++)
   		cout << ans[i] << '\n';
	}
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 6 ms 27228 KB Output is correct
2 Correct 6 ms 27324 KB Output is correct
3 Incorrect 7 ms 27356 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 27228 KB Output is correct
2 Correct 6 ms 27324 KB Output is correct
3 Incorrect 7 ms 27356 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1241 ms 118164 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 83 ms 33872 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 27228 KB Output is correct
2 Correct 6 ms 27324 KB Output is correct
3 Incorrect 7 ms 27356 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 27228 KB Output is correct
2 Correct 6 ms 27324 KB Output is correct
3 Incorrect 7 ms 27356 KB Output isn't correct
4 Halted 0 ms 0 KB -