이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
using namespace std;
#define int long long
#define nl '\n'
#define io ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
mt19937 rng((unsigned)chrono::steady_clock::now().time_since_epoch().count());
const int mod = 1000000007, mod2 = 998244353;
// change this
const int N = 200005;
int n, q, x[N], w, ans[N];
signed main() {
io;
// cout << "COMPILED" << endl;
cin >> n >> q;
vector< pair<int, pair<int, int> > > inter;
for (int i=0; i<n; i++) {
cin >> x[i];
if (i) inter.push_back({x[i] - x[i-1], {i-1, i}});
}
sort(inter.begin(), inter.end());
int l = 0, r = 0, d = 0, j = 0, m = inter.size();
for (int i=0; i<q; i++) {
cin >> w;
d += w;
int lo = l, ro = r; // old ones before we change
l = max(l, -d), r = max(r, d);
// cout << l << ' ' << r << endl;
// we can move at most r to the right and at most l to the left
while (j < m && inter[j].first < l + r) {
// this interval exceeds movement
// ok lets handle this
if (r > ro) {
// r increased
// cout << inter[j].second.first << ' ' << inter[j].first - lo << ' ' << lo << endl;
ans[inter[j].second.second] += lo; // has to be same as old l
ans[inter[j].second.first] += inter[j].first - lo; // take remaining
} else {
// l increased
// cout << inter[j].second.first << ' ' << ro << ' ' << inter[j].first - ro << endl;
ans[inter[j].second.first] += ro; // has to be same as old r
ans[inter[j].second.second] += inter[j].first - ro; // take remaining
}
j++;
}
}
ans[0] += l, ans[n-1] += r; // they can move boundless that way
while (j < m) {
ans[inter[j].second.first] += r;
ans[inter[j].second.second] += l;
j++;
}
for (int i=0; i<n; i++) cout << ans[i] << nl;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |