이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "meetings.h"
#include <bits/stdc++.h>
using namespace std;
long long rsq[5005][5005];
int cnt[100005];
int idx[100005];
vector<int>highs;
vector<int>nhighs;
int st[100005][20];
int query(int l,int r){
if(l>r) return 0;
int m=log2(r-l+1);
//cout<<l<<" "<<r<<": "<<max(st[l][m],st[r-(1<<m)+1][m])<<endl;
return max(st[l][m],st[r-(1<<m)+1][m]);
}
vector<long long> minimum_costs(vector<int> H, vector<int> L, vector<int> R){
vector<long long>ret;
int N=H.size();
if(N<=2){
memset(rsq,0,sizeof rsq);
for(int i=0;i<N;i++){
int maxi=H[i];
rsq[i][i]=H[i];
for(int j=i-1;j>=0;j--){
maxi=max(maxi,H[j]);
rsq[i][j]=rsq[i][j+1]+maxi;
}
maxi=H[i];
for(int j=i+1;j<N;j++){
maxi=max(maxi,H[j]);
rsq[i][j]=rsq[i][j-1]+maxi;
}
}
for(int q=0;q<L.size();q++){
int l=L[q],r=R[q];
long long res=LONG_LONG_MAX;
for(int i=l;i<=r;i++){
res=min(res,rsq[i][l]+rsq[i][r]-H[i]);
}
ret.push_back(res);
}
}
else{
int last=-1;
cnt[0]=0;
for(int i=0;i<N;i++){
if(i>0) cnt[i]=cnt[i-1];
if(H[i]==2){
idx[i]=highs.size();
cnt[i]++;
highs.push_back(i);
nhighs.push_back(-i);
}
}
highs.push_back(N);
int M=cnt[N-1];
for(int i=0;i<M;i++){
st[i][0]=highs[i+1]-highs[i];
}
for(int j=1;j<20;j++){
for(int i=0;i<=M-(1<<j);i++){
st[i][j]=max(st[i][j-1],st[i+(1<<(j-1))][j-1]);
}
}
for(int q=0;q<L.size();q++){
int l=L[q],r=R[q];
if(cnt[r]-cnt[l]+(int)(H[l]==2)==0){
ret.push_back(r-l+1);
}
else{
int l1=*lower_bound(highs.begin(),highs.end(),l);
int l2=*lower_bound(nhighs.rbegin(),nhighs.rend(),-r);
l2*=-1;
int ans=max(l1-l,r-l2);
if(l1!=l2){
int idx1=idx[l1],idx2=idx[l2]-1;
ans=max(query(idx1,idx2)-1,ans);
}
ret.push_back(2*(r-l+1)-ans);
}
hell:;
}
}
return ret;
}
컴파일 시 표준 에러 (stderr) 메시지
meetings.cpp: In function 'std::vector<long long int> minimum_costs(std::vector<int>, std::vector<int>, std::vector<int>)':
meetings.cpp:34:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int q=0;q<L.size();q++){
~^~~~~~~~~
meetings.cpp:65:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int q=0;q<L.size();q++){
~^~~~~~~~~
meetings.cpp:44:7: warning: unused variable 'last' [-Wunused-variable]
int last=-1;
^~~~
meetings.cpp:81:4: warning: label 'hell' defined but not used [-Wunused-label]
hell:;
^~~~
# | 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... |