Submission #334070

#TimeUsernameProblemLanguageResultExecution timeMemory
334070jiahngHedgehog Daniyar and Algorithms (IZhO19_sortbooks)C++14
0 / 100
3067 ms99188 KiB
//https://oj.uz/problem/view/IZhO19_sortbooks

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<ll,ll> pi;
typedef vector <ll> vi;
typedef vector <pi> vpi;
typedef pair<pi,ll> pii;
typedef set <ll> si;
typedef long double ld;
#define f first
#define s second
#define FOR(i,s,e) for(ll i=s;i<=ll(e);++i)
#define DEC(i,s,e) for(ll i=s;i>=ll(e);--i)
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define lbd(x, y) lower_bound(all(x), y)
#define ubd(x, y) upper_bound(all(x), y)
#define aFOR(i,x) for (auto i: x)
#define mem(x,i) memset(x,i,sizeof x)
#define fast ios_base::sync_with_stdio(false),cin.tie(0)
typedef pair <pi,pi> pipi;
typedef pair <ll, pi> ipi;
#define maxn 1000001
#define INF (1e9 + 10)

int N, M, W[maxn];
pipi A[maxn];
int ans[maxn];
int a,b,c;

pi minmax(pi i,pi j){
	i.f = min(i.f, j.f);
	i.s = max(i.s,j.s);
	return i;
}
struct node{
	int s,e,m,val,mxval,mnval;
	node *l,*r;
	node(int ss,int ee){
		s = ss; e = ee; m = (s + e) / 2;
		
		if (s == e){
			mxval = mnval = W[s];
			val = 0;
		}else{
			l = new node(s,m); r = new node(m + 1, e);
			mxval = max(l->mxval, r->mxval);
			mnval = min(l->mnval, r->mnval);
			
			val = max(l->val, r->val);
			if (l->mxval > r->mnval){
				int idx = lower_bound(W + r->s, W + r->e + 1, l->mxval) - W - 1;
				
				val = max(val, l->mxval + W[idx]);
			}
		}
	}
	
	pi minmaxqry(int a,int b){
		if (a <= s && e <= b) return pi(mnval, mxval);
		if (a > e || s > b) return pi(INF,-1);
		return minmax(l->minmaxqry(a,b), r->minmaxqry(a,b));
	}
	
	int qry(int a,int b){
		if (a <= s && e <= b) return val;
		
		if (a > e || s > b) return 0;
		pi lminmax = l->minmaxqry(a,b);
		pi rminmax = r->minmaxqry(a,b);
		
		int ans = max(l->qry(a,b), r->qry(a,b));
		if (lminmax.s > rminmax.f){
			int idx = lower_bound(W + m + 1, W + b + 1, lminmax.s) - W - 1;
			ans = max(ans, l->mxval + W[idx]);
		}
		return ans;
	}
}*root;
		
		

int main(){
	fast;
	
	cin >> N >> M;
	
	FOR(i,1,N) cin >> W[i];
	root = new node(1,N);
	
	FOR(i,1,M){
		cin >> a >> b >> c;
		if (root->qry(a,b) <= c) cout << 1 << '\n';
		else cout << 0 << '\n';
	}
	
}

#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...