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 sum, ans = 0, mx = 0, mn = 1000000000, num, pos;
/*
ViHHiPuh
(( `'-""``""-'` ))
)-__-_.._-__-(
/ --- (o _ o) --- \
\ .-* ( .0. ) *-. /
_'-. ,_ '=' _, .-'_
/ `;#'#'# - #'#'#;` \
\_)) -----'#'----- ((_/
# --------- #
'# ------- ------ #'
/..-'# ------- #'-.\
_\...-\'# -- #'/-.../_
((____)- '#' -(____))
cout << fixed << setprecision(6) << x;
freopen ( "sum.in", "r", stdin )
*/
stack <int> st;
int lg = 20;
int t[ 4000001 ], mp[ 1000001 ], an[ 1000001 ];
vector <pair<int, int> > v;
void upd( int v, int tl, int tr, int pos, int x ) {
if ( tl > pos || tr < pos )
return;
if ( tl == tr ) {
t[ v ] = max( x, t[ v ] );
return;
}
int mid = ( tl + tr ) / 2;
upd( v + v, tl, mid, pos, x );
upd( v + v + 1, mid + 1, tr, pos, x );
t[ v ] = max( 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 ) {
// cout << tl << " " << tr << " " << t[ v ] << "\n";
num = max( num, t[ v ] + 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);
int n, m;
cin >> n >> m;
int a[ n + 1 ];
for ( int i = 1; i <= n; i ++ ) {
cin >> a[ i ];
}
int l[ m + 1 ], r[ m + 1 ], x[ m + 1 ];
for ( int i = 1; i <= m; i++ ) {
cin >> l[ i ] >> r[ i ] >> x[ i ];
v.push_back( { r[ i ], i } );
}
sort( v.begin(), v.end() );
reverse( v.begin(), v.end() );
for ( int i = 1; i <= n; i ++ ) {
while ( st.size() && a[ st.top() ] <= a[ i ] )
st.pop();
if ( !st.size() ) {
mp[ i ] = 0;
}
else {
mp[ i ] = st.top();
}
st.push( i );
sum = 0;
if ( mp[ i ] ) {
sum = a[ i ] + a[ mp[ i ] ];
upd( 1, 1, n, mp[ i ], sum );
}
num = 0;
while ( v.size() && v.back().first == i ) {
num = 0;
gett( 1, 1, n, l[ v.back().second ], r[ v.back().second ] );
an[ v.back().second ] = ( x[ v.back().second ] >= num );
v.pop_back();
}
}
for ( int i = 1; i <= m; i ++ )
cout << an[ i ] << "\n";
}
/*
2 1
5 1
2 2 2
*/
# | 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... |