#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;}
void ono_min(int &MIN, int CMP) { if(CMP < MIN) MIN = 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, const int &st, const int &en,
const vi &L, const int &L_st, const int &L_en,
const vi &R, const int &R_st, const 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 cur_L = tl, cur_R = tm + 1, buba = 0;
for(int i = tl; i <= tr; i++) {
if(cur_L == tm + 1) {
sus[lvl][i] = sus[lvl + 1][cur_R];
cur_R++;
continue;
}
if(cur_R == tr + 1) {
sus[lvl][i] = sus[lvl + 1][cur_L];
cur_L++;
continue;
}
if(sus[lvl + 1][cur_L] <= sus[lvl + 1][cur_R]) {
sus[lvl][i] = sus[lvl + 1][cur_L];
cur_L++;
}
else {
sus[lvl][i] = sus[lvl + 1][cur_R];
ono_max(buba, sus[lvl + 1][cur_R]);
cur_R++;
}
}
if(buba != 0)
ono_max(str[idx].ans, str[idx * 2 + 1].max + buba);
// 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; ret.range = tmp[lvl];
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 cur_L = l, cur_R = tm + 1, buba = 0;
for(int i = l; i <= r; i++) {
if(cur_L == tm + 1) {
ret.range[i] = R_qr.range[cur_R];
cur_R++;
continue;
}
if(cur_R == r + 1) {
ret.range[i] = L_qr.range[cur_L];
cur_L++;
continue;
}
if(L_qr.range[cur_L] <= R_qr.range[cur_R]) {
ret.range[i] = L_qr.range[cur_L];
cur_L++;
}
else {
ret.range[i] = R_qr.range[cur_R];
ono_max(buba, R_qr.range[cur_R]);
cur_R++;
}
}
if(buba != 0)
ono_max(ret.ans, L_qr.max + buba);
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 |
131 ms |
262144 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
131 ms |
262144 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
99 ms |
262144 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
93 ms |
262144 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
131 ms |
262144 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
131 ms |
262144 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |