//Make CSP great again
//Vengeance
#include <bits/stdc++.h>
#define TASK "TESTCODE"
#define Log2(x) 31 - __builtin_clz(x)
using namespace std;
const int N = 2e5;
const long long oo = 1e18 + 10;
long long x[N + 1], l[N + 1], r[N + 1], cur, MaxLeft = 0, MaxRight = 0;
int n, q, id[N + 1];
void read()
{
cin >> n >> q;
for (int i = 1; i <= n; ++ i)
{
cin >> x[i];
id[i] = i;
l[i] = -oo;
r[i] = oo;
}
sort(id + 1, id + n, [&](const int &a, const int &b)
{
return x[a + 1] - x[a] < x[b + 1] - x[b];
});
}
void solve()
{
int i = 1;
while(q--)
{
long long w;
cin >> w;
cur += w;
MaxRight = max(MaxRight, cur);
MaxLeft = min(MaxLeft, cur);
for (; i < n && x[id[i] + 1] - x[id[i]] <= MaxRight - MaxLeft; ++ i)
{
int j = id[i];
if (w > 0)
{
r[j] = x[j + 1] + MaxLeft - 1;
l[j + 1] = x[j + 1] + MaxLeft;
}
else
{
l[j + 1] = x[j] + MaxRight;
r[j] = x[j] + MaxRight - 1;
}
}
}
for (int i = 1; i <= n; ++ i)
{
//cerr << l[i] << ' ' << r[i] << '\n';
long long L = (l[i] == -oo ? x[i] + MaxLeft : l[i]), R = (r[i] == oo ? x[i] + MaxRight - 1 : r[i]);
//cerr << L << ' ' << R << '\n';
cout << R - L + 1 << '\n';
}
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
if (fopen(TASK".INP", "r"))
{
freopen(TASK".INP", "r", stdin);
//freopen(TASK".OUT", "w", stdout);
}
int t = 1;
bool typetest = false;
if (typetest)
{
cin >> t;
}
for (int __ = 1; __ <= t; ++ __)
{
//cout << "Case " << __ << ": ";
read();
solve();
}
}
Compilation message
Main.cpp: In function 'int main()':
Main.cpp:65:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
65 | freopen(TASK".INP", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
412 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
2 ms |
412 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
428 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
2 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
328 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
468 KB |
Output is correct |
16 |
Correct |
1 ms |
468 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
412 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
2 ms |
412 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
428 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
2 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
328 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
468 KB |
Output is correct |
16 |
Correct |
1 ms |
468 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
26 ms |
2384 KB |
Output is correct |
21 |
Correct |
25 ms |
2252 KB |
Output is correct |
22 |
Correct |
24 ms |
1992 KB |
Output is correct |
23 |
Correct |
23 ms |
2000 KB |
Output is correct |
24 |
Correct |
26 ms |
2668 KB |
Output is correct |
25 |
Correct |
98 ms |
11092 KB |
Output is correct |
26 |
Correct |
91 ms |
11036 KB |
Output is correct |
27 |
Correct |
89 ms |
10684 KB |
Output is correct |
28 |
Correct |
87 ms |
10840 KB |
Output is correct |
29 |
Correct |
102 ms |
10316 KB |
Output is correct |
30 |
Correct |
71 ms |
9740 KB |
Output is correct |
31 |
Correct |
66 ms |
9072 KB |
Output is correct |
32 |
Correct |
61 ms |
9232 KB |
Output is correct |
33 |
Correct |
10 ms |
1468 KB |
Output is correct |
34 |
Correct |
84 ms |
11420 KB |
Output is correct |
35 |
Correct |
85 ms |
10764 KB |
Output is correct |
36 |
Correct |
94 ms |
11092 KB |
Output is correct |
37 |
Correct |
88 ms |
10764 KB |
Output is correct |
38 |
Correct |
84 ms |
10700 KB |
Output is correct |
39 |
Correct |
83 ms |
10836 KB |
Output is correct |
40 |
Correct |
72 ms |
10896 KB |
Output is correct |
41 |
Correct |
28 ms |
3012 KB |
Output is correct |
42 |
Correct |
73 ms |
9228 KB |
Output is correct |
43 |
Correct |
101 ms |
12536 KB |
Output is correct |
44 |
Correct |
29 ms |
2876 KB |
Output is correct |
45 |
Correct |
82 ms |
10776 KB |
Output is correct |
46 |
Correct |
87 ms |
12764 KB |
Output is correct |
47 |
Correct |
88 ms |
12916 KB |
Output is correct |
48 |
Correct |
86 ms |
13164 KB |
Output is correct |