# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1092722 | I_am_Polish_Girl | Snowball (JOI21_ho_t2) | C++14 | 91 ms | 11448 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")
#pragma GCC optimize("O3")
#pragma GCC optimization ("unroll-loops")
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <queue>
#include <cmath>
#include <random>
#include <chrono>
#include <iomanip>
#include <iostream>
#include <bitset>
#define int long long
using namespace std;
int log_ = 3;
int inf = 200000000000000;
int mod = 5;
int p = 505;
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int n , m;
cin >> n >> m;
vector <int> a(n);
for (int i = 0; i < n; i++)
cin >> a[i];
vector <int> pr;
pr.push_back(0);
int p = 0;
for (int i = 0; i < m; i++)
{
int x;
cin >> x;
p += x;
pr.push_back(p);
}
int mx = 0;
int mn = 0;
vector <int> pr2;
pr2.push_back(0);
for (int i = 1; i <= m; i++)
{
if (mn > pr[i])
{
if (i + 1 <= m)
{
if (pr[i] > pr[i + 1])
continue;
}
pr2.push_back(pr[i]);
mn = pr[i];
}
if (mx < pr[i])
{
if (i + 1 <= m)
{
if (pr[i] < pr[i + 1])
continue;
}
pr2.push_back(pr[i]);
mx = pr[i];
}
}
pr = pr2;
vector <int> l(pr.size(), 0);
vector <int> r(pr.size() , 0);
for (int i = 1; i < pr.size(); i++)
{
l[i] = min(l[i - 1], pr[i]);
r[i] = max(r[i - 1], pr[i]);
}
for (int i = 0; i < n; i++)
{
int pr_ = -inf;
if (i > 0)
pr_ = a[i - 1];
int lx = 0;
int rx = pr.size();
while (rx - lx > 1)
{
int m = (lx + rx) / 2;
if ((-l[m] + r[m]) <= (a[i] - pr_))
{
lx = m;
}
else
rx = m;
}
int ans = 0;
ans += -l[lx];
if (lx + 1 < l.size())
{
if (l[lx] > l[lx + 1])
{
ans += (a[i] - pr_) - (-l[lx] + r[lx]);
}
}
int next_ = inf;
if (i + 1 < n)
next_ = a[i + 1];
lx = 0;
rx = pr.size();
while (rx - lx > 1)
{
int m = (lx + rx) / 2;
if ((-l[m] + r[m]) <= (next_ - a[i]))
{
lx = m;
}
else
rx = m;
}
ans += r[lx];
if (lx + 1 < r.size())
{
if (r[lx] < r[lx + 1])
{
ans += (next_ - a[i]) - (-l[lx] + r[lx]);
}
}
cout << ans << "\n";
}
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |