This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 int 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 {
int mn, mx;
public :
Node operator + ( Node a ) {
Node c;
c.mn = min( mn, a.mn );
c.mx = max( mx, a.mx );
return c;
}
} t[ 4000001 ];
int n, m, a[ 1000001 ];
void build( int v, int tl, int tr ) {
if ( tl == tr ) {
t[ v ].mn = a[ tl ];
t[ v ].mx = a[ tl ];
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 ) {
if ( t[ v ].mn > mx )
num = 1;
mx = max( mx, t[ v ].mx + 0ll );
return;
}
int mid = ( tl + tr ) / 2;
gett( v + v, tl, mid, l, r );
gett( v + v + 1, mid + 1, tr, l, r );
}
int 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 ];
mn = min( mn, a[ i ] + 0ll );
}
int l, r, x;
build( 1, 1, n );
while ( m -- ) {
cin >> l >> r >> x;
if ( x < mn ) {
num = 0;
mx = 0;
gett( 1, 1, n, l, r );
cout << !num << "\n";
continue;
}
mx = a[ l ];
ans = 0;
for ( int i = l + 1; i <= r; i ++ ) {
if ( a[ i ] < mx )
ans = max( ans, mx + a[ i ] );
else
mx = a[ i ];
}
cout << ( ans <= x ) << "\n";
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |