#include <bits/stdc++.h>
using namespace std;
constexpr int NMAX = 1e6;
struct Node {
Node *Left, *Right;
vector <int> Order;
int Max;
int Worst;
Node () {
Left = Right = nullptr;
Order = {};
Max = 0;
Worst = 0;
}
};
int N, M;
int W[NMAX + 5];
Node* Tree;
void Init (Node *Tree, int a, int b) {
if (a == b) {
Tree->Order.push_back(W[a]);
Tree->Max = W[a];
Tree->Worst = 0;
return;
}
int mij = (a + b) / 2;
Tree->Left = new Node;
Tree->Right = new Node;
Init(Tree->Left, a, mij);
Init(Tree->Right, mij+1, b);
int i = 0, j = 0;
Tree->Worst = 0;
while (i < Tree->Left->Order.size() && j < Tree->Right->Order.size()) {
if (Tree->Left->Order[i] > Tree->Right->Order[j]) {
Tree->Worst = max(Tree->Worst, Tree->Left->Order[i] + Tree->Right->Order[j]);
Tree->Order.push_back(Tree->Right->Order[j]);
++ j;
}
else {
Tree->Order.push_back(Tree->Left->Order[i]);
++ i;
}
}
while (i < Tree->Left->Order.size()) {
Tree->Order.push_back(Tree->Left->Order[i]);
Tree->Worst = max(Tree->Worst, Tree->Left->Order[i] + Tree->Right->Order.back());
++ i;
}
while (j < Tree->Right->Order.size()) {
Tree->Order.push_back(Tree->Right->Order[j]);
++ j;
}
Tree->Worst = max(Tree->Worst, max(Tree->Left->Worst, Tree->Right->Worst));
Tree->Max = max(Tree->Left->Max, Tree->Right->Max);
}
int answer, Maximum;
void Answer (Node *Tree, int a, int b, int qa, int qb) {
if (qa <= a && b <= qb) {
answer = max(answer, Tree->Worst);
int st = 0, dr = Tree->Order.size()-1;
int pos = -1;
while (st <= dr) {
int mij = (st + dr) / 2;
if (Tree->Order[mij] < Maximum) {
pos = mij;
st = mij + 1;
}
else dr = mij - 1;
}
if (pos != -1)
answer = max(answer, Tree->Order[pos] + Maximum);
Maximum = max(Maximum, Tree->Max);
return;
}
int mij = (a + b) / 2;
if (qa <= mij) Answer(Tree->Left, a, mij, qa, qb);
if (mij < qb) Answer(Tree->Right, mij+1, b, qa, qb);
}
void Read () {
cin >> N >> M;
for (int i = 1; i <= N; ++ i )
cin >> W[i];
}
void Solve () {
Tree = new Node;
Init(Tree, 1, N);
for (int i = 1; i <= M; ++ i ) {
int l, r, k;
cin >> l >> r >> k;
answer = Maximum = 0;
Maximum = -1;
Answer(Tree, 1, N, l, r);
if (answer > k) cout << 0 << '\n';
else cout << 1 << '\n';
}
}
int main () {
Read();
Solve();
return 0;
}
Compilation message
sortbooks.cpp: In function 'void Init(Node*, int, int)':
sortbooks.cpp:47:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
47 | while (i < Tree->Left->Order.size() && j < Tree->Right->Order.size()) {
| ~~^~~~~~~~~~~~~~~~~~~~~~~~~~
sortbooks.cpp:47:46: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
47 | while (i < Tree->Left->Order.size() && j < Tree->Right->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 (i < Tree->Left->Order.size()) {
| ~~^~~~~~~~~~~~~~~~~~~~~~~~~~
sortbooks.cpp:70:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
70 | while (j < Tree->Right->Order.size()) {
| ~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
2 ms |
340 KB |
Output is correct |
7 |
Correct |
3 ms |
340 KB |
Output is correct |
8 |
Correct |
2 ms |
340 KB |
Output is correct |
9 |
Incorrect |
2 ms |
340 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
2 ms |
340 KB |
Output is correct |
7 |
Correct |
3 ms |
340 KB |
Output is correct |
8 |
Correct |
2 ms |
340 KB |
Output is correct |
9 |
Incorrect |
2 ms |
340 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
862 ms |
262144 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
381 ms |
26572 KB |
Output is correct |
2 |
Correct |
357 ms |
26512 KB |
Output is correct |
3 |
Correct |
376 ms |
26504 KB |
Output is correct |
4 |
Correct |
385 ms |
26688 KB |
Output is correct |
5 |
Correct |
358 ms |
26564 KB |
Output is correct |
6 |
Correct |
320 ms |
26652 KB |
Output is correct |
7 |
Correct |
296 ms |
26588 KB |
Output is correct |
8 |
Correct |
362 ms |
26680 KB |
Output is correct |
9 |
Incorrect |
196 ms |
684 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
2 ms |
340 KB |
Output is correct |
7 |
Correct |
3 ms |
340 KB |
Output is correct |
8 |
Correct |
2 ms |
340 KB |
Output is correct |
9 |
Incorrect |
2 ms |
340 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
2 ms |
340 KB |
Output is correct |
7 |
Correct |
3 ms |
340 KB |
Output is correct |
8 |
Correct |
2 ms |
340 KB |
Output is correct |
9 |
Incorrect |
2 ms |
340 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |