이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
typedef long long ll;
typedef pair<ll,int> ii;
const int N = 2e5;
const ll INF = 1e18;
int n, q;
ll x[N+2], ans[N+2];
int main() {
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> n >> q;
for (int i = 1; i <= n; i++) {
cin >> x[i];
}
vector<ii> dl, dr;
for (int i = 1; i <= n; i++) {
if (i == 1) dl.push_back({INF,i});
else dl.push_back({x[i]-x[i-1],i});
if (i == n) dr.push_back({INF,i});
else dr.push_back({x[i+1]-x[i],i});
}
sort(dl.begin(),dl.end());
sort(dr.begin(),dr.end());
ll pl = 0, pr = 0, lf = 0, rg = 0, ps = 0;
while (q--) {
ll w; cin >> w;
ps += w;
while (pl < n && dl[pl].fi <= rg-ps) {
ans[dl[pl].se] += max(-lf,dl[pl].fi-rg);
pl++;
}
while (pr < n && dr[pr].fi <= ps-lf) {
ans[dr[pr].se] += max(rg,dr[pr].fi+lf);
pr++;
}
lf = min(lf,ps);
rg = max(rg,ps);
}
for (; pl < n; pl++) ans[dl[pl].se] += -lf;
for (; pr < n; pr++) ans[dr[pr].se] += rg;
for (int i = 1; i <= n; i++) {
cout << ans[i] << '\n';
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |