#include <bits/stdc++.h>
#define respagold ios_base::sync_with_stdio(0), cin.tie(0);
#define int long long
#define ll long long
#define int2 __int128_t
#define FOR( i, x, n, d ) for( int i = x; i <= n; i += d )
#define FORR( i, x, n, d ) for( int i = x; i >= n; i -= d )
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x.size())
#define pb push_back
#define ins insert
#define lb lower_bound
#define ub upper_bound
#define pii pair <int, int>
#define mkp make_pair
using namespace std;
const int N = 1e6 + 123;
const int inf = 1e18;
const int mod = 1e9 + 7;
int a[N], b[N], c[N], n, m, q, k, z, w, x, y;
vector <pair <int, pii>> g[N];
mt19937 rng( chrono::steady_clock::now().time_since_epoch().count());
int rand( int l, int r )
{
uniform_int_distribution <int> uid( l, r );
return uid( rng );
}
int binpow( int a, int b )
{
if( !b ) return 1;
if( b & 1 ) return binpow( a, b - 1 ) * a % mod;
int res = binpow( a, b >> 1 ); return res * res % mod;
}
int t[4 * N];
void update( int p, int x, int v = 1, int tl = 1, int tr = n )
{
if( tl == tr )
{
t[v] = x;
return;
}
int tm = tl + tr >> 1;
if( p <= tm ) update( p, x, v + v, tl, tm );
else update( p, x, v + v + 1, tm + 1, tr );
t[v] = max( t[v + v], t[v + v + 1] );
}
int get( int l, int r, int v = 1, int tl = 1, int tr = n )
{
if( tl > r || l > tr ) return 0;
if( l <= tl && tr <= r ) return t[v];
int tm = tl + tr >> 1;
return max( get( l, r, v + v, tl, tm ), get( l, r, v + v + 1, tm + 1, tr ));
}
void solve()
{
cin >> n >> m;
FOR( i, 1, n, 1 ) cin >> a[i];
FOR( i, 1, m, 1 )
{
cin >> x >> y >> w;
g[x].pb({ i, {y, w} });
}
stack <int> st;
FORR( i, n, 1, 1 )
{
while( sz(st) && a[st.top()] >= a[i] ) st.pop();
if( sz(st) ) update( st.top(), a[st.top()] + a[i] );
for( auto j : g[i] ) b[j.F] = get( i, j.S.F ) <= j.S.S;
st.push(i);
}
FOR( i, 1, m, 1 ) cout << b[i] << '\n';
}
signed main()
{
// freopen("connect.in", "r", stdin);
// freopen("connect.out", "w", stdout);
respagold
int test = 1;
if( !test ) cin >> test;
while( test -- )
{
solve();
}
}
// solved by KluydQ
# | 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... |