이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#include <vector>
#define ll long long
#define Max(a, b) (((a) < (b)) ? (b) : (a))
#pragma GCC optimize ("O3")
const int nmax = 1e6 + 5;
struct day {
int st, dr, ind;
ll k;
};
ll v[nmax], aint[4*nmax];
int ans[nmax], last[nmax];
std::vector<int>st;
std::vector<day>skema[nmax];
void update(int node, int st, int dr, int x, ll val) {
if (st == dr and st == x) {
aint[node] = Max(aint[node], val); return;
}
int mij = (st + dr) >> 1;
if(x<=mij) update(node << 1, st, mij, x, val);
else update(node << 1 | 1, mij + 1, dr, x, val);
aint[node] = Max(aint[node << 1], aint[node << 1 | 1]);
}
ll query(int node, int st, int dr, int x, int y) {
if (y<st or x>dr) return 0;
if (x <= st and dr <= y) return aint[node];
int mij = (st + dr) >> 1;
return Max(query(node << 1, st, mij, x, y), query(node << 1 | 1, mij + 1, dr, x, y));
}
int main()
{
std::ios::sync_with_stdio(false);
std::cin.tie(0);
std::cout.tie(0);
int n, m;
std::cin >> n >> m;
for (int i = 1; i <= n; i++) std::cin >> v[i];
st.push_back(n);
for (int i = n - 1; i >= 1; i--) {
while (!st.empty() and v[st.back()] < v[i]) last[st.back()] = i, st.pop_back();
st.push_back(i);
}
for (int i = 1; i <= m; i++) {
day aux;
std::cin >> aux.st >> aux.dr >> aux.k, aux.ind = i;
skema[aux.dr].push_back(aux);
}
for (int i = 1; i <= n; i++) {
if (last[i] != 0) update(1, 1, n, last[i], v[i] + v[last[i]]);
for (auto aux : skema[i]) ans[aux.ind] = (query(1, 1, n, aux.st, aux.dr) <= aux.k);
}
for (int i = 1; i <= m; i++) std::cout << ans[i] << "\n";
return 0;
}
# | 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... |