#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = array<int, 2>;
#define all(x) begin(x), end(x)
#define sz(x) (int) (x).size()
int main() {
cin.tie(0) -> sync_with_stdio(0);
int n, q;
cin >> n >> q;
vector<int> w(n);
for (int &i : w) { cin >> i; }
for (int t = 0; t < q; t++) {
int l, r, k;
cin >> l >> r >> k;
--l, --r;
vector<int> sorted;
for (int i = l; i <= r; i++) {
sorted.push_back(w[i]);
}
sort(all(sorted));
int lst = -1;
for (int i = r; i >= l; i--) {
if (sorted[i - l] != w[i]) {
lst = i;
break;
}
}
int ans = -1;
if (lst != -1) {
int mn = INT_MAX, mx = -1;
for (int i = l; i <= lst; i++) {
mn = min(mn, w[i]);
mx = max(mx, w[i]);
}
ans = mn + mx;
}
cout << (ans <= k) << "\n";
}
}
// this is just for subtasks lmao to see if my sol is right
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3007 ms |
21696 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3050 ms |
2316 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |