#include <cstdio>
#include <vector>
#include <algorithm>
#include <cstring>
#define PB push_back
#define X first
#define Y second
#define deb(...) fprintf(stderr, __VA_ARGS__)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int LOG = 20;
const int N = 1 << LOG;
int n, a[N];
int t[2 * N];
void update(int x, int w) {
x += N;
t[x] = max(t[x], w);
for(x >>= 1; x; x >>= 1) { t[x] = max(t[2 * x], t[2 * x + 1]); }
}
int query(int l, int r, int u = 1, int lo = 0, int hi = N) {
if(r <= lo || hi <= l) { return 0; }
if(l <= lo && hi <= r) { return t[u]; }
int mi = (lo + hi) / 2;
return max(query(l, r, 2 * u, lo, mi), query(l, r, 2 * u + 1, mi, hi));
}
int T[2 * N];
void upd(int x, int w) {
x += N;
T[x] = w;
for(x >>= 1; x; x >>= 1) { T[x] = max(T[2 * x], T[2 * x + 1]); }
}
int qry(int x, int u = 1, int lo = 0, int hi = N) {
if(lo + 1 == hi) { return u - N; }
int mi = (lo + hi) / 2;
if(T[2 * u + 1] > x) { return qry(x, 2 * u + 1, mi, hi); }
return qry(x, 2 * u, lo, mi);
}
int ans[N], k[N];
vector<pii> q[N];
int main() {
int m;
scanf("%d%d", &n, &m);
for(int i = 1; i <= n; ++i) { scanf("%d", a + i); }
for(int i = 0; i < m; ++i) {
int l, r;
scanf("%d%d%d", &l, &r, k + i);
q[r].PB({l ,i});
}
for(int i = 1; i <= n; ++i) {
upd(i, a[i]);
int ind = qry(a[i]);
update(ind, a[ind] + a[i]);
for(auto &j : q[i]) { ans[j.Y] = query(j.X, i + 1) > k[j.Y]; }
}
for(int i = 0; i < m; ++i) printf("%d\n", !ans[i]);
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
sortbooks.cpp: In function 'int main()':
sortbooks.cpp:56:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
56 | scanf("%d%d", &n, &m);
| ~~~~~^~~~~~~~~~~~~~~~
sortbooks.cpp:57:40: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
57 | for(int i = 1; i <= n; ++i) { scanf("%d", a + i); }
| ~~~~~^~~~~~~~~~~~~
sortbooks.cpp:61:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
61 | scanf("%d%d%d", &l, &r, k + i);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~| # | 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... |