Submission #600528

# Submission time Handle Problem Language Result Execution time Memory
600528 2022-07-21T02:44:44 Z penguinhacker Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++17
0 / 100
1899 ms 100820 KB
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define ar array

const int mxN=1e6;
int n, m, w[mxN], st[1<<21], lz[1<<21];
vector<ar<int, 3>> queries[mxN];
bool ans[mxN];

void psh(int u, int l, int r) {
	if (lz[u]) {
		st[u]+=lz[u];
		if (l!=r)
			lz[2*u]+=lz[u], lz[2*u+1]+=lz[u];
		lz[u]=0;
	}
}

void upd(int ql, int qr, int x, int u=1, int l=0, int r=n-1) {
	psh(u, l, r);
	if (l>qr||r<ql)
		return;
	if (ql<=l&&r<=qr) {
		lz[u]=x;
		psh(u, l, r);
		return;
	}
	int mid=(l+r)/2;
	upd(ql, qr, x, 2*u, l, mid);
	upd(ql, qr, x, 2*u+1, mid+1, r);
	st[u]=max(st[2*u], st[2*u+1]);
}

int qry(int ql, int qr, int u=1, int l=0, int r=n-1) {
	psh(u, l, r);
	if (l>qr||r<ql)
		return 0;
	if (ql<=l&&r<=qr)
		return st[u];
	int mid=(l+r)/2;
	return max(qry(ql, qr, 2*u, l, mid), qry(ql, qr, 2*u+1, mid+1, r));
}

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin >> n >> m;
	for (int i=0; i<n; ++i)
		cin >> w[i];
	for (int i=0; i<m; ++i) {
		int l, r, k;
		cin >> l >> r >> k, --l, --r;
		queries[r].push_back({l, k, i});
	}
	stack<int> st;
	for (int i=0; i<n; ++i) {
		while(st.size()&&w[i]>=w[st.top()])
			st.pop();
		if (st.size())
			upd(0, st.top(), w[i]+w[st.top()]-qry(st.top(), st.top()));
		for (auto [l, k, ind] : queries[i])
			ans[ind]=qry(l, i)<=k;
		st.push(i);
	}
	for (int i=0; i<m; ++i)
		cout << ans[i] << "\n";
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 13 ms 23812 KB Output is correct
2 Correct 15 ms 23764 KB Output is correct
3 Incorrect 14 ms 23764 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 13 ms 23812 KB Output is correct
2 Correct 15 ms 23764 KB Output is correct
3 Incorrect 14 ms 23764 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1899 ms 100820 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 147 ms 30564 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 13 ms 23812 KB Output is correct
2 Correct 15 ms 23764 KB Output is correct
3 Incorrect 14 ms 23764 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 13 ms 23812 KB Output is correct
2 Correct 15 ms 23764 KB Output is correct
3 Incorrect 14 ms 23764 KB Output isn't correct
4 Halted 0 ms 0 KB -