#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <bits/stdc++.h>
using namespace std;
using namespace __gnu_pbds;
#define int long long
#define ff first
#define ss second
#define tobit(n) bitset<(int)30>(n)
typedef unsigned long long ull;
#define all(v) (v).begin(), (v).end()
#pragma GCC optimize("Ofast","inline","-ffast-math")
#define rtt(v) rotate(vec.begin(), vec.begin() + k, vec.end()); //move k elements back
vector<int> dx = {1, -1, 0, 0, 1, 1, -1, -1}, dy = {0, 0, 1, -1, 1, -1, 1, -1};
vector<pair<int, int>> DX = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}};
const vector<pair<int, int>> ANS = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};
const int MOD = 1e9 + 7, N = (int)1e6, inf = numeric_limits<int>::max();
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
void IO(string str_ = ""){
if((int)str_.size()){
freopen((str_ + ".in").c_str(), "r", stdin);
freopen((str_ + ".out").c_str(), "w", stdout);
}
}
void HASH(){
const int k = 31, mod = 1e9+7;
string s = "abacabadaba";
long long h = 0, m = 1;
for(auto c : s){
int x = (int) (c - 'a' + 1);
h = (h + m * x) % mod;
m = (m * k) % mod;
}
}
void rabinKarp(string pattern, string str, int q){
int m = pattern.size(), n = str.size();
int i, j, p = 0, t = 0, h = 1, d = 256;
for(i = 0; i < m - 1; i++) h = (h * d) % q;
for(i = 0; i < m; i++) p = (d * p + pattern[i]) % q, t = (d * t + str[i]) % q;
for(i = 0; i <= n - m; i++){
if(p == t){
for(j = 0; j < m; j++){
if(str[i + j] != pattern[j]) break;
} if(j == m) cout << "Pattern found at index " << i << endl;
} if(i < n - m){
t = (d * (t - str[i] * h) + str[i + m]) % q;
if(t < 0) t = (t + q);
}
}
}
const int LOG = 20;
const int MAXN = 1e6 + 5;
int st[LOG][MAXN];
int log_[MAXN];
void FUNC(vector<int>& A, int size){
for(int i = 0; i < size; i++) st[0][i] = A[i];
log_[1] = 0;
for(int i = 2; i <= size; i++) log_[i] = log_[i/2] + 1;
for(int j = 1; j < LOG; j++){
for(int i = 0; i + (1 << j) <= size; i++) st[j][i] = max(st[j - 1][i], st[j - 1][i + (1 << (j - 1))]);
}
}
int fync(int l, int r){
if(l > r) return 0;
int j = log_[r - l + 1];
return max(st[j][l], st[j][r - (1 << j) + 1]);
}
signed main(){ // clock_t the_time = clock(); double t_;
IO(""); int n, m; cin >> n >> m;
vector<int> v(n), A(n - 1);
vector<tuple<int, int, int>> tp(m);
for(auto &to : v) cin >> to;
for(auto &to : tp) cin >> get<0>(to) >> get<1>(to) >> get<2>(to);
for(int i = 0; i < n - 2; i++){
if(v[i] > v[i + 1]) A[i] = v[i] + v[i + 1];
else A[i] = 0;
} if(n > 1) FUNC(A, n - 1);
for(int i = 0; i < m; i++){
int l = get<0>(tp[i]), r = get<1>(tp[i]), k = get<2>(tp[i]);
if(l == r){ cout << 1 << "\n"; continue; }
int l_ = l - 1, r_ = r - 2;
if(l_ > r_) cout << 1 << "\n";
else cout << (fync(l_, r_) <= k ? 1 : 0) << "\n";
} // t_ = double(clock() - the_time) / CLOCKS_PER_SEC; cout << fixed << setprecision(16)<< t_ << " sec.";
}
const int fastIO = [](){
ios_base::sync_with_stdio(false);
cin.tie(nullptr); cout.tie(nullptr);
return 0;
}();
/*
Открыть терминал: F5
Закрыть терминал: F6
Спрятать/показать терминал: F7
Скомпилировать и запустить: F9
Только запустить: F12
*/
컴파일 시 표준 에러 (stderr) 메시지
sortbooks.cpp: In function 'void IO(std::string)':
sortbooks.cpp:22:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
22 | freopen((str_ + ".in").c_str(), "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
sortbooks.cpp:23:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
23 | freopen((str_ + ".out").c_str(), "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~| # | 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... |