#include <bits/stdc++.h>
using namespace std;
#ifdef DEBUG
#include "debug.hpp"
#define debug(x...) cerr << "[" << #x << "] = [", _print(x)
#else
#define debug(x...)
#endif
#define int long long
struct Query {
int l, w, id;
};
const int MAX = 1e6 + 5;
int n, Q, a[MAX], L[MAX], rs[MAX], tree[MAX];
vector<Query> g[MAX];
void update(int idx, int val) {
for (int i = idx; i; i -= i & -i)
tree[idx] = max(tree[idx], val);
}
int query(int idx) {
int rs = 0;
for (int i = idx; i <= n; i += i & -i)
rs = max(rs, tree[i]);
return rs;
}
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
#ifdef DEBUG
freopen("../_input", "r", stdin);
#endif
cin >> n >> Q;
for (int i = 1; i <= n; i++) {
cin >> a[i];
L[i] = i - 1;
int tmp = i - 1;
while (tmp && a[i] >= a[tmp])
L[i] = tmp = L[tmp];
}
int l, r, w;
for (int i = 1; i <= Q; i++) {
cin >> l >> r >> w;
g[r].push_back({l, w, i});
}
for (int i = 1; i <= n; i++) {
if (L[i])
update(L[i], a[L[i]] + a[i]);
for (auto q: g[i])
rs[q.id] = query(q.l) <= q.w;
}
for (int i = 1; i <= Q; i++)
cout << rs[i] << '\n';
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
23764 KB |
Output is correct |
2 |
Correct |
12 ms |
23812 KB |
Output is correct |
3 |
Incorrect |
12 ms |
23764 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
23764 KB |
Output is correct |
2 |
Correct |
12 ms |
23812 KB |
Output is correct |
3 |
Incorrect |
12 ms |
23764 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
889 ms |
121496 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
84 ms |
32416 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
23764 KB |
Output is correct |
2 |
Correct |
12 ms |
23812 KB |
Output is correct |
3 |
Incorrect |
12 ms |
23764 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
23764 KB |
Output is correct |
2 |
Correct |
12 ms |
23812 KB |
Output is correct |
3 |
Incorrect |
12 ms |
23764 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |