#include <bits/stdc++.h>
#define MAX_N 1000000
using namespace std;
int w[MAX_N];
int lower( vector <int> &v, int x ) {
int l, r, mid;
l = 0;
r = v.size();
while ( r - l > 1 ) {
mid = (l + r) / 2;
if ( v[mid] < x )
l = mid;
else
r = mid;
}
return v[l] < x ? v[l] : -x;
}
struct AINT {
struct nod {
int maxEffort, maxW;
vector <int> v;
};
struct answer {
int maxEfort, maxW;
};
nod aint[4 * MAX_N];
answer ans;
void init( int nod, int l, int r ) {
int mid, i, j;
if ( l == r ) {
aint[nod].maxEffort = 0;
aint[nod].maxW = w[l];
aint[nod].v.push_back( w[l] );
return;
}
mid = (l + r) / 2;
init( nod * 2 + 1, l, mid );
init( nod * 2 + 2, mid + 1, r );
aint[nod].maxW = max( aint[nod * 2 + 1].maxW, aint[nod * 2 + 2].maxW );
aint[nod].maxEffort = max( max( aint[nod * 2 + 1].maxEffort, aint[nod * 2 + 2].maxEffort ), aint[nod * 2 + 1].maxW + lower( aint[nod * 2 + 2].v, aint[nod * 2 + 1].maxW ) );
i = j = 0;
while ( i < aint[nod * 2 + 1].v.size() && j < aint[nod * 2 + 2].v.size() ) {
if ( aint[nod * 2 + 1].v[i] < aint[nod * 2 + 2].v[j] ) {
aint[nod].v.push_back( aint[nod * 2 + 1].v[i] );
i++;
} else {
aint[nod].v.push_back( aint[nod * 2 + 2].v[j] );
j++;
}
}
while ( i < aint[nod * 2 + 1].v.size() ) {
aint[nod].v.push_back( aint[nod * 2 + 1].v[i] );
i++;
}
while ( j < aint[nod * 2 + 2].v.size() ) {
aint[nod].v.push_back( aint[nod * 2 + 2].v[j] );
j++;
}
}
void query( int nod, int l, int r, int lq, int rq ) {
int mid;
if ( nod == 0 )
ans = { 0, 0 };
if ( l > rq || r < lq )
return;
if ( lq <= l && r <= rq ) {
ans.maxEfort = max( max( ans.maxEfort, aint[nod].maxEffort ), ans.maxW + lower( aint[nod].v, ans.maxW ) );
ans.maxW = max( ans.maxW, aint[nod].maxW );
return;
}
mid = (l + r) / 2;
query( nod * 2 + 1, l, mid, lq, rq );
query( nod * 2 + 2, mid + 1, r, lq, rq );
}
};
AINT shelf;
signed main() {
int n, m, l, r, k, i;
cin >> n >> m;
for ( i = 0; i < n; i++ )
cin >> w[i];
shelf.init( 0, 0, n - 1 );
for ( i = 0; i < m; i++ ) {
cin >> l >> r >> k;
shelf.query( 0, 0, n - 1, l - 1, r - 1 );
if ( shelf.ans.maxEfort > k )
cout << "0\n";
else
cout << "1\n";
}
return 0;
}
Compilation message
sortbooks.cpp: In member function 'void AINT::init(int, int, int)':
sortbooks.cpp:58:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
58 | while ( i < aint[nod * 2 + 1].v.size() && j < aint[nod * 2 + 2].v.size() ) {
| ~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
sortbooks.cpp:58:53: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
58 | while ( i < aint[nod * 2 + 1].v.size() && j < aint[nod * 2 + 2].v.size() ) {
| ~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
sortbooks.cpp:67:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
67 | while ( i < aint[nod * 2 + 1].v.size() ) {
| ~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
sortbooks.cpp:71:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
71 | while ( j < aint[nod * 2 + 2].v.size() ) {
| ~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
55 ms |
125512 KB |
Output is correct |
2 |
Correct |
66 ms |
125436 KB |
Output is correct |
3 |
Correct |
63 ms |
125492 KB |
Output is correct |
4 |
Correct |
58 ms |
125460 KB |
Output is correct |
5 |
Correct |
68 ms |
125492 KB |
Output is correct |
6 |
Correct |
73 ms |
125536 KB |
Output is correct |
7 |
Correct |
64 ms |
125536 KB |
Output is correct |
8 |
Correct |
57 ms |
125532 KB |
Output is correct |
9 |
Correct |
55 ms |
125540 KB |
Output is correct |
10 |
Correct |
63 ms |
125564 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
55 ms |
125512 KB |
Output is correct |
2 |
Correct |
66 ms |
125436 KB |
Output is correct |
3 |
Correct |
63 ms |
125492 KB |
Output is correct |
4 |
Correct |
58 ms |
125460 KB |
Output is correct |
5 |
Correct |
68 ms |
125492 KB |
Output is correct |
6 |
Correct |
73 ms |
125536 KB |
Output is correct |
7 |
Correct |
64 ms |
125536 KB |
Output is correct |
8 |
Correct |
57 ms |
125532 KB |
Output is correct |
9 |
Correct |
55 ms |
125540 KB |
Output is correct |
10 |
Correct |
63 ms |
125564 KB |
Output is correct |
11 |
Correct |
80 ms |
125688 KB |
Output is correct |
12 |
Correct |
70 ms |
126076 KB |
Output is correct |
13 |
Correct |
74 ms |
126204 KB |
Output is correct |
14 |
Correct |
75 ms |
126204 KB |
Output is correct |
15 |
Correct |
79 ms |
126156 KB |
Output is correct |
16 |
Correct |
74 ms |
126200 KB |
Output is correct |
17 |
Correct |
73 ms |
125860 KB |
Output is correct |
18 |
Correct |
76 ms |
126112 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
825 ms |
262144 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
536 ms |
139476 KB |
Output is correct |
2 |
Correct |
571 ms |
139340 KB |
Output is correct |
3 |
Correct |
501 ms |
139304 KB |
Output is correct |
4 |
Correct |
570 ms |
139436 KB |
Output is correct |
5 |
Correct |
514 ms |
139272 KB |
Output is correct |
6 |
Correct |
483 ms |
139340 KB |
Output is correct |
7 |
Correct |
468 ms |
139336 KB |
Output is correct |
8 |
Correct |
464 ms |
139316 KB |
Output is correct |
9 |
Correct |
273 ms |
125828 KB |
Output is correct |
10 |
Correct |
443 ms |
139220 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
55 ms |
125512 KB |
Output is correct |
2 |
Correct |
66 ms |
125436 KB |
Output is correct |
3 |
Correct |
63 ms |
125492 KB |
Output is correct |
4 |
Correct |
58 ms |
125460 KB |
Output is correct |
5 |
Correct |
68 ms |
125492 KB |
Output is correct |
6 |
Correct |
73 ms |
125536 KB |
Output is correct |
7 |
Correct |
64 ms |
125536 KB |
Output is correct |
8 |
Correct |
57 ms |
125532 KB |
Output is correct |
9 |
Correct |
55 ms |
125540 KB |
Output is correct |
10 |
Correct |
63 ms |
125564 KB |
Output is correct |
11 |
Correct |
80 ms |
125688 KB |
Output is correct |
12 |
Correct |
70 ms |
126076 KB |
Output is correct |
13 |
Correct |
74 ms |
126204 KB |
Output is correct |
14 |
Correct |
75 ms |
126204 KB |
Output is correct |
15 |
Correct |
79 ms |
126156 KB |
Output is correct |
16 |
Correct |
74 ms |
126200 KB |
Output is correct |
17 |
Correct |
73 ms |
125860 KB |
Output is correct |
18 |
Correct |
76 ms |
126112 KB |
Output is correct |
19 |
Correct |
1198 ms |
153988 KB |
Output is correct |
20 |
Correct |
1291 ms |
153872 KB |
Output is correct |
21 |
Correct |
1206 ms |
153916 KB |
Output is correct |
22 |
Correct |
1072 ms |
153848 KB |
Output is correct |
23 |
Correct |
1101 ms |
154068 KB |
Output is correct |
24 |
Correct |
1050 ms |
153872 KB |
Output is correct |
25 |
Correct |
1041 ms |
153900 KB |
Output is correct |
26 |
Correct |
1135 ms |
153992 KB |
Output is correct |
27 |
Correct |
1173 ms |
153928 KB |
Output is correct |
28 |
Correct |
1179 ms |
153876 KB |
Output is correct |
29 |
Correct |
1223 ms |
153916 KB |
Output is correct |
30 |
Correct |
1190 ms |
154008 KB |
Output is correct |
31 |
Correct |
1417 ms |
153904 KB |
Output is correct |
32 |
Correct |
1520 ms |
153928 KB |
Output is correct |
33 |
Correct |
1344 ms |
153896 KB |
Output is correct |
34 |
Correct |
1036 ms |
153912 KB |
Output is correct |
35 |
Correct |
1041 ms |
153936 KB |
Output is correct |
36 |
Correct |
1036 ms |
153976 KB |
Output is correct |
37 |
Correct |
1068 ms |
153880 KB |
Output is correct |
38 |
Correct |
1137 ms |
153880 KB |
Output is correct |
39 |
Correct |
1281 ms |
153908 KB |
Output is correct |
40 |
Correct |
971 ms |
142112 KB |
Output is correct |
41 |
Correct |
1182 ms |
153864 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
55 ms |
125512 KB |
Output is correct |
2 |
Correct |
66 ms |
125436 KB |
Output is correct |
3 |
Correct |
63 ms |
125492 KB |
Output is correct |
4 |
Correct |
58 ms |
125460 KB |
Output is correct |
5 |
Correct |
68 ms |
125492 KB |
Output is correct |
6 |
Correct |
73 ms |
125536 KB |
Output is correct |
7 |
Correct |
64 ms |
125536 KB |
Output is correct |
8 |
Correct |
57 ms |
125532 KB |
Output is correct |
9 |
Correct |
55 ms |
125540 KB |
Output is correct |
10 |
Correct |
63 ms |
125564 KB |
Output is correct |
11 |
Correct |
80 ms |
125688 KB |
Output is correct |
12 |
Correct |
70 ms |
126076 KB |
Output is correct |
13 |
Correct |
74 ms |
126204 KB |
Output is correct |
14 |
Correct |
75 ms |
126204 KB |
Output is correct |
15 |
Correct |
79 ms |
126156 KB |
Output is correct |
16 |
Correct |
74 ms |
126200 KB |
Output is correct |
17 |
Correct |
73 ms |
125860 KB |
Output is correct |
18 |
Correct |
76 ms |
126112 KB |
Output is correct |
19 |
Runtime error |
825 ms |
262144 KB |
Execution killed with signal 9 |
20 |
Halted |
0 ms |
0 KB |
- |