이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <cstdio>
#include <vector>
#define ll long long
#define Max(a, b) (((a) < (b)) ? (b) : (a))
#pragma GCC optimize ("O3")
const int nmax = 1e6 + 5;
struct day {
int st, dr, ind;
ll k;
} aux;
ll v[nmax], aint[4*nmax];
int last[nmax];
bool ans[nmax];
std::vector<int>st;
std::vector<day>skema[nmax];
void update(int node, int st, int dr, int x, ll val) {
if (st == dr and st == x) {
aint[node] = Max(aint[node], val); return;
}
int mij = (st + dr) >> 1;
if(x<=mij) update(node << 1, st, mij, x, val);
else update(node << 1 | 1, mij + 1, dr, x, val);
aint[node] = Max(aint[node << 1], aint[node << 1 | 1]);
}
ll query(int node, int st, int dr, int x, int y) {
if (y<st or x>dr) return 0;
if (x <= st and dr <= y) return aint[node];
int mij = (st + dr) >> 1;
return Max(query(node << 1, st, mij, x, y), query(node << 1 | 1, mij + 1, dr, x, y));
}
int main() {
int n, m;
scanf("%d%d", &n, &m);
for (int i = 1; i <= n; i++) scanf("%d", &v[i]);
st.push_back(n);
for (int i = n - 1; i >= 1; i--) {
while (!st.empty() and v[st.back()] < v[i]) last[st.back()] = i, st.pop_back();
st.push_back(i);
}
for (int i = 1; i <= m; i++) {
scanf("%d %d %lld", &aux.st, &aux.dr, &aux.k);
aux.ind = i;
skema[aux.dr].push_back(aux);
}
for (int i = 1; i <= n; i++) {
if (last[i] != 0) update(1, 1, n, last[i], v[i] + v[last[i]]);
for (day aux : skema[i]) ans[aux.ind] = (query(1, 1, n, aux.st, aux.dr) <= aux.k);
}
for (int i = 1; i <= m; i++) printf("%d\n", ans[i]);
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
sortbooks.cpp: In function 'int main()':
sortbooks.cpp:40:42: warning: format '%d' expects argument of type 'int*', but argument 2 has type 'long long int*' [-Wformat=]
40 | for (int i = 1; i <= n; i++) scanf("%d", &v[i]);
| ~^ ~~~~~
| | |
| | long long int*
| int*
| %lld
sortbooks.cpp:39:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
39 | scanf("%d%d", &n, &m);
| ~~~~~^~~~~~~~~~~~~~~~
sortbooks.cpp:40:39: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
40 | for (int i = 1; i <= n; i++) scanf("%d", &v[i]);
| ~~~~~^~~~~~~~~~~~~
sortbooks.cpp:47:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
47 | scanf("%d %d %lld", &aux.st, &aux.dr, &aux.k);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# | 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... |