#include <bits/stdc++.h>
#define fi first
#define se second
#define For(i, a, b) for (int i = (a); i <= (b); ++i)
#define ForD(i, a, b) for (int i = (a); i >= (b); --i)
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repD(i, n) for (int i = (n) - 1; i >= 0; --i)
#define coutE(x) {cout << x << '\n'; return;}
#define pb push_back
#define pf push_front
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
#define bs binary_search
#define ub upper_bound
#define lb lower_bound
#define endl '\n'
#define db long double
#define ll long long
#define ii pair<int, int>
#define vi vector<int>
#define vii vector<ii>
using namespace std;
void file(string s){
if (s.empty()) return;
freopen((s + ".inp").c_str(), "r", stdin);
freopen((s + ".out").c_str(), "w", stdout);
}
template <class X, class Y>
bool minimize(X &x, Y y){
if (x > y) return x = y, 1;
return 0;
}
template <class X, class Y>
bool maximize(X &x, Y y){
if (x < y) return x = y, 1;
return 0;
}
const int N = 1e6 + 5;
int n, q, a[N];
namespace sub1{
void solve(){
while (q--){
int l, r, k; cin >> l >> r >> k;
set<int> st;
bool res = 1;
For(i, l, r){
auto it = st.end();
if (it != st.begin() && *(prev(it)) > a[i] && *(prev(it)) + a[i] > k){
res = 0;
break;
}
st.insert(a[i]);
}
cout << res << '\n';
}
}
}
namespace sub2{
int pre[N];
void solve(){
For(i, 2, n) pre[i] = pre[i - 1] + (a[i] >= a[i - 1]);
while (q--){
int l, r, k; cin >> l >> r >> k;
bool res = (l == r) || (pre[r] - pre[l] == r - l);
cout << res << '\n';
}
}
}
signed main(){
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
cin >> n >> q;
For(i, 1, n) cin >> a[i];
if (max(n, q) <= 5000) return sub1::solve(), 0;
sub2::solve();
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
sortbooks.cpp: In function 'void file(std::string)':
sortbooks.cpp:34:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
34 | freopen((s + ".inp").c_str(), "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
sortbooks.cpp:35:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
35 | freopen((s + ".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... |