#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 nod {
int maxEffort, maxW;
};
vector <int> v[4 * MAX_N];
nod aint[4 * MAX_N];
nod 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];
v[nod].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( v[nod * 2 + 2], aint[nod * 2 + 1].maxW ) );
i = j = 0;
while ( i < v[nod * 2 + 1].size() && j < v[nod * 2 + 2].size() ) {
if ( v[nod * 2 + 1][i] < v[nod * 2 + 2][j] ) {
v[nod].push_back( v[nod * 2 + 1][i] );
i++;
} else {
v[nod].push_back( v[nod * 2 + 2][j] );
j++;
}
}
while ( i < v[nod * 2 + 1].size() ) {
v[nod].push_back( v[nod * 2 + 1][i] );
i++;
}
while ( j < v[nod * 2 + 2].size() ) {
v[nod].push_back( v[nod * 2 + 2][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.maxEffort = max( max( ans.maxEffort, aint[nod].maxEffort ), ans.maxW + lower( v[nod], 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 );
}
int main() {
int n, m, l, r, k, i;
cin >> n >> m;
for ( i = 0; i < n; i++ )
cin >> w[i];
init( 0, 0, n - 1 );
for ( i = 0; i < m; i++ ) {
cin >> l >> r >> k;
query( 0, 0, n - 1, l - 1, r - 1 );
if ( ans.maxEffort > k )
cout << "0\n";
else
cout << "1\n";
}
return 0;
}
Compilation message
sortbooks.cpp: In function 'void init(int, int, int)':
sortbooks.cpp:52:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
52 | while ( i < v[nod * 2 + 1].size() && j < v[nod * 2 + 2].size() ) {
| ~~^~~~~~~~~~~~~~~~~~~~~~~
sortbooks.cpp:52:44: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
52 | while ( i < v[nod * 2 + 1].size() && j < v[nod * 2 + 2].size() ) {
| ~~^~~~~~~~~~~~~~~~~~~~~~~
sortbooks.cpp:61:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
61 | while ( i < v[nod * 2 + 1].size() ) {
| ~~^~~~~~~~~~~~~~~~~~~~~~~
sortbooks.cpp:65:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
65 | while ( j < v[nod * 2 + 2].size() ) {
| ~~^~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
46 ms |
94200 KB |
Output is correct |
2 |
Correct |
46 ms |
94104 KB |
Output is correct |
3 |
Correct |
50 ms |
94204 KB |
Output is correct |
4 |
Correct |
47 ms |
94112 KB |
Output is correct |
5 |
Correct |
45 ms |
94244 KB |
Output is correct |
6 |
Correct |
48 ms |
94252 KB |
Output is correct |
7 |
Correct |
49 ms |
94236 KB |
Output is correct |
8 |
Correct |
47 ms |
94248 KB |
Output is correct |
9 |
Correct |
49 ms |
94220 KB |
Output is correct |
10 |
Correct |
47 ms |
94192 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
46 ms |
94200 KB |
Output is correct |
2 |
Correct |
46 ms |
94104 KB |
Output is correct |
3 |
Correct |
50 ms |
94204 KB |
Output is correct |
4 |
Correct |
47 ms |
94112 KB |
Output is correct |
5 |
Correct |
45 ms |
94244 KB |
Output is correct |
6 |
Correct |
48 ms |
94252 KB |
Output is correct |
7 |
Correct |
49 ms |
94236 KB |
Output is correct |
8 |
Correct |
47 ms |
94248 KB |
Output is correct |
9 |
Correct |
49 ms |
94220 KB |
Output is correct |
10 |
Correct |
47 ms |
94192 KB |
Output is correct |
11 |
Correct |
54 ms |
94424 KB |
Output is correct |
12 |
Correct |
65 ms |
95020 KB |
Output is correct |
13 |
Correct |
64 ms |
94904 KB |
Output is correct |
14 |
Correct |
65 ms |
95036 KB |
Output is correct |
15 |
Correct |
62 ms |
94936 KB |
Output is correct |
16 |
Correct |
61 ms |
94924 KB |
Output is correct |
17 |
Correct |
65 ms |
94716 KB |
Output is correct |
18 |
Correct |
61 ms |
94932 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3099 ms |
248620 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
574 ms |
110188 KB |
Output is correct |
2 |
Correct |
503 ms |
110020 KB |
Output is correct |
3 |
Correct |
551 ms |
110052 KB |
Output is correct |
4 |
Correct |
552 ms |
110132 KB |
Output is correct |
5 |
Correct |
535 ms |
110156 KB |
Output is correct |
6 |
Correct |
469 ms |
109972 KB |
Output is correct |
7 |
Correct |
444 ms |
110088 KB |
Output is correct |
8 |
Correct |
516 ms |
110048 KB |
Output is correct |
9 |
Correct |
262 ms |
94424 KB |
Output is correct |
10 |
Correct |
454 ms |
110004 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
46 ms |
94200 KB |
Output is correct |
2 |
Correct |
46 ms |
94104 KB |
Output is correct |
3 |
Correct |
50 ms |
94204 KB |
Output is correct |
4 |
Correct |
47 ms |
94112 KB |
Output is correct |
5 |
Correct |
45 ms |
94244 KB |
Output is correct |
6 |
Correct |
48 ms |
94252 KB |
Output is correct |
7 |
Correct |
49 ms |
94236 KB |
Output is correct |
8 |
Correct |
47 ms |
94248 KB |
Output is correct |
9 |
Correct |
49 ms |
94220 KB |
Output is correct |
10 |
Correct |
47 ms |
94192 KB |
Output is correct |
11 |
Correct |
54 ms |
94424 KB |
Output is correct |
12 |
Correct |
65 ms |
95020 KB |
Output is correct |
13 |
Correct |
64 ms |
94904 KB |
Output is correct |
14 |
Correct |
65 ms |
95036 KB |
Output is correct |
15 |
Correct |
62 ms |
94936 KB |
Output is correct |
16 |
Correct |
61 ms |
94924 KB |
Output is correct |
17 |
Correct |
65 ms |
94716 KB |
Output is correct |
18 |
Correct |
61 ms |
94932 KB |
Output is correct |
19 |
Correct |
1301 ms |
126716 KB |
Output is correct |
20 |
Correct |
1218 ms |
126884 KB |
Output is correct |
21 |
Correct |
1187 ms |
126708 KB |
Output is correct |
22 |
Correct |
1111 ms |
126744 KB |
Output is correct |
23 |
Correct |
1112 ms |
126728 KB |
Output is correct |
24 |
Correct |
1124 ms |
126736 KB |
Output is correct |
25 |
Correct |
1002 ms |
126668 KB |
Output is correct |
26 |
Correct |
1215 ms |
126868 KB |
Output is correct |
27 |
Correct |
1235 ms |
126884 KB |
Output is correct |
28 |
Correct |
1316 ms |
126888 KB |
Output is correct |
29 |
Correct |
1188 ms |
126800 KB |
Output is correct |
30 |
Correct |
1179 ms |
126752 KB |
Output is correct |
31 |
Correct |
1226 ms |
126736 KB |
Output is correct |
32 |
Correct |
1215 ms |
126856 KB |
Output is correct |
33 |
Correct |
1198 ms |
126828 KB |
Output is correct |
34 |
Correct |
973 ms |
126728 KB |
Output is correct |
35 |
Correct |
977 ms |
126684 KB |
Output is correct |
36 |
Correct |
974 ms |
126708 KB |
Output is correct |
37 |
Correct |
997 ms |
126684 KB |
Output is correct |
38 |
Correct |
1042 ms |
126740 KB |
Output is correct |
39 |
Correct |
1035 ms |
126728 KB |
Output is correct |
40 |
Correct |
806 ms |
112856 KB |
Output is correct |
41 |
Correct |
971 ms |
126744 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
46 ms |
94200 KB |
Output is correct |
2 |
Correct |
46 ms |
94104 KB |
Output is correct |
3 |
Correct |
50 ms |
94204 KB |
Output is correct |
4 |
Correct |
47 ms |
94112 KB |
Output is correct |
5 |
Correct |
45 ms |
94244 KB |
Output is correct |
6 |
Correct |
48 ms |
94252 KB |
Output is correct |
7 |
Correct |
49 ms |
94236 KB |
Output is correct |
8 |
Correct |
47 ms |
94248 KB |
Output is correct |
9 |
Correct |
49 ms |
94220 KB |
Output is correct |
10 |
Correct |
47 ms |
94192 KB |
Output is correct |
11 |
Correct |
54 ms |
94424 KB |
Output is correct |
12 |
Correct |
65 ms |
95020 KB |
Output is correct |
13 |
Correct |
64 ms |
94904 KB |
Output is correct |
14 |
Correct |
65 ms |
95036 KB |
Output is correct |
15 |
Correct |
62 ms |
94936 KB |
Output is correct |
16 |
Correct |
61 ms |
94924 KB |
Output is correct |
17 |
Correct |
65 ms |
94716 KB |
Output is correct |
18 |
Correct |
61 ms |
94932 KB |
Output is correct |
19 |
Execution timed out |
3099 ms |
248620 KB |
Time limit exceeded |
20 |
Halted |
0 ms |
0 KB |
- |