#include <bits/stdc++.h>
using namespace std;
#define vi vector<int>
#define vll vector<long long>
#define pb push_back
using ll= long long;
#define fast_io ios::sync_with_stdio(0); cin.tie(0)
#define inpint(x) int x; cin>>x
#define inpll(x) long long x; cin>>x
#define fl(i, n) for(int i=0; i<n; i++)
#define flo(i, n) for(int i=1; i<=n; i++)
#define int long long
#define pi pair<int, int>
#define mp make_pair
#define ld long double
const int MODa = 7 + (int)1e9;
const int INF = (int)1e18;
const int MOD = 998244353;
void solve()
{
int n, q;
cin>>n>>q;
vector<int> x(n+1, 0);
for(int i=1; i<=n; i++)
{
cin>>x[i];
}
vector<int> w(q+1, 0);
vector<int> a(q+1, 0);
vector<int> ml(q+1, 0);
vector<int> mr(q+1, 0);
for(int i=1; i<=q; i++)
{
cin>>w[i];
a[i] = a[i-1] + w[i];
ml[i] = min(ml[i-1], a[i]);
mr[i] = max(mr[i-1], a[i]);
}
vector<int> ans(n+1, 0);
ans[1] -= ml[q];
ans[n] += mr[q];
for(int i=1; i<n; i++)
{
int j = i+1;
if(x[i]+mr[q]<=x[j]+ml[q])
{
ans[i] += mr[q];
ans[j] -= ml[q];
continue;
}
int high = q;
int low = 0;
//cerr<<i<<": \n";
while(high-low>1)
{
int mid = (high+low)/2;
if(x[i]+mr[mid]>x[j]+ml[mid]) high = mid;
else low = mid;
//cerr<<low<<" "<<high<<"\n";
}
//cerr<<"\n";
ans[i] += mr[low];
ans[j] -= ml[low];
if(w[low+1]<0)
{
ans[j] += x[j] - x[i] - mr[low] + ml[low];
}
else
{
ans[i] += x[j] - x[i] - mr[low] + ml[low];
}
}
for(int i=1; i<=n; i++)
{
cout<<ans[i]<<"\n";
}
}
signed main()
{
fast_io;
int t=1;
//cin>>t;
while(t--)
{
solve();
}
cout<<endl;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
460 KB |
Output is correct |
5 |
Correct |
1 ms |
464 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
460 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
372 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
316 KB |
Output is correct |
13 |
Correct |
1 ms |
316 KB |
Output is correct |
14 |
Correct |
0 ms |
324 KB |
Output is correct |
15 |
Correct |
1 ms |
376 KB |
Output is correct |
16 |
Correct |
1 ms |
376 KB |
Output is correct |
17 |
Correct |
1 ms |
468 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
340 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 |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
460 KB |
Output is correct |
5 |
Correct |
1 ms |
464 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
460 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
372 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
316 KB |
Output is correct |
13 |
Correct |
1 ms |
316 KB |
Output is correct |
14 |
Correct |
0 ms |
324 KB |
Output is correct |
15 |
Correct |
1 ms |
376 KB |
Output is correct |
16 |
Correct |
1 ms |
376 KB |
Output is correct |
17 |
Correct |
1 ms |
468 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
26 ms |
8652 KB |
Output is correct |
21 |
Correct |
26 ms |
8504 KB |
Output is correct |
22 |
Correct |
27 ms |
8232 KB |
Output is correct |
23 |
Correct |
25 ms |
8140 KB |
Output is correct |
24 |
Correct |
29 ms |
8652 KB |
Output is correct |
25 |
Correct |
112 ms |
14984 KB |
Output is correct |
26 |
Correct |
108 ms |
14916 KB |
Output is correct |
27 |
Correct |
104 ms |
14548 KB |
Output is correct |
28 |
Correct |
101 ms |
14800 KB |
Output is correct |
29 |
Correct |
115 ms |
14252 KB |
Output is correct |
30 |
Correct |
93 ms |
13640 KB |
Output is correct |
31 |
Correct |
71 ms |
13004 KB |
Output is correct |
32 |
Correct |
57 ms |
13260 KB |
Output is correct |
33 |
Correct |
9 ms |
1756 KB |
Output is correct |
34 |
Correct |
101 ms |
15320 KB |
Output is correct |
35 |
Correct |
104 ms |
14808 KB |
Output is correct |
36 |
Correct |
99 ms |
14936 KB |
Output is correct |
37 |
Correct |
122 ms |
14800 KB |
Output is correct |
38 |
Correct |
99 ms |
14644 KB |
Output is correct |
39 |
Correct |
98 ms |
14796 KB |
Output is correct |
40 |
Correct |
84 ms |
14788 KB |
Output is correct |
41 |
Correct |
29 ms |
9260 KB |
Output is correct |
42 |
Correct |
50 ms |
13144 KB |
Output is correct |
43 |
Correct |
84 ms |
16456 KB |
Output is correct |
44 |
Correct |
31 ms |
9140 KB |
Output is correct |
45 |
Correct |
58 ms |
14676 KB |
Output is correct |
46 |
Correct |
95 ms |
16588 KB |
Output is correct |
47 |
Correct |
88 ms |
16836 KB |
Output is correct |
48 |
Correct |
87 ms |
16972 KB |
Output is correct |