#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef pair<int, int> pii;
#define ff first
#define ss second
const int mxl = 25;
const int mxn = 2e5 + 10;
vector<vi> sus(mxl, vi (mxn));
vector<vi> tmp(mxl, vi (mxn));
int a[mxn], n, m;
struct con {
int ans, max;
con() {ans = max = 0;}
} str[mxn * 4];
void ono_max(int &MAX, int CMP) { if(MAX < CMP) MAX = CMP;}
void ono_min(int &MIN, int CMP) { if(MIN > CMP) MIN = CMP;}
void build(int idx, int lvl, int tl, int tr) {
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);
int L = tl, R = tm + 1, i = tl;
while(1) {
if(L == tm + 1 && R == tr + 1) break;
if(L == tm + 1) {
sus[lvl][i] = sus[lvl + 1][R];
i++, R++;
continue;
}
if(R == tr + 1) {
sus[lvl][i] = sus[lvl + 1][L];
i++, L++;
continue;
}
if(sus[lvl + 1][L] <= sus[lvl + 1][R]) {
sus[lvl][i] = sus[lvl + 1][L];
L++, i++;
}
else {
sus[lvl][i] = sus[lvl + 1][R];
ono_max(str[idx].ans, str[idx * 2 + 1].max + sus[lvl][i]);
R++, i++;
}
}
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);
// cout << tl << ' ' << tr << ":\n";
// for(int i = tl; i <= tr; i++)
// cout << sus[lvl][i] << ' ';
// cout << "- " << str[idx].max << ' ' << str[idx].ans << '\n';
}
pair<con, bool> query(int idx, int lvl, int tl, int tr, int l, int r) {
if(tl == l && r == tr) return {str[idx], 1};
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);
pair<con, bool> L_qr = query(idx * 2 + 1, lvl + 1, tl, tm, l, tm);
pair<con, bool> R_qr = query(idx * 2 + 2, lvl + 1, tm + 1, tr, tm + 1, r);
con ret;
int L = l, R = tm + 1, i = l;
vi &L_next = (L_qr.ss) ? sus[lvl + 1] : tmp[lvl + 1];
vi &R_next = (R_qr.ss) ? sus[lvl + 1] : tmp[lvl + 1];
while(1) {
if(L == tm + 1 && R == tr + 1) break;
if(L == tm + 1) {
tmp[lvl][i] = R_next[R];
i++, R++;
continue;
}
if(R == tr + 1) {
tmp[lvl][i] = L_next[L];
i++, L++;
continue;
}
if(L_next[L] <= R_next[R]) {
tmp[lvl][i] = L_next[L];
L++, i++;
}
else {
tmp[lvl][i] = R_next[R];
ono_max(ret.ans, L_qr.ff.max + tmp[lvl][i]);
R++, i++;
}
}
ono_max(ret.ans, L_qr.ff.ans);
ono_max(ret.ans, R_qr.ff.ans);
ono_max(ret.max, L_qr.ff.max);
ono_max(ret.max, R_qr.ff.max);
return {ret, 0};
}
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;
pair<con, bool> q = query(0, 0, 1, n, l, r);
cout << (q.ff.ans <= k) << '\n';
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
20 ms |
46700 KB |
Output is correct |
2 |
Correct |
22 ms |
46576 KB |
Output is correct |
3 |
Incorrect |
21 ms |
46664 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
20 ms |
46700 KB |
Output is correct |
2 |
Correct |
22 ms |
46576 KB |
Output is correct |
3 |
Incorrect |
21 ms |
46664 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
112 ms |
95684 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3052 ms |
47324 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
20 ms |
46700 KB |
Output is correct |
2 |
Correct |
22 ms |
46576 KB |
Output is correct |
3 |
Incorrect |
21 ms |
46664 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
20 ms |
46700 KB |
Output is correct |
2 |
Correct |
22 ms |
46576 KB |
Output is correct |
3 |
Incorrect |
21 ms |
46664 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |