이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
//#define int ll
#define MottoHayaku ios::sync_with_stdio(0);cin.tie(0);
#define F first
#define S second
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define pb push_back
#define uni(c) c.resize(distance(c.begin(),unique(c.begin(),c.end())))
#define unisort(c) sort(c.begin(),c.end());uni(c);
#define X first
#define Y second
const int N=2e5+5;
ll x[N],l[N],r[N];
signed main()
{
MottoHayaku
ll n,q;
cin>>n>>q;
rep1(i,n) cin>>x[i];
vector<ll> mn(q+1,0),mx(q+1,0),d(q+1,0);
ll cur=0;
rep1(i,q)
{
ll w;
cin>>w;
cur+=w;
mn[i]=max(mn[i-1],-cur);
mx[i]=max(mx[i-1],cur);
d[i]=mx[i]+mn[i];
}
l[1]=x[1]-mn[q];
r[n]=x[n]+mx[q];
rep1(i,n-1)
{
ll z=x[i+1]-x[i];
ll pos=lower_bound(d.begin(),d.end(),z)-d.begin();
if(pos==d.size())
{
r[i]=x[i]+mx[q];
l[i+1]=x[i+1]-mn[q];
continue;
}
ll tmx=mx[pos],tmn=mn[pos];
ll pmx=lower_bound(mx.begin(),mx.end(),tmx)-mx.begin();
ll pmn=lower_bound(mn.begin(),mn.end(),tmn)-mn.begin();
if(pmn<pmx) l[i+1]=r[i]=x[i+1]-tmn;
else r[i]=l[i+1]=x[i]+tmx;
}
rep1(i,n) cout<<r[i]-l[i]<<"\n";
}
컴파일 시 표준 에러 (stderr) 메시지
Main.cpp: In function 'int main()':
Main.cpp:42:15: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
42 | if(pos==d.size())
| ~~~^~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |