This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
#include "meetings.h"
//#include "grader.cpp"
#define ll long long
#define pb push_back
#define sz size
#define fst first
#define scd second
#define vl vector<ll>
#define vi vector<int>
#define ii pair<int,int>
using namespace std;
vl minimum_costs(vi H, vi L,vi R) {
vl ret;
for(int i=0;i<L.sz();i++){
deque<ii>dq;
vl a1,a2;
ll sum=0;
for(int j=L[i];j<=R[i];j++){
int x=H[j];
ii to={x,1};
while(dq.sz()&& dq[0].fst<=to.fst ){
sum-=dq[0].fst*dq[0].scd;
to.scd+=dq[0].scd;
dq.pop_front();
}
sum+=to.fst*to.scd;
dq.push_front(to);
a1.pb(sum);
}
dq.clear();
sum=0;
for(int j=R[i];j>=L[i];j--){
int x=H[j];
ii to={x,1};
while(dq.sz()&& dq[0].fst<=to.fst ){
sum-=dq[0].fst*dq[0].scd;
to.scd+=dq[0].scd;
dq.pop_front();
}
sum+=to.fst*to.scd;
dq.push_front(to);
a2.pb(sum);
}
ll ans=1e18;
reverse(a2.begin(),a2.end());
for(int j=0;j<a1.sz();j++){
ll ai=a1[j];
if( j+1 != a1.sz() ){
ai+=a2[j+1];
}
ans=min(ans,ai);
}
ret.pb(ans);
// cout<<ans<<endl;
}
return ret;
}
//
//int main(){
//
// vi ans=minimum_costs({5,3,1,4,6,3,5,7,1},{0,1,3,3},{8,4,6,8});
//
//return 0;}
Compilation message (stderr)
meetings.cpp: In function 'std::vector<long long int> minimum_costs(std::vector<int>, std::vector<int>, std::vector<int>)':
meetings.cpp:21:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
21 | for(int i=0;i<L.sz();i++){
| ~^~~~~~~
meetings.cpp:59:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
59 | for(int j=0;j<a1.sz();j++){
| ~^~~~~~~~
meetings.cpp:61:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
61 | if( j+1 != a1.sz() ){
| ~~~~^~~~~~~~~~
# | 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... |