#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 , x);
add(x * 2 + 1 , m + 1 , r , pos , x);
}
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 |
Incorrect |
19 ms |
19960 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
19 ms |
19960 KB |
Output is correct |
2 |
Correct |
19 ms |
19960 KB |
Output is correct |
3 |
Incorrect |
19 ms |
19960 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1688 ms |
54476 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
141 ms |
24504 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
19 ms |
19960 KB |
Output is correct |
2 |
Correct |
19 ms |
19960 KB |
Output is correct |
3 |
Incorrect |
19 ms |
19960 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
19 ms |
19960 KB |
Output is correct |
2 |
Correct |
19 ms |
19960 KB |
Output is correct |
3 |
Incorrect |
19 ms |
19960 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |