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;
#define N 1000005
struct ii{
int l, r, idx;
bool operator < (ii& o){
return l < o.l;
}
};
struct fw{
int n;
vector<int> bit;
fw(int siz){
n = siz;
bit.resize(n + 1, 0);
}
void ud(int pos, int val){
while (pos <= n){
bit[pos] = max(bit[pos], val);
pos += (pos & (-pos));
}
}
int get(int pos){
int rt = 0;
while (pos >= 1){
rt = max(rt, bit[pos]);
pos -= (pos & (-pos));
}
return rt;
}
};
int n, m, a[N], res[N];
vector<ii> vd, qr[N];
signed main(){
ios_base::sync_with_stdio(0);
cin.tie(NULL);
stack<int> st;
cin >> n >> m;
for (int i = 1; i <= n; i++){
cin >> a[i];
while (st.size() && a[st.top()] <= a[i]) st.pop();
if (st.size()){
vd.push_back({st.top(), i, 0});
}
st.push(i);
}
for (int i = 1; i <= m; i++){
int l, r, k;
cin >> l >> r >> k;
qr[l].push_back({k, r, i});
}
sort(vd.begin(), vd.end());
int j = (int) vd.size();
fw s1(n);
for (int i = n; i >= 1; i--){
while (j - 1 >= 0 && vd[j - 1].l >= i){
j--;
s1.ud(vd[j].r, a[vd[j].l] + a[vd[j].r]);
}
for (auto x : qr[i]){
res[x.idx] = (s1.get(x.r) <= x.l);
}
}
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... |