#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
vi t;
struct con {
int ans, max;
vi &range = t;
con() {
ans = max = 0;
}
};
void ono_max(int &MAX, int CMP) { if(CMP > MAX) MAX = CMP;}
const int mxl = 33;
const int mxn = 1e6 + 10;
vector<vi> sus(mxl, vi (mxn));
vector<vi> tmp(mxl, vi (mxn));
con str[mxn * 4];
int a[mxn], n, m;
int merge(
vi &edit, int st, int en,
vi &L, int L_st, int L_en,
vi &R, int R_st, int R_en) {
int ret = 0;
int cur_L = L_st, cur_R = R_st;
for(int i = st; i <= en; i++) {
if(cur_L == L_en + 1) {
edit[i] = R[cur_R];
cur_R++;
continue;
}
if(cur_R == R_en + 1) {
edit[i] = L[cur_L];
cur_L++;
continue;
}
if(L[cur_L] <= R[cur_R]) {
edit[i] = L[cur_L];
cur_L++;
}
else {
edit[i] = R[cur_R];
ono_max(ret, R[cur_R]);
cur_R++;
}
}
return ret;
}
void build(int idx, int lvl, int tl, int tr) {
str[idx].range = sus[lvl];
if(tl == tr) {
// cout << tl << ": " << a[tl] << '\n';
sus[lvl][tl] = a[tl];
str[idx].max = a[tl];
str[idx].ans = 0;
return;
}
int tm = (tl + tr) / 2;
build(idx * 2 + 1, lvl + 1, tl, tm);
build(idx * 2 + 2, lvl + 1, tm + 1, tr);
ono_max(str[idx].max, str[idx * 2 + 1].max);
ono_max(str[idx].max, str[idx * 2 + 2].max);
ono_max(str[idx].ans, str[idx * 2 + 1].ans);
ono_max(str[idx].ans, str[idx * 2 + 2].ans);
int t = merge(
sus[lvl], tl, tr,
sus[lvl + 1], tl, tm,
sus[lvl + 1], tm + 1, tr
);
if(t != 0)
ono_max(str[idx].ans, str[idx * 2 + 1].max + t);
// cout << tl << ' ' << tr << ":\n";
// for(int i = tl; i <= tr; i++)
// cout << sus[lvl][i] << ' ';
// cout << "- " << str[idx].max << ' ' << str[idx].ans << '\n';
}
con query(int idx, int lvl, int tl, int tr, int l, int r) {
if(tl == l && r == tr) return str[idx];
int tm = (tl + tr) / 2;
if(r <= tm) return query(idx * 2 + 1, lvl + 1, tl, tm, l, r);
if(tm < l) return query(idx * 2 + 2, lvl + 1, tm + 1, tr, l, r);
con L_qr = query(idx * 2 + 1, lvl + 1, tl, tm, l, tm);
con R_qr = query(idx * 2 + 2, lvl + 1, tm + 1, tr, tm + 1, r);
con ret;
ono_max(ret.max, L_qr.max);
ono_max(ret.max, R_qr.max);
ono_max(ret.ans, L_qr.ans);
ono_max(ret.ans, R_qr.ans);
int t = merge(
ret.range, l, r,
L_qr.range, l, tm,
R_qr.range, tm + 1, r
);
if(t != 0)
ono_max(ret.ans, L_qr.max + t);
return ret;
}
int main() {
cin >> n >> m;
for(int i = 1; i <= n; i++)
cin >> a[i];
build(0, 0, 1, n);
// for(int i = 1; i <= n; i++)
// cout << sus[0][i] << ' ';
while(m--) {
int l, r, k;
cin >> l >> r >> k;
con t = query(0, 0, 1, n, l, r);
cout << (t.ans <= k) << '\n';
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
94 ms |
262144 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
94 ms |
262144 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
73 ms |
262144 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
80 ms |
262144 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
94 ms |
262144 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
94 ms |
262144 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |