This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define Task ""
struct __Init__ {
__Init__() {
cin.tie(nullptr)->sync_with_stdio(false);
if (fopen(Task".inp", "r")) {
freopen(Task".inp", "r", stdin);
freopen(Task".out", "w", stdout); }
}
} __init__;
using ll = long long;
#ifdef LOCAL
#define debug(x) cerr << "[" #x " = " << x << "]\n";
#else
#define debug(...)
#endif // LOCAL
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define fi first
#define se second
#define For(i, l, r) for (int i = (l); i <= (r); ++i)
#define Ford(i, r, l) for (int i = (r); i >= (l); --i)
#define Rep(i, n) For (i, 0, (n) - 1)
#define Repd(i, n) Ford (i, (n) - 1, 0)
template<class C> int isz(const C& c) { return c.size(); }
template<class T> bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } return false; }
template<class T> bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } return false; }
constexpr int eps = 1e-9;
constexpr int inf = 1e9;
constexpr ll linf = 1e18;
// =============================================================================
constexpr int maxN = 1e6 + 5;
int n, nq;
int a[maxN];
int ql[maxN];
int qr[maxN];
int qk[maxN];
struct Sub1 {
bool test(int l, int r, int k) {
For (i, l, r) {
For (j, i + 1, r) {
if (a[i] > a[j] && a[i] + a[j] > k) {
return false;
}
}
}
return true;
}
void solve() {
For (i, 1, nq) {
cout << test(ql[i], qr[i], qk[i]) << '\n';
}
}
};
struct Sub2 {
bool test(int l, int r, int k) {
int mx = a[l];
For (i, l + 1, r) {
if (mx > a[i] && mx + a[i] > k) return false;
chmax(mx, a[i]);
}
return true;
}
void solve() {
For (i, 1, nq) {
cout << test(ql[i], qr[i], qk[i]) << '\n';
}
}
};
struct Sub3 {
vector<pair<int, int>> seg;
bool test(int l, int r) {
auto it = upper_bound(all(seg), make_pair(l, inf));
if (it == seg.begin()) return false;
--it;
return r <= it->se;
}
void solve() {
seg.reserve(n);
For (i, 1, n) {
int j = i;
while (j + 1 <= n && a[j] <= a[j + 1]) {
++j;
}
seg.emplace_back(i, j);
i = j;
}
For (i, 1, nq) {
cout << test(ql[i], qr[i]) << '\n';
}
}
};
signed main() {
cin >> n >> nq;
For (i, 1, n) cin >> a[i];
For (i, 1, nq) {
cin >> ql[i] >> qr[i] >> qk[i];
}
bool sub3 = true;
{
int mn = *min_element(a + 1, a + n + 1);
For (i, 1, nq) {
sub3 &= (qk[i] < mn);
}
}
#define SUB(x) \
Sub##x* sol = new Sub##x{}; \
sol->solve(); delete sol
if (n <= 500 && nq <= 500) {
SUB(1);
} else if (n <= 5000 && nq <= 5000) {
SUB(2);
} else if (sub3) {
SUB(3);
} else {
assert(false);
}
}
/*
*/
Compilation message (stderr)
sortbooks.cpp: In constructor '__Init__::__Init__()':
sortbooks.cpp:11:20: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
11 | freopen(Task".inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
sortbooks.cpp:12:20: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
12 | 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... |