#include<iostream>
#include<stdio.h>
#include<stdint.h>
#include<vector>
#include<algorithm>
#include<utility>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<deque>
#include<string>
#include<assert.h>
using namespace std;
const int64_t INF = (int64_t) 1e18 + 5;
const int64_t mINF = 1e6 + 1;
const int64_t MOD = (int64_t) 1e9 + 7;
const int nbit = 30;
const int ndig = 10;
const int nchar = 26;
const int p1 = 31;
const int p2 = 53;
const int D = 4;
int dr[D] = {0, 1, 0, -1};
int dc[D] = {1, 0, -1, 0};
// 0 right // 1 down // 2 left // 3 up
struct Thing
{
int64_t left;
int64_t right;
int64_t w;
Thing(int64_t left_, int64_t right_, int64_t w_) : left(left_), right(right_), w(w_) {}
};
struct Solution
{
int n;
int q;
vector<int64_t> a;
Solution() {}
void solve()
{
cin >> n >> q;
a.push_back(-INF);
for(int i = 0; i < n; i++)
{
int64_t val;
cin >> val;
a.push_back(val);
}
a.push_back(INF);
vector<int64_t> b;
for(int i = 1; i < (int) a.size(); i++)
{
b.push_back(a[i] - a[i - 1]);
}
int64_t left = 0;
int64_t right = 0;
int64_t sum = 0;
vector<Thing> v;
v.push_back(Thing(0, 0, INF));
for(int i = 0; i < q; i++)
{
int64_t w;
cin >> w;
sum += w;
v[i].w = w;
left = max(left, -sum);
right = max(right, sum);
v.push_back(Thing(left, right, INF));
}
int k = b.size();
vector<int64_t> ans(n, 0);
for(int i = 0; i < k; i++)
{
int64_t len = b[i];
int l = 0;
int r = q;
int id = -1;
while(l <= r)
{
int mid = l + (r - l) / 2;
int64_t tmp = v[mid].left + v[mid].right;
if(tmp < len)
{
id = mid;
l = mid + 1;
}
else r = mid - 1;
}
int64_t w = v[id].w;
int64_t x = v[id].left;
int64_t y = v[id].right;
if(w != INF)
{
int64_t re = len - (x + y);
if(w > 0) y += re;
else x += re;
}
if(i != 0) ans[i - 1] += y;
if(i != k - 1) ans[i] += x;
}
for(int i = 0; i < n; i++)
{
cout << ans[i] << "\n";
}
}
int modsub(int t1, int t2)
{
int res = t1 - t2;
if(res < 0) res += MOD;
return res;
}
int modadd(int t1, int t2)
{
int res = t1 + t2;
if(res >= MOD) res -= MOD;
return res;
}
int modmul(int t1, int t2)
{
int64_t res = 1LL * t1 * t2;
return (res % MOD);
}
bool BIT(int64_t& mask, int& j)
{
return (mask & MASK(j));
}
int64_t MASK(int j)
{
return (1LL << j);
}
};
void __startup()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
//
// freopen("in.txt", "r", stdin);
// freopen("out.txt", "w", stdout);
}
int main()
{
__startup();
int t = 1;
// cin >> t;
for(int i = 1; i <= t; i++)
{
Solution().solve();
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
328 KB |
Output is correct |
4 |
Correct |
2 ms |
468 KB |
Output is correct |
5 |
Correct |
1 ms |
468 KB |
Output is correct |
6 |
Correct |
1 ms |
460 KB |
Output is correct |
7 |
Correct |
1 ms |
464 KB |
Output is correct |
8 |
Correct |
1 ms |
468 KB |
Output is correct |
9 |
Correct |
1 ms |
468 KB |
Output is correct |
10 |
Correct |
2 ms |
404 KB |
Output is correct |
11 |
Correct |
1 ms |
468 KB |
Output is correct |
12 |
Correct |
0 ms |
324 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
324 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 |
468 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
460 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
328 KB |
Output is correct |
4 |
Correct |
2 ms |
468 KB |
Output is correct |
5 |
Correct |
1 ms |
468 KB |
Output is correct |
6 |
Correct |
1 ms |
460 KB |
Output is correct |
7 |
Correct |
1 ms |
464 KB |
Output is correct |
8 |
Correct |
1 ms |
468 KB |
Output is correct |
9 |
Correct |
1 ms |
468 KB |
Output is correct |
10 |
Correct |
2 ms |
404 KB |
Output is correct |
11 |
Correct |
1 ms |
468 KB |
Output is correct |
12 |
Correct |
0 ms |
324 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
324 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 |
468 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
460 KB |
Output is correct |
20 |
Correct |
30 ms |
8252 KB |
Output is correct |
21 |
Correct |
32 ms |
8120 KB |
Output is correct |
22 |
Correct |
35 ms |
7932 KB |
Output is correct |
23 |
Correct |
27 ms |
7808 KB |
Output is correct |
24 |
Correct |
41 ms |
8276 KB |
Output is correct |
25 |
Correct |
108 ms |
15112 KB |
Output is correct |
26 |
Correct |
99 ms |
14968 KB |
Output is correct |
27 |
Correct |
108 ms |
14652 KB |
Output is correct |
28 |
Correct |
115 ms |
14696 KB |
Output is correct |
29 |
Correct |
100 ms |
14372 KB |
Output is correct |
30 |
Correct |
119 ms |
14252 KB |
Output is correct |
31 |
Correct |
68 ms |
14112 KB |
Output is correct |
32 |
Correct |
65 ms |
14200 KB |
Output is correct |
33 |
Correct |
10 ms |
1872 KB |
Output is correct |
34 |
Correct |
104 ms |
15320 KB |
Output is correct |
35 |
Correct |
105 ms |
14752 KB |
Output is correct |
36 |
Correct |
105 ms |
15124 KB |
Output is correct |
37 |
Correct |
106 ms |
14788 KB |
Output is correct |
38 |
Correct |
108 ms |
14532 KB |
Output is correct |
39 |
Correct |
104 ms |
14732 KB |
Output is correct |
40 |
Correct |
77 ms |
14732 KB |
Output is correct |
41 |
Correct |
33 ms |
8628 KB |
Output is correct |
42 |
Correct |
60 ms |
14244 KB |
Output is correct |
43 |
Correct |
79 ms |
16564 KB |
Output is correct |
44 |
Correct |
34 ms |
8492 KB |
Output is correct |
45 |
Correct |
76 ms |
14740 KB |
Output is correct |
46 |
Correct |
84 ms |
16600 KB |
Output is correct |
47 |
Correct |
84 ms |
16868 KB |
Output is correct |
48 |
Correct |
84 ms |
16944 KB |
Output is correct |