#pragma GCC optmize ("O3,unroll-loops")
#include <bits/stdc++.h>
using namespace std;
#define spIO ios::sync_with_stdio(false);cin.tie(0)
#define mem(x,va) memset(x,va,sizeof(x))
#define for0(i,n) for(int i=0;i<n;i++)
#define for1(i,n) for(int i=1;i<=n;i++)
typedef long long ll;
typedef long double ld;
const ll mod = 1e9 + 7;
inline ll inv(ll x, ll MOD = mod)
{
ll power = MOD - 2, ret = 1;
while (power)
{
if (power & 1)
(ret *= x) %= MOD;
power >>= 1;
(x *= x) %= MOD;
}
return ret;
}
inline ll gcd(ll x, ll y)
{
if (y == 0) return x;
return gcd(y, x % y);
}
ll pow2(ll target, ll p)
{
ll ret = 1;
while (p)
{
if (p & 1)
(ret *= target) %= mod;
p >>= 1;
(target *= target) %= mod;
}
return ret;
}
ll n, q;
ll x[200000 + 5], w[200000 + 5], r[200000 + 5], l[200000 + 5], ans[200000 + 5];
ll bs(ll tar)
{
int left = 0, right = q + 1, mid;
while (left != right)
{
mid = (left + right) / 2;
if (r[mid] + l[mid] <= tar)
left = mid + 1;
else
right = mid;
}
return left;
}
int main()
{
spIO;
cin >> n >> q;
for1(i, n) cin >> x[i];
for1(i, q) cin >> w[i];
ll ip = 0;
l[0] = r[0] = 0;
for1(i, q)
{
ip += w[i];
r[i] = max(r[i - 1], ip);
l[i] = max(l[i - 1], -ip);
}
ans[1] += l[q];
for (int i = 2; i <= n; i++)
{
if (l[q] + r[q] <= x[i] - x[i - 1])
{
ans[i - 1] += r[q];
ans[i] += l[q];
}
else
{
ll t = bs(x[i] - x[i - 1]);
if (r[t] - r[t - 1] > 0)
{
ans[i - 1] += x[i] - x[i - 1] - l[t];
ans[i] += l[t];
}
else
{
ans[i] += x[i] - x[i - 1] - r[t];
ans[i - 1] += r[t];
}
}
//cout << i - 1 << ' ' << i << ' ' << ans[i - 1] << ' ' << ans[i] << '\n';
}
ans[n] += r[q];
for1(i, n) cout << ans[i] << ' '; cout << '\n';
}
/*
*/
Compilation message
Main.cpp:1: warning: ignoring '#pragma GCC optmize' [-Wunknown-pragmas]
1 | #pragma GCC optmize ("O3,unroll-loops")
|
Main.cpp: In function 'int main()':
Main.cpp:7:19: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
7 | #define for1(i,n) for(int i=1;i<=n;i++)
| ^~~
Main.cpp:98:2: note: in expansion of macro 'for1'
98 | for1(i, n) cout << ans[i] << ' '; cout << '\n';
| ^~~~
Main.cpp:98:36: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
98 | for1(i, n) cout << ans[i] << ' '; cout << '\n';
| ^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
2 ms |
460 KB |
Output is correct |
5 |
Correct |
2 ms |
372 KB |
Output is correct |
6 |
Correct |
2 ms |
460 KB |
Output is correct |
7 |
Correct |
2 ms |
460 KB |
Output is correct |
8 |
Correct |
1 ms |
460 KB |
Output is correct |
9 |
Correct |
1 ms |
460 KB |
Output is correct |
10 |
Correct |
1 ms |
452 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
2 ms |
384 KB |
Output is correct |
16 |
Correct |
2 ms |
384 KB |
Output is correct |
17 |
Correct |
1 ms |
464 KB |
Output is correct |
18 |
Correct |
0 ms |
332 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
2 ms |
460 KB |
Output is correct |
5 |
Correct |
2 ms |
372 KB |
Output is correct |
6 |
Correct |
2 ms |
460 KB |
Output is correct |
7 |
Correct |
2 ms |
460 KB |
Output is correct |
8 |
Correct |
1 ms |
460 KB |
Output is correct |
9 |
Correct |
1 ms |
460 KB |
Output is correct |
10 |
Correct |
1 ms |
452 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
2 ms |
384 KB |
Output is correct |
16 |
Correct |
2 ms |
384 KB |
Output is correct |
17 |
Correct |
1 ms |
464 KB |
Output is correct |
18 |
Correct |
0 ms |
332 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
32 ms |
7104 KB |
Output is correct |
21 |
Correct |
33 ms |
6916 KB |
Output is correct |
22 |
Correct |
31 ms |
6672 KB |
Output is correct |
23 |
Correct |
29 ms |
6536 KB |
Output is correct |
24 |
Correct |
36 ms |
7108 KB |
Output is correct |
25 |
Correct |
120 ms |
13344 KB |
Output is correct |
26 |
Correct |
117 ms |
13292 KB |
Output is correct |
27 |
Correct |
120 ms |
12952 KB |
Output is correct |
28 |
Correct |
116 ms |
13092 KB |
Output is correct |
29 |
Correct |
115 ms |
12688 KB |
Output is correct |
30 |
Correct |
116 ms |
12056 KB |
Output is correct |
31 |
Correct |
77 ms |
11472 KB |
Output is correct |
32 |
Correct |
67 ms |
11628 KB |
Output is correct |
33 |
Correct |
12 ms |
1612 KB |
Output is correct |
34 |
Correct |
120 ms |
13688 KB |
Output is correct |
35 |
Correct |
137 ms |
13152 KB |
Output is correct |
36 |
Correct |
122 ms |
13380 KB |
Output is correct |
37 |
Correct |
117 ms |
13104 KB |
Output is correct |
38 |
Correct |
116 ms |
13000 KB |
Output is correct |
39 |
Correct |
114 ms |
13188 KB |
Output is correct |
40 |
Correct |
87 ms |
13128 KB |
Output is correct |
41 |
Correct |
37 ms |
7620 KB |
Output is correct |
42 |
Correct |
65 ms |
11588 KB |
Output is correct |
43 |
Correct |
94 ms |
14912 KB |
Output is correct |
44 |
Correct |
36 ms |
7524 KB |
Output is correct |
45 |
Correct |
74 ms |
13064 KB |
Output is correct |
46 |
Correct |
95 ms |
15044 KB |
Output is correct |
47 |
Correct |
99 ms |
15216 KB |
Output is correct |
48 |
Correct |
95 ms |
15300 KB |
Output is correct |