#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define all(a) (a).begin(), (a).end()
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
using ld = long double;
template<typename T1, typename T2> bool chkmin(T1 &x, T2 y) { return y < x ? (x = y, true) : false; }
template<typename T1, typename T2> bool chkmax(T1 &x, T2 y) { return y > x ? (x = y, true) : false; }
void debug_out() { cerr << endl; }
template<typename T1, typename... T2> void debug_out(T1 A, T2... B) { cerr << ' ' << A; debug_out(B...); }
template<typename T> void mdebug_out(T* a, int n) { for (int i = 0; i < n; ++i) cerr << a[i] << ' '; cerr << endl; }
#ifdef DEBUG
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#define mdebug(a, n) cerr << #a << ": ", mdebug_out(a, n)
#else
#define debug(...) 1337
#define mdebug(a, n) 1337
#endif
template<typename T> ostream& operator << (ostream& stream, const vector<T> &v) { for (auto x : v) stream << x << ' '; return stream; }
template<typename T1, typename T2> ostream& operator << (ostream& stream, const pair<T1, T2>& p) { return stream << p.first << ' ' << p.second; }
const int N = 200005;
ll X[N], D[N];
ll L[N], R[N];
ll ans[N];
signed main()
{
#ifdef DEBUG
freopen("in", "r", stdin);
#endif
ios::sync_with_stdio(0);
cin.tie(0);
int n, Q;
cin >> n >> Q;
for (int i = 1; i <= n; ++i)
{
cin >> X[i];
}
L[0] = R[0] = 0;
ll S = 0;
for (int j = 1; j <= Q; ++j)
{
cin >> D[j];
S += D[j];
L[j] = min(L[j - 1], S);
R[j] = max(R[j - 1], S);
}
ans[1] -= L[Q];
ans[n] += R[Q];
for (int i = 1; i + 1 <= n; ++i)
{
int ul = 0;
int ur = Q + 1;
while (ur - ul > 1)
{
int um = (ul + ur) >> 1;
if (X[i] + R[um] >= X[i + 1] + L[um])
ur = um;
else
ul = um;
}
if (ur == Q + 1)
{
ans[i] += R[Q];
ans[i + 1] -= L[Q];
continue;
}
if (L[ul] == L[ur])
{
ans[i] += X[i + 1] - X[i] + L[ul];
ans[i + 1] -= L[ul];
}
else
{
ans[i] += R[ul];
ans[i + 1] += X[i + 1] - X[i] - R[ul];
}
}
for (int i = 1; i <= n; ++i)
cout << ans[i] << '\n';
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
492 KB |
Output is correct |
2 |
Correct |
1 ms |
492 KB |
Output is correct |
3 |
Correct |
2 ms |
492 KB |
Output is correct |
4 |
Correct |
2 ms |
492 KB |
Output is correct |
5 |
Correct |
2 ms |
492 KB |
Output is correct |
6 |
Correct |
2 ms |
492 KB |
Output is correct |
7 |
Correct |
2 ms |
492 KB |
Output is correct |
8 |
Correct |
2 ms |
492 KB |
Output is correct |
9 |
Correct |
2 ms |
492 KB |
Output is correct |
10 |
Correct |
2 ms |
492 KB |
Output is correct |
11 |
Correct |
2 ms |
492 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
2 ms |
492 KB |
Output is correct |
16 |
Correct |
2 ms |
492 KB |
Output is correct |
17 |
Correct |
2 ms |
492 KB |
Output is correct |
18 |
Correct |
2 ms |
364 KB |
Output is correct |
19 |
Correct |
2 ms |
492 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
492 KB |
Output is correct |
2 |
Correct |
1 ms |
492 KB |
Output is correct |
3 |
Correct |
2 ms |
492 KB |
Output is correct |
4 |
Correct |
2 ms |
492 KB |
Output is correct |
5 |
Correct |
2 ms |
492 KB |
Output is correct |
6 |
Correct |
2 ms |
492 KB |
Output is correct |
7 |
Correct |
2 ms |
492 KB |
Output is correct |
8 |
Correct |
2 ms |
492 KB |
Output is correct |
9 |
Correct |
2 ms |
492 KB |
Output is correct |
10 |
Correct |
2 ms |
492 KB |
Output is correct |
11 |
Correct |
2 ms |
492 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
2 ms |
492 KB |
Output is correct |
16 |
Correct |
2 ms |
492 KB |
Output is correct |
17 |
Correct |
2 ms |
492 KB |
Output is correct |
18 |
Correct |
2 ms |
364 KB |
Output is correct |
19 |
Correct |
2 ms |
492 KB |
Output is correct |
20 |
Correct |
33 ms |
7148 KB |
Output is correct |
21 |
Correct |
31 ms |
7020 KB |
Output is correct |
22 |
Correct |
30 ms |
6764 KB |
Output is correct |
23 |
Correct |
29 ms |
6636 KB |
Output is correct |
24 |
Correct |
36 ms |
7148 KB |
Output is correct |
25 |
Correct |
148 ms |
13568 KB |
Output is correct |
26 |
Correct |
128 ms |
13448 KB |
Output is correct |
27 |
Correct |
135 ms |
13292 KB |
Output is correct |
28 |
Correct |
136 ms |
13292 KB |
Output is correct |
29 |
Correct |
119 ms |
12780 KB |
Output is correct |
30 |
Correct |
108 ms |
12148 KB |
Output is correct |
31 |
Correct |
89 ms |
11628 KB |
Output is correct |
32 |
Correct |
87 ms |
11756 KB |
Output is correct |
33 |
Correct |
13 ms |
1772 KB |
Output is correct |
34 |
Correct |
131 ms |
13804 KB |
Output is correct |
35 |
Correct |
124 ms |
13292 KB |
Output is correct |
36 |
Correct |
126 ms |
13676 KB |
Output is correct |
37 |
Correct |
133 ms |
13292 KB |
Output is correct |
38 |
Correct |
131 ms |
13152 KB |
Output is correct |
39 |
Correct |
124 ms |
13292 KB |
Output is correct |
40 |
Correct |
105 ms |
13276 KB |
Output is correct |
41 |
Correct |
45 ms |
7792 KB |
Output is correct |
42 |
Correct |
94 ms |
11756 KB |
Output is correct |
43 |
Correct |
102 ms |
15084 KB |
Output is correct |
44 |
Correct |
35 ms |
7788 KB |
Output is correct |
45 |
Correct |
95 ms |
13288 KB |
Output is correct |
46 |
Correct |
113 ms |
15096 KB |
Output is correct |
47 |
Correct |
108 ms |
15448 KB |
Output is correct |
48 |
Correct |
108 ms |
15644 KB |
Output is correct |