#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define sz(v) (int)(v).size()
#define all(v) (v).begin(), v.end()
#define ff first
#define ss second
#define pii pair<int, int>
int main() {
ios::sync_with_stdio(false); cin.tie(nullptr);
int n, q;
cin >> n >> q;
vector<int> a(n);
for (auto &i : a)
cin >> i;
int sz = sqrt(n);
while (sz * sz < n) sz++;
while (sz * sz > n) sz--;
vector<int> b = a, v((n - 1) / sz + 1);
for (int i = 0; i < sz(v); i++) {
set<int> s;
for (int j = i * sz; j < min(n, (i + 1) * sz); j++) {
if (!s.empty() && a[j] < *--s.end()) v[i] = max(v[i], a[j] + *s.upper_bound(a[j]));
s.insert(a[j]);
}
sort(b.begin() + i * sz, b.begin() + min(n, (i + 1) * sz));
}
while (q--) {
int l, r, k;
cin >> l >> r >> k; l--; r--;
if (l / sz == r / sz) {
set<int> s;
bool tr = true;
for (int i = l; i <= r && tr; i++) {
tr = (s.empty() || a[i] >= *--s.end() || a[i] + *s.upper_bound(a[i]) <= k);
s.insert(a[i]);
}
cout << tr << '\n';
continue;
}
int mx = 0;
set<int> s;
bool tr = true;
for (int i = l; i < (l / sz + 1) * sz && tr; i++) {
mx = max(mx, a[i]);
tr = (s.empty() || a[i] >= *--s.end() || a[i] + *s.upper_bound(a[i]) <= k);
s.insert(a[i]);
}
if (!tr) {
cout << "0\n";
continue;
}
for (int i = l / sz + 1; i < r / sz && tr; i++) {
int x = i * sz, y = (i + 1) * sz - 1;
tr = (max(v[i], (mx > b[x] ? mx + *--lower_bound(b.begin() + x, b.end() + y + 1, mx) : 0)) <= k);
mx = max(mx, b[y]);
}
int x = r / sz * sz;
if (!tr || (mx > b[x] && mx + *--lower_bound(b.begin() + x, b.end() + r + 1, mx) > k)) {
cout << "0\n";
continue;
}
s.clear();
for (int i = x; i <= r && tr; i++) {
tr = (s.empty() || a[i] >= *--s.end() || a[i] + *s.upper_bound(a[i]) <= k);
s.insert(a[i]);
}
cout << tr << '\n';
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
542 ms |
41800 KB |
Output is correct |
2 |
Correct |
568 ms |
42544 KB |
Output is correct |
3 |
Correct |
542 ms |
42216 KB |
Output is correct |
4 |
Correct |
529 ms |
42484 KB |
Output is correct |
5 |
Execution timed out |
3019 ms |
19792 KB |
Time limit exceeded |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
644 ms |
3412 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |