이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define fi first
#define se second
using namespace std;
typedef pair<int,int> ii;
typedef tuple<int,int,int, int> iiii;
int n,m;
ii p[1000005];
int ans[1000005];
int w[1000005];
vector<ii> st;
iiii q[1000005];
struct node{
int s,e,m,v;
node *l, *r;
node (int _s, int _e): s(_s), e(_e){
m = (s+e)/2;
v = 0;
if (s != e){
l = new node(s,m);
r = new node(m+1,e);
}
}
void up(int x, int nv){
if (s == e) {
v = max(v,nv);
return;
}
if (x > m) r->up(x,nv);
else if (x <= m) l->up(x,nv);
v = max(l->v,r->v);
}
int qu(int qs ,int qe){
if (qs == qe) return v;
if (qs > m) return r->qu(qs,qe);
else if (qe <= m) return l->qu(qs,qe);
else return max(l->qu(qs,m),r->qu(m+1,qe));
}
} *root;
int main(){
scanf("%d%d",&n,&m);
for (int i = 1; i <= n; i++) {
scanf("%d",&w[i]);
while (st.size() && st.back().fi <= w[i]) st.pop_back();
if (st.size()) p[i] = {st.back().fi + w[i], st.back().se};
else p[i] = {0,1};
st.push_back({w[i],i});
}
root = new node(1,n);
int l,r,k;
for (int i = 0; i < m; i++){
scanf("%d%d%d",&l,&r,&k);
q[i] = {r,l,k,i};
}
int cur = 0;
sort(q,q+m);
for (int i = 0; i < m; i++){
int l,r,k,id;
tie(r,l,k,id) = q[i];
while (cur <= r){
root->up(p[cur].se, p[cur].fi);
cur++;
}
ans[id] = (root->qu(l,r) <= k);
}
for (int i = 0; i < m; i++){
printf("%d\n",ans[i]);
}
}
컴파일 시 표준 에러 (stderr) 메시지
sortbooks.cpp: In function 'int main()':
sortbooks.cpp:41:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
41 | scanf("%d%d",&n,&m);
| ~~~~~^~~~~~~~~~~~~~
sortbooks.cpp:43:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
43 | scanf("%d",&w[i]);
| ~~~~~^~~~~~~~~~~~
sortbooks.cpp:52:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
52 | scanf("%d%d%d",&l,&r,&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... |