#include <bits/stdc++.h>
using namespace std;
vector<int> bks;
struct node{
int lo, hi, mid, heaviestswap;
vector<int> svals;
node *lft, *rght;
node(int l, int h){
lo = l;
hi = h;
mid = (l+h)/2;
if(l == h){
heaviestswap = 0;
svals.push_back(bks[l]);
}else{
lft = new node(l, mid);
rght = new node(mid+1, h);
heaviestswap = max(lft->heaviestswap, rght->heaviestswap);
bool hstbd = true;
int lmax = lft->svals.back();
if(lmax > rght->svals.back()){
hstbd = false;
heaviestswap = max(heaviestswap, lft->svals.back()+rght->svals.back());
}//*/
int lp = 0;
int rp = 0;
lft->svals.push_back(1000000009);
rght->svals.push_back(1000000009);
while(lp < lft->svals.size()-1 || rp < rght->svals.size()-1){
if(hstbd && rght->svals[rp] >= lmax){
hstbd = false;
if(rp != 0){
heaviestswap = max(heaviestswap, lmax+rght->svals[rp-1]);
}
}
if(lft->svals[lp] > rght->svals[rp]){
svals.push_back(rght->svals[rp]);
++rp;
}else{
svals.push_back(lft->svals[lp]);
++lp;
}
}
lft->svals.pop_back();
rght->svals.pop_back();
}
}
int ghs(int l, int h){ //Get heaviest swap
if(l <= lo && hi <= h){
return heaviestswap;
}
//int rmin = mex;
int lmax = -1000000009;
int res = 0;
if(l <= mid){
res = max(res, lft->ghs(l,h));
lmax = lft->glnstx(l,h,1000000009);
}
if(mid < h){
res = max(res, rght->ghs(l,h));
res = max(res, lmax+rght->glnstx(l,h,lmax));
}
return res;
}
int glnstx(int l, int h, int x){ //get largest number smaller than x
if(l <= lo && hi <= h){
if(x == 1000000009) return svals.back();
int l1 = -1;
int h1 = svals.size();
while(h1-l1 > 1){
int m1 = (h1+l1)/2;
if(svals[m1] < x){
l1 = m1;
}else{
h1 = m1;
}
}
if(l1 == -1) return -1000000009;
return svals[l1];
}
//int rmin = mex;
int best = -1000000009;
if(mid < h){
best = max(best, rght->glnstx(l, h, x));
}
if(l <= mid){
best = max(best, lft->glnstx(l, h, x));
}
return best;
}
} *root;
int main(){
int n, q;
scanf("%d %d", &n, &q);
bks.push_back(0);
for(int i = 0; i < n; ++i){
int x;
scanf("%d", &x);
bks.push_back(x);
}
root = new node(1, n);
for(int i = 0; i < q; ++i){
int l, r, w;
scanf("%d %d %d", &l, &r, &w);
if(root->ghs(l,r) > w){
printf("0\n");
}else{
printf("1\n");
}
}
}
Compilation message
sortbooks.cpp: In constructor 'node::node(int, int)':
sortbooks.cpp:31:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
31 | while(lp < lft->svals.size()-1 || rp < rght->svals.size()-1){
| ~~~^~~~~~~~~~~~~~~~~~~~~
sortbooks.cpp:31:50: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
31 | while(lp < lft->svals.size()-1 || rp < rght->svals.size()-1){
| ~~~^~~~~~~~~~~~~~~~~~~~~~
sortbooks.cpp: In function 'int main()':
sortbooks.cpp:100:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
100 | scanf("%d %d", &n, &q);
| ~~~~~^~~~~~~~~~~~~~~~~
sortbooks.cpp:104:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
104 | scanf("%d", &x);
| ~~~~~^~~~~~~~~~
sortbooks.cpp:110:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
110 | scanf("%d %d %d", &l, &r, &w);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
256 KB |
Output is correct |
2 |
Correct |
0 ms |
256 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
2 ms |
384 KB |
Output is correct |
7 |
Correct |
2 ms |
384 KB |
Output is correct |
8 |
Correct |
2 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
256 KB |
Output is correct |
2 |
Correct |
0 ms |
256 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
2 ms |
384 KB |
Output is correct |
7 |
Correct |
2 ms |
384 KB |
Output is correct |
8 |
Correct |
2 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
9 ms |
768 KB |
Output is correct |
12 |
Correct |
14 ms |
1664 KB |
Output is correct |
13 |
Correct |
15 ms |
1792 KB |
Output is correct |
14 |
Correct |
23 ms |
1792 KB |
Output is correct |
15 |
Correct |
22 ms |
1792 KB |
Output is correct |
16 |
Correct |
17 ms |
1792 KB |
Output is correct |
17 |
Correct |
12 ms |
1536 KB |
Output is correct |
18 |
Correct |
16 ms |
1664 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
840 ms |
262148 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
986 ms |
29168 KB |
Output is correct |
2 |
Correct |
893 ms |
29140 KB |
Output is correct |
3 |
Correct |
960 ms |
29168 KB |
Output is correct |
4 |
Correct |
928 ms |
28988 KB |
Output is correct |
5 |
Correct |
910 ms |
29040 KB |
Output is correct |
6 |
Correct |
756 ms |
28932 KB |
Output is correct |
7 |
Correct |
751 ms |
28784 KB |
Output is correct |
8 |
Correct |
654 ms |
28656 KB |
Output is correct |
9 |
Correct |
101 ms |
2040 KB |
Output is correct |
10 |
Correct |
669 ms |
28912 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
256 KB |
Output is correct |
2 |
Correct |
0 ms |
256 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
2 ms |
384 KB |
Output is correct |
7 |
Correct |
2 ms |
384 KB |
Output is correct |
8 |
Correct |
2 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
9 ms |
768 KB |
Output is correct |
12 |
Correct |
14 ms |
1664 KB |
Output is correct |
13 |
Correct |
15 ms |
1792 KB |
Output is correct |
14 |
Correct |
23 ms |
1792 KB |
Output is correct |
15 |
Correct |
22 ms |
1792 KB |
Output is correct |
16 |
Correct |
17 ms |
1792 KB |
Output is correct |
17 |
Correct |
12 ms |
1536 KB |
Output is correct |
18 |
Correct |
16 ms |
1664 KB |
Output is correct |
19 |
Correct |
2469 ms |
61172 KB |
Output is correct |
20 |
Correct |
2426 ms |
61288 KB |
Output is correct |
21 |
Correct |
2060 ms |
60908 KB |
Output is correct |
22 |
Correct |
2065 ms |
60904 KB |
Output is correct |
23 |
Correct |
2118 ms |
61160 KB |
Output is correct |
24 |
Correct |
1908 ms |
60904 KB |
Output is correct |
25 |
Correct |
1869 ms |
60912 KB |
Output is correct |
26 |
Correct |
2155 ms |
61032 KB |
Output is correct |
27 |
Correct |
2125 ms |
61164 KB |
Output is correct |
28 |
Correct |
2193 ms |
61164 KB |
Output is correct |
29 |
Correct |
2230 ms |
61172 KB |
Output is correct |
30 |
Correct |
2272 ms |
61288 KB |
Output is correct |
31 |
Correct |
2310 ms |
61340 KB |
Output is correct |
32 |
Correct |
2277 ms |
61292 KB |
Output is correct |
33 |
Correct |
2282 ms |
61364 KB |
Output is correct |
34 |
Correct |
1774 ms |
60904 KB |
Output is correct |
35 |
Correct |
1771 ms |
60956 KB |
Output is correct |
36 |
Correct |
1778 ms |
60732 KB |
Output is correct |
37 |
Correct |
1781 ms |
60752 KB |
Output is correct |
38 |
Correct |
1784 ms |
60780 KB |
Output is correct |
39 |
Correct |
1795 ms |
59916 KB |
Output is correct |
40 |
Correct |
1093 ms |
43900 KB |
Output is correct |
41 |
Correct |
1572 ms |
59240 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
256 KB |
Output is correct |
2 |
Correct |
0 ms |
256 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
2 ms |
384 KB |
Output is correct |
7 |
Correct |
2 ms |
384 KB |
Output is correct |
8 |
Correct |
2 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
9 ms |
768 KB |
Output is correct |
12 |
Correct |
14 ms |
1664 KB |
Output is correct |
13 |
Correct |
15 ms |
1792 KB |
Output is correct |
14 |
Correct |
23 ms |
1792 KB |
Output is correct |
15 |
Correct |
22 ms |
1792 KB |
Output is correct |
16 |
Correct |
17 ms |
1792 KB |
Output is correct |
17 |
Correct |
12 ms |
1536 KB |
Output is correct |
18 |
Correct |
16 ms |
1664 KB |
Output is correct |
19 |
Runtime error |
840 ms |
262148 KB |
Execution killed with signal 9 |
20 |
Halted |
0 ms |
0 KB |
- |