# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
377234 | ntabc05101 | Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) | C++14 | 821 ms | 128748 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#ifndef LOCAL
#define NDEBUG 1
#endif // LOCAL
#include<bits/stdc++.h>
#define taskname ""
#define f first
#define s second
const int max_n=100000;
int nodes[max_n<<2];
int L[max_n<<2], H[max_n<<2];
void buildRange(int node, int low, int high) {
L[node]=low, H[node]=high;
if (low==high) {
return ;
}
int mid=low+high>>1;
buildRange(node<<1, low, mid);
buildRange(node<<1|1, mid+1, high);
}
void update(int node, int posq, int value) {
if (L[node]==H[node]) {
nodes[node]=std::max(nodes[node], value);
return ;
}
if (posq>H[node<<1]) {
update(node<<1|1, posq, value);
}
else {
update(node<<1, posq, value);
}
nodes[node]=std::max(nodes[node<<1], nodes[node<<1|1]);
}
int get(int node, int leftq, int rightq) {
if (leftq>H[node] or rightq<L[node]) {
return 0;
}
if (leftq<=L[node] and rightq>=H[node]) {
return nodes[node];
}
return std::max(get(node<<1, leftq, rightq), get(node<<1|1, leftq, rightq));
}
int main() {
if (fopen(taskname".inp", "r")) {
freopen(taskname".inp", "r", stdin);
freopen(taskname".out", "w", stdout);
}
else if (fopen(taskname".in", "r")) {
freopen(taskname".in", "r", stdin);
freopen(taskname".out", "w", stdout);
}
std::ios_base::sync_with_stdio(0); std::cin.tie(0);
int n, m; std::cin>>n>>m;
int w[n];
for (int i=0; i<n; ++i) {
std::cin>>w[i];
}
std::vector< std::pair< std::pair<int, int>, int > > q[n];
for (int i=0; i<m; ++i) {
int left, right, k; std::cin>>left>>right>>k;
--left, --right;
q[right].push_back({{left, k}, i});
}
bool result[m];
buildRange(1, 0, n-1);
std::deque<int> deq;
for (int i=0; i<n; ++i) {
while (!deq.empty() and w[deq.back()]<=w[i]) {
deq.pop_back();
}
if (!deq.empty()) {
update(1, deq.back(), w[deq.back()]+w[i]);
}
deq.push_back(i);
for (auto& Q: q[i]) {
result[Q.s]=(get(1, Q.f.f, i)<=Q.f.s);
}
}
for (int i=0; i<m; ++i) {
std::cout<<result[i]<<"\n";
}
return 0;
}
Compilation message (stderr)
# | 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... |