이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
const int N = 1'000'100;
const int M = (1 << 20);
int tr[2 * M];
void update(int pos, int val) {
for (tr[pos += M] = val; pos > 1; pos >>= 1)
tr[pos >> 1] = max(tr[pos], tr[pos ^ 1]);
}
int get(int ql, int qr) {
int res = 0;
for (ql += M, qr += M + 1; ql < qr; ql >>= 1, qr >>= 1) {
if (ql & 1) res = max(res, tr[ql++]);
if (qr & 1) res = max(res, tr[--qr]);
}
return res;
}
int n, m;
int w[N];
vector<int> qrs[N];
struct query {
int l, r, k;
} Q[N];
bool res[N];
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n >> m;
for (int i = 1; i <= n; i++)
cin >> w[i];
for (int i = 1; i <= m; i++) {
cin >> Q[i].l >> Q[i].r >> Q[i].k;
qrs[Q[i].r].push_back(i);
}
vector<int> st;
for (int r = 1; r <= n; r++) {
while (!st.empty() && w[st.back()] <= w[r])
st.pop_back();
if (!st.empty())
update(st.back(), w[st.back()] + w[r]);
for (int i : qrs[r]) {
res[i] = (get(Q[i].l, Q[i].r) <= Q[i].k);
}
st.push_back(r);
}
for (int i = 1; i <= m; i++)
cout << res[i] << '\n';
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |