#include <bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define FOR(i, l, r, d) for(int i=(l); i<=(r); i+=(d))
#define szof(x) ((int)(x).size())
#define vi vector<int>
#define pii pair<int, int>
#define F first
#define S second
#define pb push_back
#define eb emplace_back
#define mkp make_pair
const int INF = INT_MAX;
const int LNF = INF*INF;
const int MOD = 1000000007;
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
const int MAX = 200010;
int n, q;
int pos[MAX];
int dx[MAX];
int ev[MAX], evs;
int pref[MAX], lpref[MAX], rpref[MAX];
int res[MAX];
int search(int len){
int L = 1, R = evs, mid;
while(L < R){
mid = (L + R) / 2;
if(pref[mid] > len) R = mid;
else L = mid + 1;
}
return L;
}
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin>>n>>q;
FOR(i, 1, n, 1){
cin>>pos[i];
}
pos[0] = -LNF;
pos[n+1] = LNF;
int L = 0, R = 0, now = 0;
FOR(i, 1, q, 1){
cin>>dx[i];
now += dx[i];
if(now < L){
evs++;
ev[evs] = now - L;
L = now;
}
if(R < now){
evs++;
ev[evs] = now - R;
R = now;
}
}
FOR(i, 1, evs, 1){
lpref[i] = lpref[i-1];
rpref[i] = rpref[i-1];
if(ev[i] > 0){
// [--->......]
lpref[i] += ev[i];
}
else{
// [......<---]
rpref[i] += (-ev[i]);
}
pref[i] = lpref[i] + rpref[i];
}
FOR(i, 0, n, 1){
int len = pos[i+1] - pos[i];
if(len >= pref[evs]){
res[i] += lpref[evs];
res[i+1] += rpref[evs];
}
else{
int ptr = search(len);
res[i] += lpref[ptr - 1];
res[i+1] += rpref[ptr - 1];
if(ev[ptr] > 0) res[i] += len - pref[ptr - 1];
else res[i+1] += len - pref[ptr - 1];
}
}
FOR(i, 1, n, 1){
cout<<res[i]<<'\n';
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
468 KB |
Output is correct |
2 |
Correct |
1 ms |
468 KB |
Output is correct |
3 |
Correct |
1 ms |
468 KB |
Output is correct |
4 |
Correct |
1 ms |
468 KB |
Output is correct |
5 |
Correct |
2 ms |
512 KB |
Output is correct |
6 |
Correct |
1 ms |
508 KB |
Output is correct |
7 |
Correct |
1 ms |
508 KB |
Output is correct |
8 |
Correct |
1 ms |
468 KB |
Output is correct |
9 |
Correct |
2 ms |
472 KB |
Output is correct |
10 |
Correct |
1 ms |
344 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 |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
2 ms |
468 KB |
Output is correct |
16 |
Correct |
1 ms |
516 KB |
Output is correct |
17 |
Correct |
1 ms |
468 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
468 KB |
Output is correct |
2 |
Correct |
1 ms |
468 KB |
Output is correct |
3 |
Correct |
1 ms |
468 KB |
Output is correct |
4 |
Correct |
1 ms |
468 KB |
Output is correct |
5 |
Correct |
2 ms |
512 KB |
Output is correct |
6 |
Correct |
1 ms |
508 KB |
Output is correct |
7 |
Correct |
1 ms |
508 KB |
Output is correct |
8 |
Correct |
1 ms |
468 KB |
Output is correct |
9 |
Correct |
2 ms |
472 KB |
Output is correct |
10 |
Correct |
1 ms |
344 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 |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
2 ms |
468 KB |
Output is correct |
16 |
Correct |
1 ms |
516 KB |
Output is correct |
17 |
Correct |
1 ms |
468 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
344 KB |
Output is correct |
20 |
Correct |
34 ms |
10212 KB |
Output is correct |
21 |
Correct |
31 ms |
10068 KB |
Output is correct |
22 |
Correct |
28 ms |
9872 KB |
Output is correct |
23 |
Correct |
25 ms |
9744 KB |
Output is correct |
24 |
Correct |
30 ms |
10176 KB |
Output is correct |
25 |
Correct |
110 ms |
16536 KB |
Output is correct |
26 |
Correct |
94 ms |
16368 KB |
Output is correct |
27 |
Correct |
94 ms |
15528 KB |
Output is correct |
28 |
Correct |
131 ms |
15224 KB |
Output is correct |
29 |
Correct |
95 ms |
12204 KB |
Output is correct |
30 |
Correct |
68 ms |
8968 KB |
Output is correct |
31 |
Correct |
55 ms |
8352 KB |
Output is correct |
32 |
Correct |
70 ms |
8560 KB |
Output is correct |
33 |
Correct |
12 ms |
1876 KB |
Output is correct |
34 |
Correct |
77 ms |
10840 KB |
Output is correct |
35 |
Correct |
93 ms |
10568 KB |
Output is correct |
36 |
Correct |
106 ms |
16160 KB |
Output is correct |
37 |
Correct |
96 ms |
14452 KB |
Output is correct |
38 |
Correct |
99 ms |
15564 KB |
Output is correct |
39 |
Correct |
114 ms |
15804 KB |
Output is correct |
40 |
Correct |
72 ms |
15816 KB |
Output is correct |
41 |
Correct |
32 ms |
10812 KB |
Output is correct |
42 |
Correct |
70 ms |
8448 KB |
Output is correct |
43 |
Correct |
81 ms |
18060 KB |
Output is correct |
44 |
Correct |
34 ms |
10684 KB |
Output is correct |
45 |
Correct |
67 ms |
15732 KB |
Output is correct |
46 |
Correct |
78 ms |
18136 KB |
Output is correct |
47 |
Correct |
79 ms |
14336 KB |
Output is correct |
48 |
Correct |
79 ms |
18516 KB |
Output is correct |