이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define maxN 1000006
using namespace std;
struct segment{
vector <int> v;
int res;
};
int a[maxN],n,m,i,l,d,k,ans,M;
segment seg[4*maxN];
void build(int n,int l,int d){
if(l==d){
seg[n].v.push_back(a[l]);
seg[n].res=1;
return;
}
int m=(l+d)/2;
build(2*n,l,m);
build(2*n+1,m+1,d);
int i,j;
i=j=0;
while(i<seg[2*n].v.size() & j<seg[2*n+1].v.size()){
if(seg[2*n].v[i]<=seg[2*n+1].v[j]) {seg[n].v.push_back(seg[2*n].v[i]); i++;}
else {seg[n].v.push_back(seg[2*n+1].v[j]); j++;}
}
while(i<seg[2*n].v.size()) {seg[n].v.push_back(seg[2*n].v[i]); i++;}
while(j<seg[2*n+1].v.size()) {seg[n].v.push_back(seg[2*n+1].v[j]); j++;}
M=seg[2*n].v.back();
int tmp=lower_bound(seg[2*n+1].v.begin(),seg[2*n+1].v.end(),M)-seg[2*n+1].v.begin();
tmp--;
if(tmp>=0) seg[n].res=seg[2*n+1].v[tmp]+M;
else seg[n].res=0;
}
void resi(int n,int l,int d,int x,int y){
if(d<x || l>y || ans==0){
return;
}
if(l>=x && d<=y){
//cout<<l<<" "<<d<<" "<<M<<" "<<n<<endl;
int tmp=lower_bound(seg[n].v.begin(),seg[n].v.end(),M)-seg[n].v.begin();
tmp--;
if(tmp>=0 && seg[n].v[tmp]+M>k) ans=0;
if(seg[n].res>k) ans=0;
M=max(M,seg[n].v.back());
return;
}
int m=(l+d)/2;
resi(2*n,l,m,x,y);
resi(2*n+1,m+1,d,x,y);
}
int main()
{
std::ios_base::sync_with_stdio(0);
cin>>n>>m;
for(i=0;i<n;i++){
cin>>a[i];
}
build(1,0,n-1);
for(i=0;i<m;i++){
cin>>l>>d>>k;
ans=1;
M=0;
resi(1,0,n-1,l-1,d-1);
cout<<ans<<"\n";
}
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
sortbooks.cpp: In function 'void build(int, int, int)':
sortbooks.cpp:24:8: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
while(i<seg[2*n].v.size() & j<seg[2*n+1].v.size()){
~^~~~~~~~~~~~~~~~~~
sortbooks.cpp:24:30: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
while(i<seg[2*n].v.size() & j<seg[2*n+1].v.size()){
~^~~~~~~~~~~~~~~~~~~~
sortbooks.cpp:24:8: warning: suggest parentheses around comparison in operand of '&' [-Wparentheses]
while(i<seg[2*n].v.size() & j<seg[2*n+1].v.size()){
~^~~~~~~~~~~~~~~~~~
sortbooks.cpp:28:8: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
while(i<seg[2*n].v.size()) {seg[n].v.push_back(seg[2*n].v[i]); i++;}
~^~~~~~~~~~~~~~~~~~
sortbooks.cpp:29:8: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
while(j<seg[2*n+1].v.size()) {seg[n].v.push_back(seg[2*n+1].v[j]); j++;}
~^~~~~~~~~~~~~~~~~~~~
# | 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... |