#include <iostream> // #include <fstream>
#include <vector>
#include <list>
#include <algorithm>
#include <math.h>
#include <tuple>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <set>
#include <map>
#include <climits>
#include <cassert>
using namespace std;
typedef long long ll;
#define all(v) v.begin(), v.end()
struct node {
int min, max, mxinv;
};
vector<node> st;
int len = 1;
node query(int f, int t, int i = 1, int s = 0, int e = len) {
if (f >= e || t <= s) return { INT_MAX, INT_MIN, INT_MIN };
if (f <= s && e <= t) return st[i];
node l = query(f, t, i * 2, s, (s + e) / 2);
node r = query(f, t, i * 2 + 1, (s + e) / 2, e);
node res;
res.min = min(l.min, r.min);
res.max = max(l.max, r.max);
res.mxinv = max(l.max - r.min, max(l.mxinv, r.mxinv));
return res;
}
int main()
{
int n, q; cin >> n >> q;
while (len < n) len *= 2;
st.resize(2 * len, { INT_MAX, INT_MIN, INT_MIN });
for (int i = len; i < len + n; i++) {
int a; cin >> a;
st[i] = { a, a, 0 };
}
for (int i = len - 1; i > 0; i--) {
node l = st[i * 2], r = st[i * 2 + 1];
st[i].min = min(l.min, r.min);
st[i].max = max(l.max, r.max);
st[i].mxinv = max(l.max - r.min, max(l.mxinv, r.mxinv));
}
while (q--) {
int f, t, k; cin >> f >> t >> k;
cout << (query(f - 1, t).mxinv <= k ? 1 : 0) << endl;
}
}
# |
결과 |
실행 시간 |
메모리 |
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 |
Incorrect |
2782 ms |
58920 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
226 ms |
5724 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 |
- |