This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
//#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
//#pragma GCC optimize("O3,unroll-loops")
#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define pb push_back
#define ss second
#define ff first
#define vt vector
#define uid(a, b) uniform_int_distribution<int>(a, b)(mt)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int inf = 2e9;
const int mod = 1e9+7;
const int maxn = 1e6;
mt19937 mt(chrono::steady_clock::now().time_since_epoch().count());
int t[maxn * 4], it, val;
void upd(int v, int l, int r){
t[v] = max(t[v], val);
if(l + 1 == r){
return;
}
if(((l + r) >> 1) <= it)upd(v * 2 + 2, ((l + r) >> 1), r);
else upd(v * 2 + 1, l, ((l + r) >> 1));
}
int get(int v, int l, int r){
if(it <= l)return t[v];
if(r <= it)return 0;
return max(get(v * 2 + 1, l, ((l + r) >> 1)), get(v * 2 + 2, ((l + r) >> 1), r));
}
void solve() {
int n, m;
cin >> n >> m;
int w[n];
for(int i = 0; i < n; i++){
cin >> w[i];
}
vt<int> q[n];
int l[m], x[m], ans[m];
for(int j = 0, r; j < m; j++){
cin >> l[j] >> r >> x[j];
l[j]--, r--;
q[r].pb(j);
}
stack<int> st;
for(int i = 0; i < n; i++){
while(!st.empty() && w[st.top()] <= w[i])st.pop();
if(!st.empty()){
val = w[i] + w[st.top()];
it = st.top();
upd(0, 0, n);
}
st.push(i);
for(auto j : q[i]){
it = l[j];
ans[j] = get(0, 0, n);
}
}
for(int i = 0; i < m; i++)cout << (ans[i] <= x[i]) << '\n';
}
int main() {
ios_base::sync_with_stdio(0); cin.tie(0);
int times = 1; //cin >> times;
for(int i = 1; i <= times; i++) {
solve();
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |