#include <bits/stdc++.h>
#define MAX_N 1000000
#define int long long
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(long long int, long long int, long long int)':
sortbooks.cpp:59:19: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
59 | while ( i < aint[nod * 2 + 1].v.size() && j < aint[nod * 2 + 2].v.size() ) {
| ~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
sortbooks.cpp:59:53: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
59 | while ( i < aint[nod * 2 + 1].v.size() && j < aint[nod * 2 + 2].v.size() ) {
| ~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
sortbooks.cpp:68:19: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
68 | while ( i < aint[nod * 2 + 1].v.size() ) {
| ~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
sortbooks.cpp:72:19: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
72 | while ( j < aint[nod * 2 + 2].v.size() ) {
| ~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
70 ms |
156812 KB |
Output is correct |
2 |
Correct |
71 ms |
156832 KB |
Output is correct |
3 |
Correct |
70 ms |
156748 KB |
Output is correct |
4 |
Correct |
73 ms |
156812 KB |
Output is correct |
5 |
Correct |
82 ms |
156844 KB |
Output is correct |
6 |
Correct |
76 ms |
156876 KB |
Output is correct |
7 |
Correct |
89 ms |
156868 KB |
Output is correct |
8 |
Correct |
75 ms |
156876 KB |
Output is correct |
9 |
Correct |
77 ms |
156780 KB |
Output is correct |
10 |
Correct |
87 ms |
156856 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
70 ms |
156812 KB |
Output is correct |
2 |
Correct |
71 ms |
156832 KB |
Output is correct |
3 |
Correct |
70 ms |
156748 KB |
Output is correct |
4 |
Correct |
73 ms |
156812 KB |
Output is correct |
5 |
Correct |
82 ms |
156844 KB |
Output is correct |
6 |
Correct |
76 ms |
156876 KB |
Output is correct |
7 |
Correct |
89 ms |
156868 KB |
Output is correct |
8 |
Correct |
75 ms |
156876 KB |
Output is correct |
9 |
Correct |
77 ms |
156780 KB |
Output is correct |
10 |
Correct |
87 ms |
156856 KB |
Output is correct |
11 |
Correct |
93 ms |
157128 KB |
Output is correct |
12 |
Correct |
86 ms |
157768 KB |
Output is correct |
13 |
Correct |
88 ms |
157772 KB |
Output is correct |
14 |
Correct |
91 ms |
157876 KB |
Output is correct |
15 |
Correct |
112 ms |
157824 KB |
Output is correct |
16 |
Correct |
91 ms |
157900 KB |
Output is correct |
17 |
Correct |
94 ms |
157492 KB |
Output is correct |
18 |
Correct |
95 ms |
157808 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
716 ms |
262144 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
695 ms |
178780 KB |
Output is correct |
2 |
Correct |
647 ms |
178712 KB |
Output is correct |
3 |
Correct |
617 ms |
178808 KB |
Output is correct |
4 |
Correct |
630 ms |
178800 KB |
Output is correct |
5 |
Correct |
704 ms |
178764 KB |
Output is correct |
6 |
Correct |
511 ms |
178756 KB |
Output is correct |
7 |
Correct |
556 ms |
178772 KB |
Output is correct |
8 |
Correct |
594 ms |
178772 KB |
Output is correct |
9 |
Correct |
317 ms |
157076 KB |
Output is correct |
10 |
Correct |
593 ms |
178792 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
70 ms |
156812 KB |
Output is correct |
2 |
Correct |
71 ms |
156832 KB |
Output is correct |
3 |
Correct |
70 ms |
156748 KB |
Output is correct |
4 |
Correct |
73 ms |
156812 KB |
Output is correct |
5 |
Correct |
82 ms |
156844 KB |
Output is correct |
6 |
Correct |
76 ms |
156876 KB |
Output is correct |
7 |
Correct |
89 ms |
156868 KB |
Output is correct |
8 |
Correct |
75 ms |
156876 KB |
Output is correct |
9 |
Correct |
77 ms |
156780 KB |
Output is correct |
10 |
Correct |
87 ms |
156856 KB |
Output is correct |
11 |
Correct |
93 ms |
157128 KB |
Output is correct |
12 |
Correct |
86 ms |
157768 KB |
Output is correct |
13 |
Correct |
88 ms |
157772 KB |
Output is correct |
14 |
Correct |
91 ms |
157876 KB |
Output is correct |
15 |
Correct |
112 ms |
157824 KB |
Output is correct |
16 |
Correct |
91 ms |
157900 KB |
Output is correct |
17 |
Correct |
94 ms |
157492 KB |
Output is correct |
18 |
Correct |
95 ms |
157808 KB |
Output is correct |
19 |
Correct |
1415 ms |
202376 KB |
Output is correct |
20 |
Correct |
1564 ms |
202256 KB |
Output is correct |
21 |
Correct |
1234 ms |
202288 KB |
Output is correct |
22 |
Correct |
1338 ms |
202348 KB |
Output is correct |
23 |
Correct |
1308 ms |
202340 KB |
Output is correct |
24 |
Correct |
1388 ms |
202368 KB |
Output is correct |
25 |
Correct |
1130 ms |
202284 KB |
Output is correct |
26 |
Correct |
1325 ms |
202436 KB |
Output is correct |
27 |
Correct |
1188 ms |
202288 KB |
Output is correct |
28 |
Correct |
1188 ms |
202344 KB |
Output is correct |
29 |
Correct |
1202 ms |
202292 KB |
Output is correct |
30 |
Correct |
1328 ms |
202376 KB |
Output is correct |
31 |
Correct |
1344 ms |
202408 KB |
Output is correct |
32 |
Correct |
1270 ms |
202428 KB |
Output is correct |
33 |
Correct |
1427 ms |
202448 KB |
Output is correct |
34 |
Correct |
1061 ms |
202388 KB |
Output is correct |
35 |
Correct |
1053 ms |
202368 KB |
Output is correct |
36 |
Correct |
1076 ms |
202460 KB |
Output is correct |
37 |
Correct |
996 ms |
202492 KB |
Output is correct |
38 |
Correct |
1037 ms |
202412 KB |
Output is correct |
39 |
Correct |
1086 ms |
202268 KB |
Output is correct |
40 |
Correct |
884 ms |
182492 KB |
Output is correct |
41 |
Correct |
1137 ms |
202352 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
70 ms |
156812 KB |
Output is correct |
2 |
Correct |
71 ms |
156832 KB |
Output is correct |
3 |
Correct |
70 ms |
156748 KB |
Output is correct |
4 |
Correct |
73 ms |
156812 KB |
Output is correct |
5 |
Correct |
82 ms |
156844 KB |
Output is correct |
6 |
Correct |
76 ms |
156876 KB |
Output is correct |
7 |
Correct |
89 ms |
156868 KB |
Output is correct |
8 |
Correct |
75 ms |
156876 KB |
Output is correct |
9 |
Correct |
77 ms |
156780 KB |
Output is correct |
10 |
Correct |
87 ms |
156856 KB |
Output is correct |
11 |
Correct |
93 ms |
157128 KB |
Output is correct |
12 |
Correct |
86 ms |
157768 KB |
Output is correct |
13 |
Correct |
88 ms |
157772 KB |
Output is correct |
14 |
Correct |
91 ms |
157876 KB |
Output is correct |
15 |
Correct |
112 ms |
157824 KB |
Output is correct |
16 |
Correct |
91 ms |
157900 KB |
Output is correct |
17 |
Correct |
94 ms |
157492 KB |
Output is correct |
18 |
Correct |
95 ms |
157808 KB |
Output is correct |
19 |
Runtime error |
716 ms |
262144 KB |
Execution killed with signal 9 |
20 |
Halted |
0 ms |
0 KB |
- |