Submission #709781

# Submission time Handle Problem Language Result Execution time Memory
709781 2023-03-14T12:16:18 Z WonderfulWhale Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++17
0 / 100
440 ms 262144 KB
#include<bits/stdc++.h>
using namespace std;

#define int int64_t
#define pb push_back
#define pii pair<int, int>
#define st first
#define nd second
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()

vector<pii> v[1000009];
int tab[1000009];

struct SegTree {
	const static int T = 1<<20;
	vector<pii> t[2*T];
	void build(int n) {
		for(int i=0;i<n;i++) {
			if(sz(v[i])==0) continue;
			t[i+T].pb(v[i][0]);
			for(int j=1;j<sz(v[i]);j++) {
				t[i+T].pb({v[i][j].st, max(v[i][j].nd, t[i+T].back().nd)});
			}
		}
		for(int i=T-1;i>=1;i--) {
			int l = 2*i;
			int r = 2*i+1;
			int a = 0;
			int b = 0;
			while(a!=sz(t[l])||b!=sz(t[r])) {
				if(a==sz(t[l])) {
					t[i].pb({t[r][b].st, max(t[r][b].nd, sz(t[i])?t[i].back().nd:(int)0)});
					b++;
				} else if(b==sz(t[r])) {
					t[i].pb({t[l][a].st, max(t[l][a].nd, sz(t[i])?t[i].back().nd:(int)0)});
					a++;
				} else if(t[l][a].st<=t[r][b].st) {
					t[i].pb({t[l][a].st, max(t[l][a].nd, sz(t[i])?t[i].back().nd:(int)0)});
					a++;
				} else {
					t[i].pb({t[r][b].st, max(t[r][b].nd, sz(t[i])?t[i].back().nd:(int)0)});
					b++;
				}
			}
		}
	}
	int query(int val, int l, int r, int tl=0, int tr=T-1, int v=1) {
		if(l > r) return 0;
		if(tl==l&&tr==r) {
			int s = -1;
			int e = sz(t[v]);
			while(e-s>1) {
				int m = (e+s)/2;
				if(t[v][m].st<=val) s = m;
				else e = m;
			}
			if(s!=-1) return t[v][s].nd;
			return 0;
		}
		int tm = (tl+tr)/2;
		return max(query(val, l, min(r, tm), tl, tm, 2*v), query(val, max(l, tm+1), r, tm+1, tr, 2*v+1));
	}
};

SegTree seg;

int32_t main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	int n, q;
	cin >> n >> q;
	for(int i=0;i<n;i++) {
		cin >> tab[i];
	}
	vector<pii> s;
	for(int i=0;i<n;i++) {
		while(sz(s)&&s.back().nd<=tab[i]) {
			s.pop_back();
		}
		if(sz(s)) {
			v[s.back().st].pb({i, tab[i]+tab[s.back().st]});
		}
		s.pb({i, tab[i]});
	}
	seg.build(n);
	for(int i=0;i<q;i++) {
		int l, r, k;
		cin >> l >> r >> k;
		cout << (seg.query(r, l, r)<=k) << "\n";
	}
}
# Verdict Execution time Memory Grader output
1 Correct 48 ms 73032 KB Output is correct
2 Correct 45 ms 73048 KB Output is correct
3 Incorrect 43 ms 73072 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 48 ms 73032 KB Output is correct
2 Correct 45 ms 73048 KB Output is correct
3 Incorrect 43 ms 73072 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 407 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 440 ms 118324 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 48 ms 73032 KB Output is correct
2 Correct 45 ms 73048 KB Output is correct
3 Incorrect 43 ms 73072 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 48 ms 73032 KB Output is correct
2 Correct 45 ms 73048 KB Output is correct
3 Incorrect 43 ms 73072 KB Output isn't correct
4 Halted 0 ms 0 KB -