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("O3,unroll-loops")
#pragma GCC target("avx,popcnt,sse4,abm")
#include <bits/stdc++.h>
using namespace std;
#ifdef WAIMAI
#define debug(HEHE...) cout << "[" << #HEHE << "] : ", dout(HEHE)
void dout() {cout << '\n';}
template<typename T, typename...U>
void dout(T t, U...u) {cout << t << (sizeof...(u) ? ", " : ""), dout(u...);}
#else
#define debug(...) 7122
#endif
#define int long long
#define ll long long
#define Waimai ios::sync_with_stdio(false), cin.tie(0)
#define FOR(x,a,b) for (int x = a, I = b; x <= I; x++)
#define pb emplace_back
#define F first
#define S second
const int SIZE = 2e5 + 5;
int n, q;
int x[SIZE], delta[SIZE], ans[SIZE];
int mxl, mxr;
vector<tuple<int, int, int>> v;
pair<int, int> cal(int len) {
int pos = lower_bound(v.begin(), v.end(), make_tuple(len, LLONG_MIN, 0)) - v.begin();
if (pos == v.size()) return {mxr, mxl};
auto [tot, val, ty] = v[pos];
if (ty == 0) return {val, len - val};
else return {len - val, val};
}
void solve() {
cin >> n >> q;
FOR (i, 1, n) cin >> x[i];
FOR (i, 1, q) {
int w;
cin >> w;
delta[i] = delta[i - 1] + w;
}
FOR (i, 1, q) {
if (delta[i] > 0) {
if (delta[i] > mxr) {
mxr = delta[i];
v.pb(mxl + mxr, mxl, 1);
}
}
if (delta[i] < 0) {
if (-delta[i] > mxl) {
mxl = -delta[i];
v.pb(mxl + mxr, mxr, 0);
}
}
}
FOR (i, 1, n - 1) {
auto [vl, vr] = cal(x[i + 1] - x[i]);
ans[i] += vl;
ans[i + 1] += vr;
}
ans[1] += mxl;
ans[n] += mxr;
FOR (i, 1, n) cout << ans[i] << '\n';
}
int32_t main() {
Waimai;
solve();
}
Compilation message (stderr)
Main.cpp: In function 'std::pair<long long int, long long int> cal(long long int)':
Main.cpp:32:13: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::tuple<long long int, long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
32 | if (pos == v.size()) return {mxr, mxl};
| ~~~~^~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |