Submission #154320

# Submission time Handle Problem Language Result Execution time Memory
154320 2019-09-20T14:09:57 Z nvmdava Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++17
0 / 100
214 ms 64144 KB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ff first
#define ss second

#define N 2010000
#define MOD 1000000007
#define INF 0x3f3f3f3f

pair<int, pair<int, int> > seg[N];

int a[N];

void build(int id, int l, int r){
	if(l == r){
		seg[id].ss.ff = a[l];
		seg[id].ss.ss = a[l];
		seg[id].ff = 0;
		return;
	}
	int m = (l + r) >> 1;
	build(id << 1, l, m);
	build(id << 1 | 1, m + 1, r);

	seg[id].ss.ss = min(seg[id << 1].ss.ss, seg[id << 1 | 1].ss.ss);
	seg[id].ss.ff = max(seg[id << 1].ss.ff, seg[id << 1 | 1].ss.ff);
	seg[id].ff = max(seg[id << 1].ff, seg[id << 1 | 1].ff);
	if(seg[id << 1].ss.ff > seg[id << 1 | 1].ss.ss){
		seg[id].ff = max(seg[id].ff, seg[id << 1].ss.ff + seg[id << 1 | 1].ss.ss);
	}
}

pair<int, pair<int, int> > query(int id, int l, int r, int L, int R){
	if(l == L && r == R){
		return seg[id];
	}
	int m = (l + r) >> 1;
	if(m >= R) return query(id << 1, l, m, L, R);
	if(m < L) return query(id << 1 | 1, m + 1, r, L, R);
	auto q1 = query(id << 1, l, m, L, m);
	auto q2 = query(id << 1 | 1, m + 1, r, m + 1, R);
	pair<int, pair<int, int> > q3;
	q3.ss.ss = min(q1.ss.ss, q2.ss.ss);
	q3.ss.ff = max(q1.ss.ff, q2.ss.ff);
	q3.ff = max(q1.ff, q2.ff);
	if(q1.ss.ff > q2.ss.ss){
		q3.ff = max(q3.ff, q1.ss.ff + q2.ss.ss);
	}
	return q3;
}

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

	mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
	
	int n, m;
	cin>>n>>m;

	for(int i = 1; i <= n; i++){
		cin>>a[i];
	}

	build(1, 1, n);

	while(m--){
		int l, r, k;
		cin>>l>>r>>k;
		cout<<(query(1, 1, n, l, r).ff <= k)<<'\n';
	}
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 252 KB Output is correct
2 Correct 3 ms 376 KB Output is correct
3 Incorrect 3 ms 404 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 252 KB Output is correct
2 Correct 3 ms 376 KB Output is correct
3 Incorrect 3 ms 404 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 214 ms 64144 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 124 ms 6068 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 252 KB Output is correct
2 Correct 3 ms 376 KB Output is correct
3 Incorrect 3 ms 404 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 252 KB Output is correct
2 Correct 3 ms 376 KB Output is correct
3 Incorrect 3 ms 404 KB Output isn't correct
4 Halted 0 ms 0 KB -