#include<bits/stdc++.h>
using namespace std;
#define int long long
#define pii pair<int,int>
#define ff first
#define ss second
#define all(x) x.begin(),x.end()
#define pb emplace_back
#define N 200010
int x[N],now,rmx,lmx,ans[N];
vector<pii> v;
signed main(){
ios::sync_with_stdio(0);
cin.tie(0);
int n,q,i,j,w;
cin>>n>>q;
x[0]=-1e18,x[n+1]=1e18;
for(i=1;i<=n+1;i++){
if(i<=n) cin>>x[i];
v.pb(x[i]-x[i-1],i-1);
}
sort(all(v));
i=0;
while(q--){
cin>>w;
now+=w;
rmx=max(now,rmx),lmx=min(now,lmx);
while(rmx-lmx>=v[i].ff){
if(w>0) ans[v[i].ss]+=v[i].ff+lmx,ans[v[i].ss+1]-=lmx;
else ans[v[i].ss]+=rmx,ans[v[i].ss+1]+=v[i].ff-rmx;
i++;
}
}
while(i<v.size()){
ans[v[i].ss]+=rmx,ans[v[i].ss+1]-=lmx;
i++;
}
for(i=1;i<=n;i++) cout<<ans[i]<<'\n';
}
Compilation message
Main.cpp: In function 'int main()':
Main.cpp:34:9: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
34 | while(i<v.size()){
| ~^~~~~~~~~
Main.cpp:15:12: warning: unused variable 'j' [-Wunused-variable]
15 | int n,q,i,j,w;
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 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 |
476 KB |
Output is correct |
5 |
Correct |
1 ms |
468 KB |
Output is correct |
6 |
Correct |
1 ms |
468 KB |
Output is correct |
7 |
Correct |
1 ms |
468 KB |
Output is correct |
8 |
Correct |
1 ms |
468 KB |
Output is correct |
9 |
Correct |
1 ms |
472 KB |
Output is correct |
10 |
Correct |
1 ms |
468 KB |
Output is correct |
11 |
Correct |
1 ms |
468 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 |
1 ms |
468 KB |
Output is correct |
16 |
Correct |
1 ms |
468 KB |
Output is correct |
17 |
Correct |
1 ms |
472 KB |
Output is correct |
18 |
Correct |
0 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
468 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 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 |
476 KB |
Output is correct |
5 |
Correct |
1 ms |
468 KB |
Output is correct |
6 |
Correct |
1 ms |
468 KB |
Output is correct |
7 |
Correct |
1 ms |
468 KB |
Output is correct |
8 |
Correct |
1 ms |
468 KB |
Output is correct |
9 |
Correct |
1 ms |
472 KB |
Output is correct |
10 |
Correct |
1 ms |
468 KB |
Output is correct |
11 |
Correct |
1 ms |
468 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 |
1 ms |
468 KB |
Output is correct |
16 |
Correct |
1 ms |
468 KB |
Output is correct |
17 |
Correct |
1 ms |
472 KB |
Output is correct |
18 |
Correct |
0 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
468 KB |
Output is correct |
20 |
Correct |
21 ms |
2384 KB |
Output is correct |
21 |
Correct |
17 ms |
2236 KB |
Output is correct |
22 |
Correct |
21 ms |
2004 KB |
Output is correct |
23 |
Correct |
16 ms |
1948 KB |
Output is correct |
24 |
Correct |
19 ms |
2892 KB |
Output is correct |
25 |
Correct |
61 ms |
11952 KB |
Output is correct |
26 |
Correct |
61 ms |
11964 KB |
Output is correct |
27 |
Correct |
61 ms |
11544 KB |
Output is correct |
28 |
Correct |
61 ms |
11688 KB |
Output is correct |
29 |
Correct |
69 ms |
11248 KB |
Output is correct |
30 |
Correct |
59 ms |
10576 KB |
Output is correct |
31 |
Correct |
55 ms |
10020 KB |
Output is correct |
32 |
Correct |
42 ms |
10256 KB |
Output is correct |
33 |
Correct |
7 ms |
1632 KB |
Output is correct |
34 |
Correct |
63 ms |
12360 KB |
Output is correct |
35 |
Correct |
65 ms |
11932 KB |
Output is correct |
36 |
Correct |
62 ms |
11964 KB |
Output is correct |
37 |
Correct |
63 ms |
11700 KB |
Output is correct |
38 |
Correct |
62 ms |
11572 KB |
Output is correct |
39 |
Correct |
70 ms |
11796 KB |
Output is correct |
40 |
Correct |
60 ms |
11728 KB |
Output is correct |
41 |
Correct |
19 ms |
3024 KB |
Output is correct |
42 |
Correct |
52 ms |
10152 KB |
Output is correct |
43 |
Correct |
67 ms |
13468 KB |
Output is correct |
44 |
Correct |
21 ms |
2868 KB |
Output is correct |
45 |
Correct |
59 ms |
11668 KB |
Output is correct |
46 |
Correct |
57 ms |
13620 KB |
Output is correct |
47 |
Correct |
59 ms |
13856 KB |
Output is correct |
48 |
Correct |
57 ms |
13920 KB |
Output is correct |