# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
878057 | frostray8653 | Snowball (JOI21_ho_t2) | C++17 | 3 ms | 8692 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// #pragma GCC optimize("Ofast,unroll-loops,O3")
#include <bits/stdc++.h>
#define int long long
// #define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define IO ios::sync_with_stdio(0), cin.tie(0)
#define FOR(i, a, b) for (int i = a, I = b; i <= b; i++)
using namespace std;
void dbg() {;}
template<class T, class ...U>
void dbg(T a, U ...b) {cout << a << " "; dbg(b...);}
void ent() {cout << "\n";}
const int mod = 998244353;
// const int mod = 1e9 + 7;
// const int INF = 2e9;
const int INF = 1e18;
/// ------- Initialization End -------
const int N = 200005;
int a[N];
int dx[N];
int bestl[N], bestr[N];
int ansl[N], ansr[N];
signed main() {
IO;
int n, m;
cin >> n >> m;
FOR(i, 1, n) cin >> a[i];
FOR(i, 1, m) cin >> dx[i];
int now = 0;
int lft = 0, rgt = 0;
FOR(i, 1, m) {
now += dx[i];
lft = min(lft, now);
rgt = max(rgt, now);
bestl[i] = lft;
bestr[i] = rgt;
}
a[0] = -INF;
a[n + 1] = INF;
FOR(i, 0, n) {
int dif = a[i + 1] - a[i];
int l = 1, r = m + 1;
while (l + 1 < r) {
int mid = (l + r) >> 1;
if (bestr[mid] - bestl[mid] >= dif)
r = mid;
else
l = mid;
}
int id = l;
int len = bestr[id] - bestl[id];
ansr[i + 0] = a[i + 0] + bestr[id];
ansl[i + 1] = a[i + 1] + bestl[id];
if (id < m) {
if (bestr[id + 1] > bestr[id]) {
ansr[i + 0] += dif - len;
} else {
ansl[i + 1] -= dif - len;
}
}
}
FOR(i, 1, n)
cout << ansr[i] - ansl[i] << "\n";
return 0;
}
/*
4 3
-2 3 5 8
2
-4
7
*/
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |