#include<bits/stdc++.h>
#include<random>
using namespace std;
template<typename T> void _do(T x){cerr<<x<<"\n";}
template<typename T,typename ...U> void _do(T x,U ...y){cerr<<x<<", ";_do(y...);}
#define dbg(...) cerr<<#__VA_ARGS__<<" = ";_do(__VA_ARGS__);
#define float double
#define ss(n) fixed<<setprecision(n)
#define ll long long
#define int ll
#define IO ios::sync_with_stdio(false);cin.tie(0);
#define ld long double
#define pb push_back
#define pii pair<int,int>
#define rep(i,a) for(int i=1;i<=a;i++)
#define rep0(i,a) for(int i=0;i<a;i++)
#define F first
#define S second
#define uni(a) a.resize(distance(a.begin(),unique(a.begin(),a.end())));
#define unisort(a) sort(a.begin(),a.end()); uni(a);
ll gcd(ll a,ll b){if(b==0) return a; return gcd(b,a%b);}
const ld pi=3.14159265358979323846264338327950288419716939931;
const int lar=3e18;
const int mol1=1e9+7;
const int mol2=998244353;
const int MX=2e5+5;
void solve()
{
int n,q;
cin>>n>>q;
int a[n+1];int ans[n+1]={0};
rep(i,n) cin>>a[i];
int now=0;
int mx[q+1]={0},mn[q+1]={0};
int xx=0,n1=0,n2=0;
rep(i,q){
int g;
cin>>g;
xx+=g;
n1=min(n1,xx);
n2=max(n2,xx);
mx[i]=max(mx[i],n2);
mn[i]=min(mn[i],n1);
}
rep(i,n){
if(i==1){
int hh=mn[q];ans[1]+=abs(hh);
}
else{
int l=0,r=q;int dif=a[i]-a[i-1];
while(l<r){
int mid=l+r+1>>1;
if((mx[mid]+abs(mn[mid]))>=dif){
r=mid-1;
}
else l=mid;
}
int bb=l;
int all=mx[bb]+abs(mn[bb]);
ans[i-1]+=mx[bb];ans[i]+=abs(mn[bb]);
if(bb!=q){
if(mx[bb+1]>mx[bb]){
ans[i-1]+=dif-all;
}
else ans[i]+=dif-all;
}
}
}
ans[n]+=mx[q];
rep(i,n) cout<<ans[i]<<"\n";
}
signed main()
{
IO
solve();
return 0;
}
Compilation message
Main.cpp: In function 'void solve()':
Main.cpp:58:28: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
58 | int mid=l+r+1>>1;
| ~~~^~
Main.cpp:39:9: warning: unused variable 'now' [-Wunused-variable]
39 | int now=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 |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 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 |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 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 |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 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 |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
26 ms |
3428 KB |
Output is correct |
21 |
Correct |
25 ms |
3412 KB |
Output is correct |
22 |
Correct |
25 ms |
3412 KB |
Output is correct |
23 |
Correct |
21 ms |
3480 KB |
Output is correct |
24 |
Correct |
27 ms |
3892 KB |
Output is correct |
25 |
Correct |
93 ms |
8220 KB |
Output is correct |
26 |
Correct |
93 ms |
11732 KB |
Output is correct |
27 |
Correct |
95 ms |
11404 KB |
Output is correct |
28 |
Correct |
94 ms |
11616 KB |
Output is correct |
29 |
Correct |
102 ms |
11092 KB |
Output is correct |
30 |
Correct |
88 ms |
10496 KB |
Output is correct |
31 |
Correct |
72 ms |
9940 KB |
Output is correct |
32 |
Correct |
57 ms |
10068 KB |
Output is correct |
33 |
Correct |
9 ms |
1472 KB |
Output is correct |
34 |
Correct |
105 ms |
12116 KB |
Output is correct |
35 |
Correct |
98 ms |
11524 KB |
Output is correct |
36 |
Correct |
94 ms |
11812 KB |
Output is correct |
37 |
Correct |
98 ms |
11536 KB |
Output is correct |
38 |
Correct |
89 ms |
11468 KB |
Output is correct |
39 |
Correct |
101 ms |
11548 KB |
Output is correct |
40 |
Correct |
73 ms |
11620 KB |
Output is correct |
41 |
Correct |
31 ms |
6104 KB |
Output is correct |
42 |
Correct |
56 ms |
10084 KB |
Output is correct |
43 |
Correct |
79 ms |
13312 KB |
Output is correct |
44 |
Correct |
31 ms |
5984 KB |
Output is correct |
45 |
Correct |
64 ms |
11528 KB |
Output is correct |
46 |
Correct |
91 ms |
13456 KB |
Output is correct |
47 |
Correct |
79 ms |
13664 KB |
Output is correct |
48 |
Correct |
88 ms |
13784 KB |
Output is correct |