#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define sz(x) x.size()
#define nl '\n'
#define F first
#define S second
const int N = 1e6 + 1;
const int inf = 1e12;
int t[4 * N][2], a[N], n, q;
void upd( int v, int tl, int tr, int pos, int x )
{
if( tl == tr )
{
t[v][0] = x;
t[v][1] = x;
return;
}
int m = (tl + tr) / 2;
if( pos <= m )
upd(v + v, tl, m, pos, x);
else
upd(v + v + 1, m + 1, tr, pos, x);
t[v][0] = min(t[v + v][0], t[v + v + 1][0]);
t[v][1] = max(t[v + v][1], t[v + v + 1][1]);
}
int getmn( int v, int tl, int tr, int l, int r )
{
if( tl > r || l > tr )
return inf;
if( l <= tl && tr <= r )
return t[v][0];
int m = (tl + tr) / 2;
return min(getmn(v + v, tl, m, l, r), getmn(v + v + 1, m + 1, tr, l, r));
}
int getmx( int v, int tl, int tr, int l, int r )
{
if( tl > r || l > tr )
return 0;
if( l <= tl && tr <= r )
return t[v][1];
int m = (tl + tr) / 2;
return max(getmx(v + v, tl, m, l, r), getmx(v + v + 1, m + 1, tr, l, r));
}
signed main()
{
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
cin >>n >>q;
for( int i = 1; i <= n; ++i )
{
cin >>a[i];
upd(1, 1, n, i, a[i]);
}
while( q-- )
{
int l, r, k;
cin >>l >>r >>k;
int mn = getmn(1, 1, n, l, r);
int mx = getmx(1, 1, n, l, r);
cout <<(mx - mn <= k ? 1 : 0) <<nl;
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2392 KB |
Output is correct |
3 |
Incorrect |
1 ms |
2392 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2392 KB |
Output is correct |
3 |
Incorrect |
1 ms |
2392 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1172 ms |
75516 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
85 ms |
10936 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2392 KB |
Output is correct |
3 |
Incorrect |
1 ms |
2392 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2392 KB |
Output is correct |
3 |
Incorrect |
1 ms |
2392 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |