This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
//Make CSP great again
//Vengeance
#include <bits/stdc++.h>
#define TASK "TESTCODE"
#define Log2(x) 31 - __builtin_clz(x)
using namespace std;
const int N = 2e5;
const long long oo = 1e18 + 10;
long long x[N + 1], l[N + 1], r[N + 1], cur, MaxLeft = 0, MaxRight = 0;
int n, q, id[N + 1];
void read()
{
cin >> n >> q;
for (int i = 1; i <= n; ++ i)
{
cin >> x[i];
id[i] = i;
l[i] = -oo;
r[i] = oo;
}
sort(id + 1, id + n, [&](const int &a, const int &b)
{
return x[a + 1] - x[a] < x[b + 1] - x[b];
});
}
void solve()
{
int i = 1;
while(q--)
{
long long w;
cin >> w;
cur += w;
MaxRight = max(MaxRight, cur);
MaxLeft = min(MaxLeft, cur);
for (; i < n && x[id[i] + 1] - x[id[i]] <= MaxRight - MaxLeft; ++ i)
{
int j = id[i];
if (w > 0)
{
r[j] = x[j + 1] + MaxLeft - 1;
l[j + 1] = x[j + 1] + MaxLeft;
}
else
{
l[j + 1] = x[j] + MaxRight;
r[j] = x[j] + MaxRight - 1;
}
}
}
for (int i = 1; i <= n; ++ i)
{
//cerr << l[i] << ' ' << r[i] << '\n';
long long L = (l[i] == -oo ? x[i] + MaxLeft : l[i]), R = (r[i] == oo ? x[i] + MaxRight - 1 : r[i]);
//cerr << L << ' ' << R << '\n';
cout << R - L + 1 << '\n';
}
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
if (fopen(TASK".INP", "r"))
{
freopen(TASK".INP", "r", stdin);
//freopen(TASK".OUT", "w", stdout);
}
int t = 1;
bool typetest = false;
if (typetest)
{
cin >> t;
}
for (int __ = 1; __ <= t; ++ __)
{
//cout << "Case " << __ << ": ";
read();
solve();
}
}
Compilation message (stderr)
Main.cpp: In function 'int main()':
Main.cpp:65:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
65 | freopen(TASK".INP", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |