#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 = 2e5 + 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 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);
}
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 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 |
Correct |
28 ms |
66888 KB |
Output is correct |
2 |
Correct |
26 ms |
66712 KB |
Output is correct |
3 |
Incorrect |
72 ms |
66884 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
28 ms |
66888 KB |
Output is correct |
2 |
Correct |
26 ms |
66712 KB |
Output is correct |
3 |
Incorrect |
72 ms |
66884 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
417 ms |
143072 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3017 ms |
67392 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
28 ms |
66888 KB |
Output is correct |
2 |
Correct |
26 ms |
66712 KB |
Output is correct |
3 |
Incorrect |
72 ms |
66884 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
28 ms |
66888 KB |
Output is correct |
2 |
Correct |
26 ms |
66712 KB |
Output is correct |
3 |
Incorrect |
72 ms |
66884 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |