#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 5;
int a[N], p[N], cep[N];
int main () {
// freopen ("input.txt", "r", stdin);
int n, m;
cin >> n >> m;
for (int i = 1; i <= n; ++i) {
cin >> a[i];
}
for (int i = 1; i <= n - 1; ++i) {
if (a[i] > a[i + 1]) {
p[i] = 1;
}
}
for (int i = 1; i <= n; ++i) p[i] += p[i - 1];
stack <int> s;
for (int i = 1; i <= n; ++i) {
cep[i] = -1;
while (!s.empty() and a[s.top()] <= a[i]) s.pop();
if (!s.empty()) {
cep[i] = s.top();
}
s.push(i);
}
for (int i = 1; i <= m; ++i) {
int l, r, k;
cin >> l >> r >> k;
if (p[r - 1] - p[l - 1] == 0) {
cout << "0\n";
continue;
}
bool tr = 0;
for (int j = l; j <= r; ++j) {
if (cep[j] != -1) {
if (a[cep[j]] + a[j] > k) {
tr = 1;
break;
}
}
}
if (tr) cout << "0\n";
else cout << "1\n";
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4440 KB |
Output is correct |
2 |
Incorrect |
1 ms |
2396 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4440 KB |
Output is correct |
2 |
Incorrect |
1 ms |
2396 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2125 ms |
45920 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
672 ms |
10736 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4440 KB |
Output is correct |
2 |
Incorrect |
1 ms |
2396 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4440 KB |
Output is correct |
2 |
Incorrect |
1 ms |
2396 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |