Submission #206803

#TimeUsernameProblemLanguageResultExecution timeMemory
206803bashHedgehog Daniyar and Algorithms (IZhO19_sortbooks)C++17
0 / 100
1242 ms47372 KiB
/**
SXR0aXAkI0JwbXptI3FhI3Z3I293bCNqY2IjUG0jMCNicG0jVHFkcXZvLyNCcG0jQW10bjBhY2phcWFicXZvLyNNYm16dml0MSNWdyNhdGN1am16I2tpdiNhbXF9bSNQcXUjVnd6I0F0bW14MSNQcWEjaXptI2l0dCNicHF2b2EjUXYjYnBtI3BtaWRtdmEjaXZsI3d2I21pemJwMSNFcHcjcWEjYnBtem0ja2l2I3F2Ym16a21sbSNRdiNQcWEjeHptYW12a20jbXtrbXhiI0lhI3BtI3htenVxYmJtYnBHI1BtI3N2d2VtYnAjRXBpYiMraXh4bWl6bWJwI2J3I1BxYSNrem1pYmN6bWEjSWEsI0ptbnd6bSN3eiNJbmJteiN3eiNKbXBxdmwjYnBtdTEjVnd6I2FwaXR0I2JwbXwja3d1eGlhYSNJY29wYiN3biNwcWEjc3Z3ZXRtbG9tI017a214YiNpYSNQbSNlcXR0bWJwMSNQcWEjYnB6d3ZtI2x3YnAjbXtibXZsI1dkbXojYnBtI3BtaWRtdmEjSXZsI3d2I21pemJwLyNpdmwjUG0jbm1tdG1icCNWdyNuaWJxb2NtI3F2I29jaXpscXZvI0l2bCN4em1hbXpkcXZvI2JwbXUvI053eiNQbSNxYSNicG0jVXdhYiNQcW9wMSNCcG0jQWN4em11bSMrcXYjb3R3enwsMQ==
*/
#include <cstring>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cassert>
 
#define F first
#define S second
#define endl '\n'
#define deb(x) cout<<#x<<' '<<x<<endl;
#define pb push_back
 using namespace __gnu_pbds;
using namespace std;

typedef tree<
int,
null_type,
less<int>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
/*
#ifdef IZI_KATKA
#define int __int64_t
#else
#define int __int64
#endif
*/
const long long MOD = 1e9 + 7;
const long long MAXN = 1e6 + 1;

typedef long long ll;

#define pii pair<int,int>
 
long long readInt() {
    bool minus1 = false;
    long long result = 0;
    char ch;
    ch = getchar();
    while (true) {
        if (ch == '-') break;
        if (ch >= '0' && ch <= '9') break;
        ch = getchar();
    }
    if (ch == '-') minus1 = true; else result = ch-'0';
    while (true) {
        ch = getchar();
        if (ch < '0' || ch > '9') break;
        result = result*10 + (ch - '0');
    }
    if (minus1)
        return -result;
    else
        return result;
}

struct query {
	int l, r, x, id;
};


int n, m;
int a[MAXN];
int lim[MAXN];
int t[MAXN*4];
int ans[MAXN];

void build(int v, int tl, int tr) {
	if (tl == tr) {
		t[v] = lim[tl];
		return;
	}
	int tm = (tl + tr)/ 2;
	build(v * 2, tl, tm);
	build(v * 2 + 1, tm + 1, tr);
	t[v] = max(t[v + v], t[v + v + 1]);
}

int get(int l, int r, int v = 1, int tl = 1, int tr = n) {
	if (l <= tl && tr <= r) {
	    return t[v];
	}
	if (r < tl || tr < l) {
		return 0;
	}
	int tm = (tl + tr) / 2;
	return max(get(l, r, v + v, tl, tm), get(l, r, v + v + 1, tm + 1, tr));
}

bool cmp(const query &a, const query &b) {
	if (a.r == b.r) {
		return a.l < b.l;		
	}
	return a.r < b.r;
}

int main() {
	#ifdef IZI_KATKA
	assert(freopen("input", "r", stdin));
    assert(freopen("output", "w", stdout));
    #endif
    n = readInt(), m = readInt();
    for (int i = 1; i <= n; i++) {
    	a[i] = readInt();
    }
    stack <int> kek; /// pos
    for (int i = 1; i <= n; i++) {
		while(!kek.empty() && a[kek.top()] <= a[i]) {
			kek.pop();
		}
		if (!kek.empty()) {
			int pos = kek.top();
			lim[pos] = max(lim[pos], a[i] + a[pos]);
		}
		kek.push(i);    	
    }
    build(1, 1, n);
    vector<query> queries;
    for (int i = 1; i <= m; i++) {
		query tmp;
		tmp.l = readInt(), tmp.r = readInt(), tmp.x = readInt();
		tmp.id = i;
		queries.pb(tmp);
    }
    sort(queries.begin(), queries.end(), cmp);
    for (query cur : queries) {
    	int L = cur.l;
    	int R = cur.r;
    	int X = cur.x;
    	ans[cur.id] = (get(L, R) <= X);
    }
    for (int i = 1; i <= m; i++) {
    	cout << ans[i] << endl;
    }
    return 0;
}
#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...