이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef int64_t llo;
#define mp make_pair
#define pb push_back
#define a first
#define b second
int n;
//int it[1000001];
int aa,bb,cc;
int tree3[4000001];
int tree2[4000001];
vector<int> tree[4000001];
void build(int no,int l,int r){
if(l==r){
cin>>tree3[no];
// tree3[no]=it[l];
tree[no].pb(tree3[no]);
tree2[no]=0;
}
else{
int mid=(l+r)/2;
build(no*2+1,l,mid);
build(no*2+2,mid+1,r);
tree3[no]=max(tree3[no*2+1],tree3[no*2+2]);
int ind=0;
int ind2=0;
while(ind<tree[no*2+1].size() and ind2<tree[no*2+2].size()){
if(tree[no*2+1][ind]<tree[no*2+2][ind2]){
tree[no].pb(tree[no*2+1][ind]);
ind+=1;
}
else{
tree[no].pb(tree[no*2+2][ind2]);
ind2+=1;
}
}
while(ind<tree[no*2+1].size()){
tree[no].pb(tree[no*2+1][ind]);
ind+=1;
}
while(ind2<tree[no*2+2].size()){
tree[no].pb(tree[no*2+2][ind2]);
ind2+=1;
}
auto x=lower_bound(tree[no*2+2].begin(),tree[no*2+2].end(),tree3[no*2+1]);
if(x!=tree[no*2+2].begin()){
x--;
tree2[no]=tree3[no*2+1]+(*x);
}
else{
tree2[no]=0;
}
tree2[no]=max(tree2[no],tree2[no*2+1]);
tree2[no]=max(tree2[no],tree2[no*2+2]);
}
// cout<<l<<","<<r<<","<<tree2[no]<<","<<tree3[no]<<endl;
}
int ma=0;
int ans[1000001];
//vector<pair<int,int>> of[4000001];
pair<pair<int,int>,int> qq[1000001];
int val[1000001];
int ind5;
void query(int no,int l,int r,int aa,int bb){
if(r<aa or l>bb){
return;
}
if(aa<=l and r<=bb){
ans[ind5]=max(ans[ind5],tree2[no]);
// of[no].pb({ma,ind5});
ma=max(tree3[no],ma);
/*auto x=lower_bound(tree[no].begin(),tree[no].end(),ma);
if(x!=tree[no].begin()){
x--;
ans=max(ans,(*x)+ma);
}*/
}
else{
int mid=(l+r)/2;
query(no*2+1,l,mid,aa,bb);
query(no*2+2,mid+1,r,aa,bb);
}
}
int ind;
/*void proc(int no,int l,int r){
ind=-1;
for(auto i:of[no]){
while(ind+1<tree[no].size()){
if(tree[no][ind+1]<i.a){
ind+=1;
}
else{
break;
}
}
if(ind>-1){
ans[i.b]=max(tree[no][ind]+i.a,ans[i.b]);
}
}
if(l<r){
int mid=(l+r)/2;
proc(no*2+1,l,mid);
proc(no*2+2,mid+1,r);
}
}*/
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int m;
cin>>n>>m;
/*for(int i=0;i<n;i++){
cin>>it[i];
}*/
build(0,0,n-1);
for(int i=0;i<m;i++){
ans[i]=0;
cin>>aa>>bb>>cc;
aa-=1;
bb-=1;
qq[i]={{-aa,bb},i};
val[i]=cc;
}
return 0;
sort(qq,qq+m);
/* for(int i=0;i<m;i++){
aa=-qq[i].a.a;
bb=qq[i].a.b;
ind5=qq[i].b;
ma=0;
query(0,0,n-1,aa,bb);
}
proc(0,0,n-1);
for(int i=0;i<m;i++){
cout<<((ans[i]<=val[i])?1:0)<<'\n';
}
*/
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
sortbooks.cpp: In function 'void build(int, int, int)':
sortbooks.cpp:28:12: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
while(ind<tree[no*2+1].size() and ind2<tree[no*2+2].size()){
~~~^~~~~~~~~~~~~~~~~~~~
sortbooks.cpp:28:41: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
while(ind<tree[no*2+1].size() and ind2<tree[no*2+2].size()){
~~~~^~~~~~~~~~~~~~~~~~~~
sortbooks.cpp:38:12: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
while(ind<tree[no*2+1].size()){
~~~^~~~~~~~~~~~~~~~~~~~
sortbooks.cpp:42:13: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
while(ind2<tree[no*2+2].size()){
~~~~^~~~~~~~~~~~~~~~~~~~
# | 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... |