이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "meetings.h"
#include <bits/stdc++.h>
using namespace std;
#define dbgv(v) cout<<#v<<" = "; f(i,0,int(v.size())) cout<<v[i]<<" "; cout<<endl
#define dbga(a,x,y) cout<<#a<<" = "; f(i,x,y) cout<<a[i]<<" "; cout<<endl
#define erorp(x) cout<<#x<<"={"<<x.F<<" , "<<x.S<<"}"<<endl
#define eror(x) cout<<#x<<'='<<(x)<<endl
#define f_(i,a,b) for(int i=a;i>=b;i--)
#define f(i,a,b) for(int i=a;i<b;i++)
#define nb(x) __builtin_popcount(x)
#define all(v) v.begin(),v.end()
#define bit(n,k) (((n)>>(k))&1)
#define Add(x,y) x=(x+y)%mod
#define maxm(a,b) a=max(a,b)
#define minm(a,b) a=min(a,b)
#define lst(x) x[x.size()-1]
#define sz(x) int(x.size())
#define mp make_pair
#define ll long long
#define pb push_back
#define S second
#define F first
const int N=1e6+99;
const ll inf=1e9+99;
int n,q;
ll res[N];
vector<ll> H,A;
vector<ll> ans;
ll solve(vector<ll> A){
vector<ll> vec(1);
ll sum=0;
f(i,0,int(A.size())) res[i]=0;
f(i,1,int(A.size())-1){
while(A[i]>=A[vec.back()]){
int x=vec.back(),y=x;
vec.pop_back();
if(vec.size()) y=vec.back();
sum-=(x-y)*A[x];
}
sum+=(i-vec.back())*A[i];
res[i]+=sum;
vec.pb(i);
}
sum=0;
vec.resize(1);
vec[0]=A.size()-1;
f_(i,int(A.size())-2,1){
while(A[i]>=A[vec.back()]){
int x=vec.back(),y=x;
vec.pop_back();
if(vec.size()) y=vec.back();
sum-=(y-x)*A[x];
}
sum+=(vec.back()-i)*A[i];
res[i]+=sum;
vec.pb(i);
}
ll ans=1ll*N*inf,mx=0;
f(i,1,int(A.size())-1){
//minm(ans,res[i]-A[i]);
sum=mx=A[i];
f_(j,i-1,1){
maxm(mx,A[j]);
sum+=mx;
}
mx=A[i];
f(j,i+1,A.size()-1){
maxm(mx,A[j]);
sum+=mx;
}
minm(ans,sum);
}
return ans;
}
vector<ll> minimum_costs(vector<int> _H,vector<int> L,vector<int> R){
q=L.size(),n=_H.size();
f(i,0,n) H.pb(_H[i]);
ans.resize(q);
f(i,0,q){
A.clear();
A.pb(inf);
f(j,L[i],R[i]+1) A.pb(H[j]);
A.pb(inf);
ans[i]=solve(A);
}
return ans;
}
컴파일 시 표준 에러 (stderr) 메시지
meetings.cpp: In function 'long long int solve(std::vector<long long int>)':
meetings.cpp:9:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
9 | #define f(i,a,b) for(int i=a;i<b;i++)
......
70 | f(j,i+1,A.size()-1){
| ~~~~~~~~~~~~~~~~
meetings.cpp:70:5: note: in expansion of macro 'f'
70 | f(j,i+1,A.size()-1){
| ^
# | 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... |