#include <bits/stdc++.h>
using namespace std;
#define int long long
signed main() {
int n, q;
cin >> n >> q;
vector<int> a(n + 2);
a[0] = -1e18, a[n + 1] = 1e18;
for (int i = 1; i <= n; i++)
cin >> a[i];
int mn = 0, mx = 0;
int cur = 0;
int x;
map<int, int> mp;
mp[0] = 0;
for (int i = 1; i <= q; i++) {
cin >> x;
cur += x;
if (cur < mn) {
mp[cur] = i;
mn = cur;
}
if (cur > mx) {
mp[cur] = i;
mx = cur;
}
}
for (int i = 1; i <= n; i++) {
int left = a[i], right = a[i];
{
int l = a[i - 1], r = a[i];
while (r - l > 1) {
int mid = (l + r) / 2;
int x = mid - a[i];
int y = mid - a[i - 1];
auto it1 = mp.upper_bound(x);
if (it1 == mp.begin()) {
l = mid;
continue;
}
--it1;
auto it2 = mp.lower_bound(y);
if (it2 == mp.end()) {
r = mid;
continue;
}
if ((it1 -> second) < (it2 -> second))
r = mid;
else
l = mid;
}
auto it1 = mp.upper_bound(r - 1 - a[i]);
auto it2 = mp.lower_bound(r - a[i - 1]);
if ((it1 != mp.begin()) && ((it2 == mp.end()) ||((--it1) -> second < it2 -> second)))
r--;
left = r;
}
{
int l = a[i], r = a[i + 1];
while (r - l > 1) {
int mid = (l + r) / 2;
int x = mid - a[i];
int y = mid - a[i + 1];
auto it1 = mp.lower_bound(x);
if (it1 == mp.end()) {
r = mid;
continue;
}
auto it2 = mp.upper_bound(y);
if (it2 == mp.begin()) {
l = mid;
continue;
}
--it2;
if ((it1 -> second) < (it2 -> second))
l = mid;
else
r = mid;
}
auto it1 = mp.lower_bound(l + 1 - a[i]);
auto it2 = mp.upper_bound(l - a[i + 1]);
if ((it1 != mp.end()) && ((it2 == mp.begin() || (it1 -> second < (--it2) -> second))))
l++;
right = l;
}
cout << right - left << endl;
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
2 ms |
476 KB |
Output is correct |
4 |
Correct |
10 ms |
604 KB |
Output is correct |
5 |
Correct |
9 ms |
636 KB |
Output is correct |
6 |
Correct |
9 ms |
620 KB |
Output is correct |
7 |
Correct |
8 ms |
604 KB |
Output is correct |
8 |
Correct |
8 ms |
592 KB |
Output is correct |
9 |
Correct |
7 ms |
348 KB |
Output is correct |
10 |
Correct |
3 ms |
348 KB |
Output is correct |
11 |
Correct |
3 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
344 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
11 ms |
604 KB |
Output is correct |
16 |
Correct |
10 ms |
604 KB |
Output is correct |
17 |
Correct |
6 ms |
600 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
3 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
2 ms |
476 KB |
Output is correct |
4 |
Correct |
10 ms |
604 KB |
Output is correct |
5 |
Correct |
9 ms |
636 KB |
Output is correct |
6 |
Correct |
9 ms |
620 KB |
Output is correct |
7 |
Correct |
8 ms |
604 KB |
Output is correct |
8 |
Correct |
8 ms |
592 KB |
Output is correct |
9 |
Correct |
7 ms |
348 KB |
Output is correct |
10 |
Correct |
3 ms |
348 KB |
Output is correct |
11 |
Correct |
3 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
344 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
11 ms |
604 KB |
Output is correct |
16 |
Correct |
10 ms |
604 KB |
Output is correct |
17 |
Correct |
6 ms |
600 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
3 ms |
348 KB |
Output is correct |
20 |
Correct |
77 ms |
14924 KB |
Output is correct |
21 |
Correct |
85 ms |
14844 KB |
Output is correct |
22 |
Correct |
78 ms |
14664 KB |
Output is correct |
23 |
Correct |
87 ms |
14420 KB |
Output is correct |
24 |
Correct |
282 ms |
14672 KB |
Output is correct |
25 |
Correct |
2347 ms |
19540 KB |
Output is correct |
26 |
Correct |
2309 ms |
19280 KB |
Output is correct |
27 |
Correct |
2202 ms |
18260 KB |
Output is correct |
28 |
Correct |
2079 ms |
17236 KB |
Output is correct |
29 |
Correct |
1737 ms |
11840 KB |
Output is correct |
30 |
Correct |
655 ms |
5948 KB |
Output is correct |
31 |
Correct |
298 ms |
5200 KB |
Output is correct |
32 |
Correct |
274 ms |
5456 KB |
Output is correct |
33 |
Correct |
141 ms |
1884 KB |
Output is correct |
34 |
Correct |
1121 ms |
7764 KB |
Output is correct |
35 |
Correct |
1365 ms |
8020 KB |
Output is correct |
36 |
Execution timed out |
2502 ms |
18892 KB |
Time limit exceeded |
37 |
Halted |
0 ms |
0 KB |
- |