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>
using namespace std;
#define ll long long
#define pb push_back
#define ff first
#define ss second
#define all(s) s.begin(),s.end()
#define rall(s) s.rbegin(),s.rend()
struct segtree{
int n;
vector<int>d;
segtree(int n):n(n){
d.resize(4*n);
build(1,0,n-1);
}
void build(int node,int l,int r){
if(l==r){
d[node]=0;
return;
}
int mid=(l+r)/2;
build(node*2,l,mid);
build(node*2+1,mid+1,r);
}
int query(int node,int l,int r,int L,int R){
if(l>r||L>r||l>R) return 0;
if(l<=L&&R<=r){
return d[node];
}
int mid=(l+r)/2;
return max(query(node*2,l,mid,L,R),query(node*2+1,mid+1,r,L,R));
}
void update(int node,int l,int r,int pos,int val){
if(pos<l||r<pos) return;
if(l==r){
d[node]=val;
return;
}
int mid=(l+r)/2;
update(node*2,l,mid,pos,val);
update(node*2+1,mid+1,r,pos,val);
d[node]=max(d[node*2],d[node*2+1]);
}
};
vector<ll>minimum_costs(vector<int>H,vector<int>L,vector<int>R){
int n=H.size(),m=L.size();
vector<ll>ans(m,1e18);
vector<int>p;
for(int i=0;i<n;i++){
if(H[i]==2){
p.pb(i);
}
}
segtree sg(n);
for(int i=1;i<p.size();i++){
sg.update(1,0,n-1,p[i-1],p[i]-p[i-1]-1);
}
for(int j=0;j<m;j++){
if(p.empty()){
ans[j]=R[j]-L[j]+1;
continue;
}
int l=lower_bound(all(p),L[j])-p.begin();
if(l==p.size()||p[l]>R[j]){
ans[j]=R[j]-L[j]+1;
continue;
}
int r=lower_bound(all(p),R[j]+1)-p.begin();
r--;
int mx=sg.query(1,0,n-1,l,r-1);
mx=max(mx,p[l]-L[j]);
mx=max(mx,R[j]-p[r]);
ans[j]=2*(R[j]-L[j]+1)-mx;
}
return ans;
}
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:59:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
59 | for(int i=1;i<p.size();i++){
| ~^~~~~~~~~
meetings.cpp:68:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
68 | if(l==p.size()||p[l]>R[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... |