#include <bits/stdc++.h>
#define all(x) x.begin(), x.end()
#define FOR(i, a, b) for (int i = a, _b = b; i <= _b; ++i)
#define FORD(i, a, b) for (int i = a, _b = b; i >= _b; --i)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int maxn = 1e6 + 3;
int n, q, a[maxn];
struct Qr
{
int l, r, k;
} qrs[maxn];
namespace sub12
{
bool approve()
{
return 1ll * q * n <= int(5e7);
}
void solve()
{
FOR(t, 1, q)
{
int ma = -1e9;
bool c = true;
FOR(i, qrs[t].l, qrs[t].r)
{
if (ma > a[i] && a[i] + ma > qrs[t].k)
{
c = false;
break;
}
ma = max(ma, a[i]);
}
cout << c << '\n';
}
}
}
namespace sub3
{
int pre[maxn];
bool approve()
{
int ma = 0;
FOR(i, 1, n) ma = max(ma, a[i]);
FOR(i, 1, q) if (ma <= qrs[i].k) return false;
return true;
}
void solve()
{
FOR(i, 2, n)
{
pre[i] = pre[i - 1];
if (a[i] < a[i - 1]) ++pre[i];
}
FOR(t, 1, q)
{
cout << (pre[qrs[t].r] - pre[qrs[t].l] == 0) << '\n';
}
}
}
void solve()
{
cin >> n >> q;
FOR(i, 1, n) cin >> a[i];
FOR(i, 1, q) cin >> qrs[i].l >> qrs[i].r >> qrs[i].k;
if (sub3 :: approve()) sub3 :: solve();
else sub12 :: solve();
}
signed main()
{
ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define TASK "TEST"
if (fopen(TASK".INP", "r"))
{
freopen(TASK".INP", "r", stdin);
freopen(TASK".OUT", "w", stdout);
}
solve();
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
sortbooks.cpp: In function 'int main()':
sortbooks.cpp:86:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
86 | freopen(TASK".INP", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
sortbooks.cpp:87:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
87 | freopen(TASK".OUT", "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... |