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;
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
const int maxx = 1e6+6;
int tr[maxx];
int n;
vector <int> ad[maxx*4];
void add(int id, int val){
while(id > 0){
tr[id] = max(tr[id], val);
id -= id & -id;
}
}
int get(int id){
int s = 0;
while(id <= n){
s = max(s, tr[id]);
id += id & -id;
}
return s;
}
void S()
{
int m;
cin >> n >> m;
vector <int> a(n+1), b(n+1), c(n+1), k(n+1);
for(int i = 1; i <= n; i ++)
cin >> a[i];
vector <int> st;
for(int i = 1; i <= m; i ++){
cin >> b[i] >> c[i] >> k[i];
ad[c[i]].push_back(i);
}
vector <bool> ans(m+1);
for(int i = 1; i <= n; i ++){
while(st.size() > 0 && a[i] >= a[st.back()])
st.pop_back();
int x = st.size() == 0 ? 0 : st.back();
add(x, a[x] + a[i]);
// cout << x << "\n";
for(int it : ad[i])
ans[it] = (get(b[it]) <= k[it]); //, cout << get(b[it]) << " ";
//cout << "\n";
st.push_back(i);
}
/* for(int i = 1; i <= n; i ++)
cout << tr[i] << " ";
cout << "yeah\n";*/
for(int i = 1; i <= m; i++)
cout << ans[i] << "\n";
}
int main()
{
IOS;
/*int t;
cin >> t;
while(t --)*/
S();
}
# | 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... |