This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const int MAXN = 1000000;
struct kveri{
int l, val, ind;
};
vector <kveri> queries[MAXN+5];
int bit[MAXN+5];
int a[MAXN+5];
void upd(int x, int val){
while(x <= MAXN){
bit[x] = max(bit[x], val);
x += x & -x;
}
}
int query(int x){
int res = 0;
while(x){
res = max(res, bit[x]);
x -= x & -x;
}
return res;
}
bool res[MAXN+5];
int main(){
ios_base::sync_with_stdio(false), cin.tie(0);
cout.precision(10);
cout << fixed;
int n, m;
cin >> n >> m;
for(int i=1; i<=n; i++) cin >> a[i];
for(int i=1; i<=m; i++){
int l, r, v;
cin >> l >> r >> v;
queries[r].push_back({l, v, i});
}
stack <int> st;
for(int i=1; i<=n; i++){
while(!st.empty() && a[st.top()] <= a[i]) st.pop();
if(!st.empty()){
upd(MAXN+1-st.top(), a[st.top()] + a[i]);
}
for(auto kveri : queries[i]){
res[kveri.ind] = (query(MAXN-kveri.l+1) <= kveri.val);
}
st.push(i);
}
for(int i=1; i<=m; i++) cout << res[i] << "\n";
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... |