#include <bits/stdc++.h>
using namespace std;
constexpr int NMAX = 1e6;
typedef pair <int, int> PII;
struct Node {
vector <int> Order;
int Max;
int Worst;
Node () {
Order = {};
Max = 0;
Worst = 0;
}
};
int N, M;
int W[NMAX + 5];
Node arb[4*NMAX+2];
void Init (int nod, int a, int b) {
if (a == b) {
arb[nod].Order.push_back(W[a]);
return;
}
int mij = (a + b) / 2;
Init(2*nod, a, mij);
Init(2*nod+1, mij+1, b);
int i = 0, j = 0;
while (i < arb[2*nod].Order.size() && j < arb[2*nod+1].Order.size()) {
if (arb[2*nod].Order[i] > arb[2*nod+1].Order[j]) {
arb[nod].Worst = arb[2*nod].Order[i] + arb[2*nod+1].Order[j];
arb[nod].Order.push_back(arb[2*nod+1].Order[j]);
++ j;
}
else {
arb[nod].Order.push_back(arb[2*nod].Order[i]);
++ i;
}
}
while (i < arb[2*nod].Order.size()) {
arb[nod].Order.push_back(arb[2*nod].Order[i]);
arb[nod].Worst = arb[2*nod].Order[i] + arb[2*nod+1].Order.back();
++ i;
}
while (j < arb[2*nod+1].Order.size()) {
arb[nod].Order.push_back(arb[2*nod+1].Order[j]);
++ j;
}
arb[nod].Worst = max(arb[nod].Worst, max(arb[2*nod].Worst, arb[2*nod+1].Worst));
arb[nod].Max = arb[nod].Order.back();
}
void Answer (int nod, int a, int b, int qa, int qb, int &answer, int &Maximum) {
if (qa <= a && b <= qb) {
answer = max(answer, arb[nod].Worst);
auto it = upper_bound(arb[nod].Order.begin(), arb[nod].Order.end(), Maximum);
if (it != arb[nod].Order.begin()) {
it = prev(it);
answer = max(answer, (*it) + Maximum);
}
Maximum = max(Maximum, arb[nod].Order.back());
return;
}
int mij = (a + b) / 2;
if (qa <= mij) Answer(2*nod, a, mij, qa, qb, answer, Maximum);
if (mij < qb) Answer(2*nod+1, mij+1, b, qa, qb, answer, Maximum);
}
void Read () {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cin >> N >> M;
for (int i = 1; i <= N; ++ i )
cin >> W[i];
}
int ans = 0, Max = 0;
void Solve () {
Init(1, 1, N);
for (int i = 1; i <= M; ++ i ) {
int l, r, k;
cin >> l >> r >> k;
ans = Max = 0;
Answer(1, 1, N, l, r, ans, Max);
if (ans > k) cout << 0 << '\n';
else cout << 1 << '\n';
}
}
int main () {
Read();
Solve();
return 0;
}
Compilation message
sortbooks.cpp: In function 'void Init(int, int, int)':
sortbooks.cpp:39:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
39 | while (i < arb[2*nod].Order.size() && j < arb[2*nod+1].Order.size()) {
| ~~^~~~~~~~~~~~~~~~~~~~~~~~~
sortbooks.cpp:39:45: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
39 | while (i < arb[2*nod].Order.size() && j < arb[2*nod+1].Order.size()) {
| ~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
sortbooks.cpp:54:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
54 | while (i < arb[2*nod].Order.size()) {
| ~~^~~~~~~~~~~~~~~~~~~~~~~~~
sortbooks.cpp:62:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
62 | while (j < arb[2*nod+1].Order.size()) {
| ~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
59 ms |
125464 KB |
Output is correct |
2 |
Correct |
59 ms |
125560 KB |
Output is correct |
3 |
Correct |
67 ms |
125560 KB |
Output is correct |
4 |
Correct |
60 ms |
125516 KB |
Output is correct |
5 |
Correct |
61 ms |
125740 KB |
Output is correct |
6 |
Correct |
60 ms |
125500 KB |
Output is correct |
7 |
Correct |
60 ms |
125560 KB |
Output is correct |
8 |
Correct |
60 ms |
125600 KB |
Output is correct |
9 |
Incorrect |
59 ms |
125496 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
59 ms |
125464 KB |
Output is correct |
2 |
Correct |
59 ms |
125560 KB |
Output is correct |
3 |
Correct |
67 ms |
125560 KB |
Output is correct |
4 |
Correct |
60 ms |
125516 KB |
Output is correct |
5 |
Correct |
61 ms |
125740 KB |
Output is correct |
6 |
Correct |
60 ms |
125500 KB |
Output is correct |
7 |
Correct |
60 ms |
125560 KB |
Output is correct |
8 |
Correct |
60 ms |
125600 KB |
Output is correct |
9 |
Incorrect |
59 ms |
125496 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
470 ms |
262144 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
232 ms |
140624 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
59 ms |
125464 KB |
Output is correct |
2 |
Correct |
59 ms |
125560 KB |
Output is correct |
3 |
Correct |
67 ms |
125560 KB |
Output is correct |
4 |
Correct |
60 ms |
125516 KB |
Output is correct |
5 |
Correct |
61 ms |
125740 KB |
Output is correct |
6 |
Correct |
60 ms |
125500 KB |
Output is correct |
7 |
Correct |
60 ms |
125560 KB |
Output is correct |
8 |
Correct |
60 ms |
125600 KB |
Output is correct |
9 |
Incorrect |
59 ms |
125496 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
59 ms |
125464 KB |
Output is correct |
2 |
Correct |
59 ms |
125560 KB |
Output is correct |
3 |
Correct |
67 ms |
125560 KB |
Output is correct |
4 |
Correct |
60 ms |
125516 KB |
Output is correct |
5 |
Correct |
61 ms |
125740 KB |
Output is correct |
6 |
Correct |
60 ms |
125500 KB |
Output is correct |
7 |
Correct |
60 ms |
125560 KB |
Output is correct |
8 |
Correct |
60 ms |
125600 KB |
Output is correct |
9 |
Incorrect |
59 ms |
125496 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |