/*
KAMUI!
▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
▓▓▓▓▓▓▓▓▓▓▓▓▓██████████▓▓▓▓▓▓▓▓▓▓▓▓▓▓
▓▓▓▓▓▓▓▓▓▓███▓▓▓▓▓▓▓▓▓▓█████▓▓▓▓▓▓▓▓▓
▓▓▓▓▓▓▓███▓▒▒░▒▒▒▒▒░░░▒▒▒▓▓███▓▓▓▓▓▓▓
▓▓▓▓▓▓█▓▒▒▒▓▓████████▓▒▒░▒▒▒▓██▓▓▓▓▓▓
▓▓▓▓██▒▓████████████████▓░▒▒▒▒▓██▓▓▓▓
▓▓▓██▓███████▓▒░░░░░░░▒███▒░░▒▒▒██▓▓▓
▓▓█████████▓░░░░░░░░░░░░░██▓▓██████▓▓
▓▓█▒▓███████████▓▓▒▒▒▓▓██████████▓█▓▓
▓██▒▒▒███████████████████████████▓▓█▓
▓█▓▒▒░░████████▒░░░░▓███████████▓░▒█▓
▓█▒▒▒░██░▒████░░░░░░█████░░████▓░░▒█▓
▓█▒▒▒▒██░░░██▓░░░░░░░███▒░░████▒▒▒▒█▓
▓█▓▒▒▒██▒░░░▓█▓░░░░░▓█▓░░░▓███▓▒▒░▓█▓
▓█▓▒▒▒███░░░░████████▓░░░░░████▒▒▒▓█▓
▓▓█▒▒░▓███░░░▒███████▒░░░▒███▓▒▒▒▒█▓▓
▓▓██▒▒░████▒░░███████░░░▓███▓░▒▒▒██▓▓
▓▓▓██▒▒▒█████▓░░██████▒▓███▓▒░▒▒██▓▓▓
▓▓▓▓██▓▒░▓██████████████▓▒░▒▒▒▓██▓▓▓▓
▓▓▓▓▓▓██▓░▒▓█████████▒░░▒▒▒▒▓██▓▓▓▓▓▓
▓▓▓▓▓▓▓███▓▒▒▓██████▓░▒▒▒▓▓███▓▓▓▓▓▓▓
▓▓▓▓▓▓▓▓▓▓▓███▓▓▓▓███▓▓▓████▓▓▓▓▓▓▓▓▓
▓▓▓▓▓▓▓▓▓▓▓▓▓███████████▓▓▓▓▓▓▓▓▓▓▓▓▓
▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
*/
#include <iostream>
#include <complex>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <deque>
#include <random>
using namespace std;
template<typename T1, typename T2> inline void chkmin(T1 &a, T2 b) {if (a > b) a = b;}
template<typename T1, typename T2> inline void chkmax(T1 &a, T2 b) {if (a < b) a = b;}
#define files(FILENAME) read(FILENAME); write(FILENAME)
#define read(FILENAME) freopen((FILENAME + ".in").c_str(), "r", stdin)
#define write(FILENAME) freopen((FILENAME + ".out").c_str(), "w", stdout)
#define all(c) (c).begin(), (c).end()
#define sz(c) (int)(c).size()
#define left left228
#define right right228
#define y1 y1228
#define mp make_pair
#define pb push_back
#define y2 y2228
#define rank rank228
using ll = long long;
using ld = long double;
const string FILENAME = "input";
const int Mod = 1000000007;
int sum(int a, int b) {
return (a + b >= Mod ? a + b - Mod: a + b);
}
int mul(int a, int b) {
return ((ll)a * b) % Mod;
}
int powm(int a, int b) {
int res = 1;
while (b) {
if (b & 1) {
res = mul(res, a);
}
a = mul(a, a);
b >>= 1;
}
return res;
}
int inv(int a) {
return powm(a, Mod - 2);
}
const int MAXN = 200229;
int n, q;
ll x[MAXN];
ll val[MAXN];
void solve() {
cin >> n >> q;
for (int i = 0; i < n; i++) {
cin >> x[i];
}
ll sum = 0;
ll kek = 0;
ll kek1 = 0;
vector<pair<ll, int> > ste, ste1;
for (int it = 0; it < q; it++) {
ll shift;
cin >> shift;
sum += shift;
if (sum > kek) {
ste1.pb(mp(sum, -kek1));
}
if (sum < kek1) {
ste.pb(mp(-sum, kek));
}
chkmax(kek, sum);
chkmin(kek1, sum);
}
vector<pair<ll, int> > st, st1;
for (int i = 0; i < n; i++) {
ll add = 0;
if (i == 0) {
add += abs(kek1);
} else {
st.pb(mp(x[i] - x[i - 1], i));
}
if (i == n - 1) {
add += abs(kek);
} else {
st1.pb(mp(x[i + 1] - x[i], i));
}
val[i] = add;
}
sort(all(st));
sort(all(st1));
int uk = 0;
ll fk = 0;
for (auto x: st) {
while (uk < sz(ste)) {
ll val = ste[uk].first + ste[uk].second;
if (val <= x.first) {
chkmax(fk, ste[uk].first);
uk++;
} else {
break;
}
}
if (uk != sz(ste)) {
ll g = x.first - ste[uk].second;
ll fk1 = max(min(fk, x.first), g);
val[x.second] += fk1;
} else {
val[x.second] += min(fk, x.first);
}
}
uk = 0;
fk = 0;
for (auto x: st1) {
while (uk < sz(ste1)) {
ll val = ste1[uk].first + ste1[uk].second;
if (val <= x.first) {
chkmax(fk, ste1[uk].first);
uk++;
} else {
break;
}
}
if (uk != sz(ste1)) {
ll g = x.first - ste1[uk].second;
ll fk1 = max(min(fk, x.first), g);
val[x.second] += fk1;
} else {
val[x.second] += min(fk, x.first);
}
}
for (int i = 0; i < n; i++) {
cout << val[i] << '\n';
}
}
//21:50
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
// read(FILENAME);
int t;
t = 1;
// cin >> t;
while (t--) {
solve();
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |