#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#define fi first
#define se second
#define LL long long
using namespace std;
const int N = 1e6 + 7;
const LL mod = 1e9 + 7;
const int B = sqrt(1e5);
int n,q;
int a[N];
int l[N];
int r[N];
int k[N];
int ord[N];
int nxt[N];
int ans[N];
int t[4 * N];
stack < int > s;
void add( int x , int l , int r , int pos , int xx )
{
if( !( l <= pos && r >= pos ) )return;
t[x] = max( t[x] , xx );
int m = (l + r) / 2;
if( l == r )return;
add(x * 2 , l , m , pos , xx);
add(x * 2 + 1 , m + 1 , r , pos , xx);
}
int get( int x , int l , int r , int tl , int tr )
{
if( l >= tl && r <= tr )return t[x];
if( l > tr || r < tl )return -1;
int m = (l + r) / 2;
return max( get(x * 2 , l , m , tl , tr ) ,
get( x * 2 + 1 , m + 1 , r , tl , tr) );
}
bool cmp( int x , int y ){
return r[x] < r[y];
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
//freopen( "input.txt" , "r" , stdin );
//freopen( "output.txt" , "w" , stdout );
cin >> n >> q;
for( int i = 0; i < N; i++ )nxt[i] = -1;
for( int i = 0; i < 4 * N; i++ )t[i] = -1;
for( int i = 0; i < n; i++ ){
cin >> a[i];
}
for( int i = 0; i < q; i++ ){
cin >> l[i] >> r[i] >> k[i];
l[i]--,r[i]--;
ord[i] = i;
}
int cnt = -1;
sort( ord , ord + q , cmp );
for( int i = 0; i < n; i++ ){
while( !s.empty() && a[s.top()] <= a[i] ){
s.pop();
}
if( !s.empty() ){
nxt[i] = s.top();
}
s.push(i);
}
for( int i = 0; i < q; i++ ){
int y = ord[i];
while( cnt < r[y] ){
cnt++;
if( nxt[cnt] != -1 ){
add( 1 , 0 , n - 1 , nxt[cnt] , a[nxt[cnt]] + a[cnt] );
}
}
ans[y] = ( get( 1 , 0 , n - 1 , l[y] , r[y] ) <= k[y] );
}
for( int i = 0; i < q; i++ )
cout << ans[i] << "\n";
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
19 ms |
19960 KB |
Output is correct |
2 |
Correct |
19 ms |
19960 KB |
Output is correct |
3 |
Correct |
19 ms |
20088 KB |
Output is correct |
4 |
Correct |
19 ms |
20076 KB |
Output is correct |
5 |
Correct |
19 ms |
19952 KB |
Output is correct |
6 |
Correct |
19 ms |
19960 KB |
Output is correct |
7 |
Correct |
20 ms |
19960 KB |
Output is correct |
8 |
Correct |
19 ms |
19960 KB |
Output is correct |
9 |
Correct |
19 ms |
19960 KB |
Output is correct |
10 |
Correct |
19 ms |
19960 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
19 ms |
19960 KB |
Output is correct |
2 |
Correct |
19 ms |
19960 KB |
Output is correct |
3 |
Correct |
19 ms |
20088 KB |
Output is correct |
4 |
Correct |
19 ms |
20076 KB |
Output is correct |
5 |
Correct |
19 ms |
19952 KB |
Output is correct |
6 |
Correct |
19 ms |
19960 KB |
Output is correct |
7 |
Correct |
20 ms |
19960 KB |
Output is correct |
8 |
Correct |
19 ms |
19960 KB |
Output is correct |
9 |
Correct |
19 ms |
19960 KB |
Output is correct |
10 |
Correct |
19 ms |
19960 KB |
Output is correct |
11 |
Correct |
22 ms |
20216 KB |
Output is correct |
12 |
Correct |
22 ms |
20192 KB |
Output is correct |
13 |
Correct |
23 ms |
20088 KB |
Output is correct |
14 |
Correct |
24 ms |
20276 KB |
Output is correct |
15 |
Correct |
24 ms |
20216 KB |
Output is correct |
16 |
Correct |
24 ms |
20240 KB |
Output is correct |
17 |
Correct |
23 ms |
20216 KB |
Output is correct |
18 |
Correct |
23 ms |
20088 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1756 ms |
57000 KB |
Output is correct |
2 |
Correct |
1744 ms |
63660 KB |
Output is correct |
3 |
Correct |
1763 ms |
64448 KB |
Output is correct |
4 |
Correct |
1819 ms |
63792 KB |
Output is correct |
5 |
Correct |
1486 ms |
63932 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
137 ms |
24572 KB |
Output is correct |
2 |
Correct |
133 ms |
24420 KB |
Output is correct |
3 |
Correct |
132 ms |
24440 KB |
Output is correct |
4 |
Correct |
126 ms |
24464 KB |
Output is correct |
5 |
Correct |
168 ms |
24516 KB |
Output is correct |
6 |
Correct |
104 ms |
24436 KB |
Output is correct |
7 |
Correct |
103 ms |
24312 KB |
Output is correct |
8 |
Correct |
111 ms |
24140 KB |
Output is correct |
9 |
Correct |
73 ms |
23424 KB |
Output is correct |
10 |
Correct |
111 ms |
24144 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
19 ms |
19960 KB |
Output is correct |
2 |
Correct |
19 ms |
19960 KB |
Output is correct |
3 |
Correct |
19 ms |
20088 KB |
Output is correct |
4 |
Correct |
19 ms |
20076 KB |
Output is correct |
5 |
Correct |
19 ms |
19952 KB |
Output is correct |
6 |
Correct |
19 ms |
19960 KB |
Output is correct |
7 |
Correct |
20 ms |
19960 KB |
Output is correct |
8 |
Correct |
19 ms |
19960 KB |
Output is correct |
9 |
Correct |
19 ms |
19960 KB |
Output is correct |
10 |
Correct |
19 ms |
19960 KB |
Output is correct |
11 |
Correct |
22 ms |
20216 KB |
Output is correct |
12 |
Correct |
22 ms |
20192 KB |
Output is correct |
13 |
Correct |
23 ms |
20088 KB |
Output is correct |
14 |
Correct |
24 ms |
20276 KB |
Output is correct |
15 |
Correct |
24 ms |
20216 KB |
Output is correct |
16 |
Correct |
24 ms |
20240 KB |
Output is correct |
17 |
Correct |
23 ms |
20216 KB |
Output is correct |
18 |
Correct |
23 ms |
20088 KB |
Output is correct |
19 |
Correct |
307 ms |
31736 KB |
Output is correct |
20 |
Correct |
312 ms |
31628 KB |
Output is correct |
21 |
Correct |
277 ms |
31500 KB |
Output is correct |
22 |
Correct |
275 ms |
31608 KB |
Output is correct |
23 |
Correct |
276 ms |
31552 KB |
Output is correct |
24 |
Correct |
236 ms |
31324 KB |
Output is correct |
25 |
Correct |
236 ms |
31352 KB |
Output is correct |
26 |
Correct |
262 ms |
31772 KB |
Output is correct |
27 |
Correct |
254 ms |
31616 KB |
Output is correct |
28 |
Correct |
264 ms |
31680 KB |
Output is correct |
29 |
Correct |
269 ms |
31608 KB |
Output is correct |
30 |
Correct |
287 ms |
31680 KB |
Output is correct |
31 |
Correct |
272 ms |
31744 KB |
Output is correct |
32 |
Correct |
272 ms |
31612 KB |
Output is correct |
33 |
Correct |
275 ms |
31608 KB |
Output is correct |
34 |
Correct |
224 ms |
31316 KB |
Output is correct |
35 |
Correct |
239 ms |
31308 KB |
Output is correct |
36 |
Correct |
231 ms |
31136 KB |
Output is correct |
37 |
Correct |
218 ms |
31136 KB |
Output is correct |
38 |
Correct |
230 ms |
31348 KB |
Output is correct |
39 |
Correct |
241 ms |
30236 KB |
Output is correct |
40 |
Correct |
203 ms |
29304 KB |
Output is correct |
41 |
Correct |
253 ms |
29832 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
19 ms |
19960 KB |
Output is correct |
2 |
Correct |
19 ms |
19960 KB |
Output is correct |
3 |
Correct |
19 ms |
20088 KB |
Output is correct |
4 |
Correct |
19 ms |
20076 KB |
Output is correct |
5 |
Correct |
19 ms |
19952 KB |
Output is correct |
6 |
Correct |
19 ms |
19960 KB |
Output is correct |
7 |
Correct |
20 ms |
19960 KB |
Output is correct |
8 |
Correct |
19 ms |
19960 KB |
Output is correct |
9 |
Correct |
19 ms |
19960 KB |
Output is correct |
10 |
Correct |
19 ms |
19960 KB |
Output is correct |
11 |
Correct |
22 ms |
20216 KB |
Output is correct |
12 |
Correct |
22 ms |
20192 KB |
Output is correct |
13 |
Correct |
23 ms |
20088 KB |
Output is correct |
14 |
Correct |
24 ms |
20276 KB |
Output is correct |
15 |
Correct |
24 ms |
20216 KB |
Output is correct |
16 |
Correct |
24 ms |
20240 KB |
Output is correct |
17 |
Correct |
23 ms |
20216 KB |
Output is correct |
18 |
Correct |
23 ms |
20088 KB |
Output is correct |
19 |
Correct |
1756 ms |
57000 KB |
Output is correct |
20 |
Correct |
1744 ms |
63660 KB |
Output is correct |
21 |
Correct |
1763 ms |
64448 KB |
Output is correct |
22 |
Correct |
1819 ms |
63792 KB |
Output is correct |
23 |
Correct |
1486 ms |
63932 KB |
Output is correct |
24 |
Correct |
137 ms |
24572 KB |
Output is correct |
25 |
Correct |
133 ms |
24420 KB |
Output is correct |
26 |
Correct |
132 ms |
24440 KB |
Output is correct |
27 |
Correct |
126 ms |
24464 KB |
Output is correct |
28 |
Correct |
168 ms |
24516 KB |
Output is correct |
29 |
Correct |
104 ms |
24436 KB |
Output is correct |
30 |
Correct |
103 ms |
24312 KB |
Output is correct |
31 |
Correct |
111 ms |
24140 KB |
Output is correct |
32 |
Correct |
73 ms |
23424 KB |
Output is correct |
33 |
Correct |
111 ms |
24144 KB |
Output is correct |
34 |
Correct |
307 ms |
31736 KB |
Output is correct |
35 |
Correct |
312 ms |
31628 KB |
Output is correct |
36 |
Correct |
277 ms |
31500 KB |
Output is correct |
37 |
Correct |
275 ms |
31608 KB |
Output is correct |
38 |
Correct |
276 ms |
31552 KB |
Output is correct |
39 |
Correct |
236 ms |
31324 KB |
Output is correct |
40 |
Correct |
236 ms |
31352 KB |
Output is correct |
41 |
Correct |
262 ms |
31772 KB |
Output is correct |
42 |
Correct |
254 ms |
31616 KB |
Output is correct |
43 |
Correct |
264 ms |
31680 KB |
Output is correct |
44 |
Correct |
269 ms |
31608 KB |
Output is correct |
45 |
Correct |
287 ms |
31680 KB |
Output is correct |
46 |
Correct |
272 ms |
31744 KB |
Output is correct |
47 |
Correct |
272 ms |
31612 KB |
Output is correct |
48 |
Correct |
275 ms |
31608 KB |
Output is correct |
49 |
Correct |
224 ms |
31316 KB |
Output is correct |
50 |
Correct |
239 ms |
31308 KB |
Output is correct |
51 |
Correct |
231 ms |
31136 KB |
Output is correct |
52 |
Correct |
218 ms |
31136 KB |
Output is correct |
53 |
Correct |
230 ms |
31348 KB |
Output is correct |
54 |
Correct |
241 ms |
30236 KB |
Output is correct |
55 |
Correct |
203 ms |
29304 KB |
Output is correct |
56 |
Correct |
253 ms |
29832 KB |
Output is correct |
57 |
Correct |
1681 ms |
64188 KB |
Output is correct |
58 |
Correct |
1691 ms |
64172 KB |
Output is correct |
59 |
Correct |
1643 ms |
64124 KB |
Output is correct |
60 |
Correct |
1652 ms |
64056 KB |
Output is correct |
61 |
Correct |
1662 ms |
64052 KB |
Output is correct |
62 |
Correct |
1630 ms |
64168 KB |
Output is correct |
63 |
Correct |
1222 ms |
65952 KB |
Output is correct |
64 |
Correct |
1224 ms |
65812 KB |
Output is correct |
65 |
Correct |
1467 ms |
64104 KB |
Output is correct |
66 |
Correct |
1462 ms |
64212 KB |
Output is correct |
67 |
Correct |
1463 ms |
64104 KB |
Output is correct |
68 |
Correct |
1485 ms |
64092 KB |
Output is correct |
69 |
Correct |
1572 ms |
64176 KB |
Output is correct |
70 |
Correct |
1491 ms |
64280 KB |
Output is correct |
71 |
Correct |
1504 ms |
64160 KB |
Output is correct |
72 |
Correct |
1521 ms |
64096 KB |
Output is correct |
73 |
Correct |
1205 ms |
67636 KB |
Output is correct |
74 |
Correct |
1185 ms |
66300 KB |
Output is correct |
75 |
Correct |
1197 ms |
67464 KB |
Output is correct |
76 |
Correct |
1167 ms |
67448 KB |
Output is correct |
77 |
Correct |
1176 ms |
67552 KB |
Output is correct |
78 |
Correct |
1320 ms |
72736 KB |
Output is correct |
79 |
Correct |
988 ms |
66080 KB |
Output is correct |
80 |
Correct |
1300 ms |
70064 KB |
Output is correct |