이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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{
ll n;
vector<ll>d;
vector<ll>u;
segtree(ll n):n(n){
d.resize(4*n);
build(1,0,n-1);
}
void build(ll node,ll l,ll r){
if(l==r){
d[node]=0;
return;
}
ll mid=(l+r)/2;
build(node*2,l,mid);
build(node*2+1,mid+1,r);
}
ll query(ll node,ll l,ll r,ll L,ll R){
if(l > R || r < L || L > R){
return 0;
}
if(L <= l && r <= R){
return d[node];
}
ll mid=(l+r)/2;
return max(query(node*2,l,mid,L,R),query(node*2+1,mid+1,r,L,R));
}
void update(ll node,ll l,ll r,ll k,ll val){
if(l>k || r<k)return;
if(l==r){
d[node]=val;
return;
}
ll mid=(l+r)/2;
update(node*2,l,mid,k,val);
update(node*2+1,mid+1,r,k,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;
}
컴파일 시 표준 에러 (stderr) 메시지
meetings.cpp: In function 'std::vector<long long int> minimum_costs(std::vector<int>, std::vector<int>, std::vector<int>)':
meetings.cpp:62:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
62 | for(int i=1;i<p.size();i++){
| ~^~~~~~~~~
meetings.cpp:71:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
71 | 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... |