#include <iostream>
#include <bits/stdc++.h>
#include <cmath>
#include <algorithm>
#include <vector>
#include <deque>
#include <set>
#include <stack>
#include <string>
#include <map>
#include <queue>
using namespace std;
const long long oo = 1000000000000000000;
long long sum, ans = 0, mx = 0, mn = 1000000000, num, pos;
/*
ViHHiPuh
(( `'-""``""-'` ))
)-__-_.._-__-(
/ --- (o _ o) --- \
\ .-* ( .0. ) *-. /
_'-. ,_ '=' _, .-'_
/ `;#'#'# - #'#'#;` \
\_)) -----'#'----- ((_/
# --------- #
'# ------- ------ #'
/..-'# ------- #'-.\
_\...-\'# -- #'/-.../_
((____)- '#' -(____))
cout << fixed << setprecision(6) << x;
freopen ( "sum.in", "r", stdin )
*/
struct Node {
vector <int> v;
int ans;
public :
Node operator + ( Node a ) {
Node c;
c.ans = max( ans, a.ans );
int l, r;
l = r = 0;
int mx = v.back();
if ( a.v.front() < mx ) {
auto it = lower_bound( a.v.begin(), a.v.end(), mx );
it = --it;
c.ans = max( c.ans, *it + mx );
}
while ( l < v.size() && r < a.v.size() ) {
if ( v[ l ] < a.v[ r ] ) {
c.v.push_back( v[ l ] );
l ++;
}
else {
c.v.push_back( a.v[ r ] );
r ++;
}
}
while ( l < v.size() ) {
c.v.push_back( v[ l ] );
l ++;
}
while ( r < a.v.size() ) {
c.v.push_back( a.v[ r ] );
r ++;
}
return c;
}
} t[ 4000001 ];
struct Node1 {
int ans, mx;
} an;
int n, m, a[ 1000001 ];
void build( int v, int tl, int tr ) {
if ( tl == tr ) {
t[ v ].v.push_back( a[ tl ] );
t[ v ].ans = 0;
return;
}
int mid = ( tl + tr ) / 2;
build( v + v, tl, mid );
build( v + v + 1, mid + 1, tr );
t[ v ] = t[ v + v ] + t[ v + v + 1 ];
}
void gett( int v, int tl, int tr, int l, int r ) {
if ( tl > r || tr < l )
return;
if ( tl >= l && tr <= r ) {
an.ans = max( an.ans, t[ v ].ans );
if ( an.mx > t[ v ].v.front() ) {
auto it = lower_bound( t[ v ].v.begin(), t[ v ].v.end(), an.mx );
it = --it;
an.ans = max( an.ans, an.mx + *it );
}
an.mx = max( an.mx, t[ v ].v.back() );
return;
}
int mid = ( tl + tr ) / 2;
gett( v + v, tl, mid, l, r );
gett( v + v + 1, mid + 1, tr, l, r );
}
main () {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
cin >> n >> m;
for ( int i = 1; i <= n; i ++ ) {
cin >> a[ i ];
}
int l, r, x;
build( 1, 1, n );
while ( m -- ) {
cin >> l >> r >> x;
num = 0;
an.mx = 0;
an.ans = 0;
gett( 1, 1, n, l, r );
cout << ( x >= an.ans ) << "\n";
}
}
/*
9 1
10 6 7 10 1 3 7 3 7
2 3 1
3 1
7 1 9
1 3 8
*/
Compilation message
sortbooks.cpp: In member function 'Node Node::operator+(Node)':
sortbooks.cpp:58:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
58 | while ( l < v.size() && r < a.v.size() ) {
| ~~^~~~~~~~~~
sortbooks.cpp:58:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
58 | while ( l < v.size() && r < a.v.size() ) {
| ~~^~~~~~~~~~~~
sortbooks.cpp:68:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
68 | while ( l < v.size() ) {
| ~~^~~~~~~~~~
sortbooks.cpp:72:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
72 | while ( r < a.v.size() ) {
| ~~^~~~~~~~~~~~
sortbooks.cpp: At global scope:
sortbooks.cpp:116:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
116 | main () {
| ^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
57 ms |
125484 KB |
Output is correct |
2 |
Correct |
55 ms |
125488 KB |
Output is correct |
3 |
Correct |
54 ms |
125560 KB |
Output is correct |
4 |
Correct |
55 ms |
125548 KB |
Output is correct |
5 |
Correct |
56 ms |
125508 KB |
Output is correct |
6 |
Correct |
56 ms |
125668 KB |
Output is correct |
7 |
Correct |
57 ms |
125512 KB |
Output is correct |
8 |
Correct |
57 ms |
125580 KB |
Output is correct |
9 |
Correct |
56 ms |
125528 KB |
Output is correct |
10 |
Correct |
64 ms |
125508 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
57 ms |
125484 KB |
Output is correct |
2 |
Correct |
55 ms |
125488 KB |
Output is correct |
3 |
Correct |
54 ms |
125560 KB |
Output is correct |
4 |
Correct |
55 ms |
125548 KB |
Output is correct |
5 |
Correct |
56 ms |
125508 KB |
Output is correct |
6 |
Correct |
56 ms |
125668 KB |
Output is correct |
7 |
Correct |
57 ms |
125512 KB |
Output is correct |
8 |
Correct |
57 ms |
125580 KB |
Output is correct |
9 |
Correct |
56 ms |
125528 KB |
Output is correct |
10 |
Correct |
64 ms |
125508 KB |
Output is correct |
11 |
Correct |
58 ms |
125720 KB |
Output is correct |
12 |
Correct |
59 ms |
126240 KB |
Output is correct |
13 |
Correct |
65 ms |
126168 KB |
Output is correct |
14 |
Correct |
62 ms |
126196 KB |
Output is correct |
15 |
Correct |
62 ms |
126248 KB |
Output is correct |
16 |
Correct |
61 ms |
126148 KB |
Output is correct |
17 |
Correct |
63 ms |
126000 KB |
Output is correct |
18 |
Correct |
63 ms |
126244 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
487 ms |
262148 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
247 ms |
139440 KB |
Output is correct |
2 |
Correct |
209 ms |
139388 KB |
Output is correct |
3 |
Correct |
185 ms |
139792 KB |
Output is correct |
4 |
Correct |
191 ms |
141252 KB |
Output is correct |
5 |
Correct |
195 ms |
141292 KB |
Output is correct |
6 |
Correct |
156 ms |
141132 KB |
Output is correct |
7 |
Correct |
153 ms |
141080 KB |
Output is correct |
8 |
Correct |
178 ms |
141040 KB |
Output is correct |
9 |
Correct |
89 ms |
127044 KB |
Output is correct |
10 |
Correct |
176 ms |
141020 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
57 ms |
125484 KB |
Output is correct |
2 |
Correct |
55 ms |
125488 KB |
Output is correct |
3 |
Correct |
54 ms |
125560 KB |
Output is correct |
4 |
Correct |
55 ms |
125548 KB |
Output is correct |
5 |
Correct |
56 ms |
125508 KB |
Output is correct |
6 |
Correct |
56 ms |
125668 KB |
Output is correct |
7 |
Correct |
57 ms |
125512 KB |
Output is correct |
8 |
Correct |
57 ms |
125580 KB |
Output is correct |
9 |
Correct |
56 ms |
125528 KB |
Output is correct |
10 |
Correct |
64 ms |
125508 KB |
Output is correct |
11 |
Correct |
58 ms |
125720 KB |
Output is correct |
12 |
Correct |
59 ms |
126240 KB |
Output is correct |
13 |
Correct |
65 ms |
126168 KB |
Output is correct |
14 |
Correct |
62 ms |
126196 KB |
Output is correct |
15 |
Correct |
62 ms |
126248 KB |
Output is correct |
16 |
Correct |
61 ms |
126148 KB |
Output is correct |
17 |
Correct |
63 ms |
126000 KB |
Output is correct |
18 |
Correct |
63 ms |
126244 KB |
Output is correct |
19 |
Correct |
503 ms |
154452 KB |
Output is correct |
20 |
Correct |
503 ms |
154496 KB |
Output is correct |
21 |
Correct |
410 ms |
156276 KB |
Output is correct |
22 |
Correct |
405 ms |
160884 KB |
Output is correct |
23 |
Correct |
429 ms |
160868 KB |
Output is correct |
24 |
Correct |
283 ms |
160824 KB |
Output is correct |
25 |
Correct |
278 ms |
160724 KB |
Output is correct |
26 |
Correct |
360 ms |
160960 KB |
Output is correct |
27 |
Correct |
359 ms |
161116 KB |
Output is correct |
28 |
Correct |
370 ms |
161020 KB |
Output is correct |
29 |
Correct |
416 ms |
161068 KB |
Output is correct |
30 |
Correct |
363 ms |
161100 KB |
Output is correct |
31 |
Correct |
356 ms |
161072 KB |
Output is correct |
32 |
Correct |
380 ms |
161088 KB |
Output is correct |
33 |
Correct |
364 ms |
161124 KB |
Output is correct |
34 |
Correct |
285 ms |
160816 KB |
Output is correct |
35 |
Correct |
279 ms |
160624 KB |
Output is correct |
36 |
Correct |
282 ms |
160532 KB |
Output is correct |
37 |
Correct |
283 ms |
160432 KB |
Output is correct |
38 |
Correct |
280 ms |
160716 KB |
Output is correct |
39 |
Correct |
344 ms |
159548 KB |
Output is correct |
40 |
Correct |
249 ms |
146516 KB |
Output is correct |
41 |
Correct |
342 ms |
159200 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
57 ms |
125484 KB |
Output is correct |
2 |
Correct |
55 ms |
125488 KB |
Output is correct |
3 |
Correct |
54 ms |
125560 KB |
Output is correct |
4 |
Correct |
55 ms |
125548 KB |
Output is correct |
5 |
Correct |
56 ms |
125508 KB |
Output is correct |
6 |
Correct |
56 ms |
125668 KB |
Output is correct |
7 |
Correct |
57 ms |
125512 KB |
Output is correct |
8 |
Correct |
57 ms |
125580 KB |
Output is correct |
9 |
Correct |
56 ms |
125528 KB |
Output is correct |
10 |
Correct |
64 ms |
125508 KB |
Output is correct |
11 |
Correct |
58 ms |
125720 KB |
Output is correct |
12 |
Correct |
59 ms |
126240 KB |
Output is correct |
13 |
Correct |
65 ms |
126168 KB |
Output is correct |
14 |
Correct |
62 ms |
126196 KB |
Output is correct |
15 |
Correct |
62 ms |
126248 KB |
Output is correct |
16 |
Correct |
61 ms |
126148 KB |
Output is correct |
17 |
Correct |
63 ms |
126000 KB |
Output is correct |
18 |
Correct |
63 ms |
126244 KB |
Output is correct |
19 |
Runtime error |
487 ms |
262148 KB |
Execution killed with signal 9 |
20 |
Halted |
0 ms |
0 KB |
- |