#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
const int mxn = 1e6 + 10;
vi a(mxn);
int n, m;
struct node {
int mx, mn;
bool flag;
} st[mxn * 4];
void build(int id, int tl, int tr) {
if(tl == tr) {
st[id].mn = a[tl];
st[id].mx = a[tr];
st[id].flag = 0;
return;
}
int tm = (tl + tr) / 2;
build(id * 2 + 1, tl, tm);
build(id * 2 + 2, tm + 1, tr);
st[id].mx = max(st[id * 2 + 1].mx, st[id * 2 + 2].mx);
st[id].mn = min(st[id * 2 + 1].mn, st[id * 2 + 2].mn);
if(st[id * 2 + 1].flag) st[id].flag = 1;
if(st[id * 2 + 2].flag) st[id].flag = 1;
if(st[id * 2 + 1].mx > st[id * 2 + 2].mn)
st[id].flag = 1;
}
node query(int id, int tl, int tr, int l, int r) {
if(tl == l && r == tr) return st[id];
int tm = (tl + tr) / 2;
if(r <= tm) return query(id * 2 + 1, tl, tm, l, r);
if(tm < l) return query(id * 2 + 2, tm + 1, tr, l, r);
node L_qr = query(id * 2 + 1, tl, tm, l, tm);
node R_qr = query(id * 2 + 2, tm + 1, tr, tm + 1, r);
node ret;
ret.mx = max(L_qr.mx, R_qr.mx);
ret.mn = min(L_qr.mn, R_qr.mn);
if(L_qr.flag) ret.flag = 1;
if(R_qr.flag) ret.flag = 1;
if(L_qr.mx > R_qr.mn) ret.flag = 1;
return ret;
}
int main() {
cin >> n >> m;
for(int i = 1; i <= n; i++)
cin >> a[i];
build(0, 1, n);
while(m--) {
int l, r, k;
cin >> l >> r >> k;
cout << !query(0, 1, n, l, r).flag << '\n';
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
4188 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
4188 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2698 ms |
63172 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
217 ms |
10468 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
4188 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
4188 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |