#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
typedef double db;
typedef vector<long long> vl;
typedef pair<long long, long long > pl;
const int N = 1e6 + 1;
#define po pop_back
#define pb push_back
#define mk make_pair
#define lw lower_bound
#define up upper_bound
#define ff first
#define ss second
#define boost ios_base::sync_with_stdio(); cin.tie(0); cout.tie(0);
#define MOD 1000000007
#define MAX 1e18
#define MIN -1e18
#define per(i,a,b) for(ll i=b;i>=a;i--)
#define con continue
#define freopen freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
#define PI 3.14159265358979323846264338327950288419716939937510582097494459230781640628
// typedef tree<ll , null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
// template< typename T>
// using indexed_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
ll n, m, ans, mid, mn, mx, cnt, sum, h1, h2, arr[3234567],arr1[1234567], sz, k, i, j, h, a, w, x, y, z,par[1234567];
bool used[1234567];
//ll dx[4]={-1,1,0,0},dy[4]={0,0,-1,1},c1[123][123];
//vector<ll> edge[1234567];
//ll jump[22][223456];
//ll lvl[1234567];
//ll bit[1234567];
//ll timer;
//ll st[1234567],endd[1234567];
ll trmax[1234567],trmin[1234567];
//ll dp[5005][5005];
ll power(ll base, ll val, ll mod) {
ll res = 1;
while (val) {
if (val % 2 == 1) {
res = res * base;
}
base = base * base;
base %= mod;
res %= mod;
val /= 2;
}
return res;
}
bool comp(pl x,pl y){
if(x.ff>y.ff)return true;
return false;
}
ll find(ll x){
if(x==par[x])return x;
else return par[x]=find(par[x]);
}
void build(ll node, ll l, ll r){
//cout<<node<<" "<<l<<" "<<r<<'\n';
if(l==r){
trmax[node]=l;
trmin[node]=r;
//cout<<node<<" "<<l<<" "<<r<<" "<<trmax[node]<<'\n';
return;
}
ll mid=(l+r)/2;
build(node*2,l,mid);
build(node*2+1,mid+1,r);
if(arr[trmax[node*2]] >= arr[trmax[node*2+1]]){
trmax[node] = trmax[node*2];
}
else trmax[node]=trmax[node*2+1];
if(arr[trmin[node*2]] >= arr[trmin[node*2+1]]){
trmin[node] = trmin[node*2+1];
}
else trmin[node]=trmin[node*2];
//cout<<node<<" "<<l<<" "<<r<<" "<<trmax[node]<<'\n';
}
ll querymax(ll node,ll l, ll r,ll L,ll R){
//cout<<node<<" "<<l<<" "<<r<<" "<<L<<" "<<R<<" "<<trmax[node]<<'\n';
if(l > R || r < L)return 0;
if(l >= L && r <= R){
return trmax[node];
}
ll mid=(l+r)/2;
x=querymax(node*2,l,mid,L,R);
y=querymax(node*2+1,mid+1,r,L,R);
if(arr[x] >= arr[y]){
return x;
}
else return y;
}
ll querymin(ll node,ll l, ll r,ll L,ll R){
if(l > R || r < L)return n+1;
if(l >= L && r <= R){
return trmin[node];
}
ll mid=(l+r)/2;
x=querymin(node*2,l,mid,L,R);
y=querymin(node*2+1,mid+1,r,L,R);
if(arr[x] >= arr[y]){
return y;
}
else return x;
}
class A {
public:
static void funcA() {
cin>>n;
ll q;
cin>>q;
for(int i=1;i<=n;i++){
cin>>arr[i];
}
arr[n+1]=MAX;
arr[0]=MIN;
build(1,1,n);
//query burt l r zavsrin max min iig olno
while(q--){
ll l,r,x;
cin>>l>>r>>x;
ll xx = querymax(1,1,n,l,r);
ll yy = querymin(1,1,n,l,r);
ll xxx = querymax(1,1,n,xx+1,r);
ll yyy = querymax(1,1,n,l,yy-1);
//cout<<xx<<" "<<xxx<<" "<<yy<<" "<<yyy<<'\n';
if(arr[xxx]-arr[xx] > x || arr[yyy]-arr[yy] > x)puts("0");
else puts("1");
}
}
}lol;
void solve() {
A::funcA();
}
int main() {
ll T = 1;
//cin>>T;
boost;
while (T--) {
solve();
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3034 ms |
38264 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
297 ms |
6660 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |