#include <bits/stdc++.h>
//#pragma GCC optimize("Ofast")
//1.0 * clock() / CLOCKS_PER_SEC
#define fi first
#define se second
#define int long long int
#define dl double long
using namespace std;
const int N = 1e6 + 7;
const int INF = 1e10 + 7;
const int mod = 998244353;
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int ar[N], tmn[4 * N], tmx[4 * N];
void buildmn(int v, int l, int r){
if(l == r){
tmn[v] = ar[l];
}else{
int m = (l + r) / 2;
buildmn(v * 2, l, m);
buildmn(v * 2 + 1, m + 1, r);
tmn[v] = min(tmn[v * 2], tmn[v * 2 + 1]);
}
}
void buildmx(int v, int l, int r){
if(l == r){
tmx[v] = ar[l];
}else{
int m = (l + r) / 2;
buildmx(v * 2, l, m);
buildmx(v * 2 + 1, m + 1, r);
tmx[v] = max(tmx[v * 2], tmx[v * 2 + 1]);
}
}
int resmn(int v, int tl, int tr, int l, int r){
if(l > r)
return INT_MAX;
if(tl == l && tr == r)
return tmn[v];
int tm = (tl + tr) / 2;
return min(resmn(v * 2, tl, tm, l, min(tm, r)), resmn(v * 2 + 1, tm + 1, tr, max(tm + 1, l), r));
}
int resmx(int v, int tl, int tr, int l, int r){
if(l > r)
return 0;
if(tl == l && tr == r)
return tmx[v];
int tm = (tl + tr) / 2;
return max(resmx(v * 2, tl, tm, l, min(tm, r)), resmx(v * 2 + 1, tm + 1, tr, max(tm + 1, l), r));
}
void solve1()
{
int n, q;
cin >> n >> q;
for(int i = 1; i <= n; i++)
cin >> ar[i];
buildmn(1, 1, n);
for(int i = 1; i <= n; i++){
if(!(ar[i] > ar[i + 1] && i != n))
ar[i] = 0;
}
buildmx(1, 1, n);
while(q--){
int l, r, k;
cin >> l >> r >> k;
if(l == r){
cout << 1 << endl;
continue;
}
int mx = resmx(1, 1, n, l, r);
int mn = resmn(1, 1, n, l, r);
if(mn < mx && mx + mn <= k){
cout << 1 << endl;
}else{
cout << 0 << endl;
}
}
}
int32_t main()
{
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0); srand(time(0));
//freopen( "input.txt" , "r" , stdin );
//freopen( "output.txt" , "w" , stdout );
//freopen( "cupboard.in" , "r" , stdin );
//freopen( "cupboard.out" , "w" , stdout );
int cghf = 1;//cin >> cghf;
while( cghf-- ){
solve1();
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Incorrect |
2 ms |
364 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Incorrect |
2 ms |
364 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3083 ms |
44092 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
416 ms |
7404 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Incorrect |
2 ms |
364 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Incorrect |
2 ms |
364 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |