#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 |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
408 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
0 ms |
204 KB |
Output is correct |
13 |
Correct |
0 ms |
204 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
1 ms |
332 KB |
Output is correct |
18 |
Correct |
0 ms |
332 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
408 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
0 ms |
204 KB |
Output is correct |
13 |
Correct |
0 ms |
204 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
1 ms |
332 KB |
Output is correct |
18 |
Correct |
0 ms |
332 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
24 ms |
204 KB |
Output is correct |
21 |
Correct |
22 ms |
332 KB |
Output is correct |
22 |
Correct |
23 ms |
344 KB |
Output is correct |
23 |
Correct |
20 ms |
528 KB |
Output is correct |
24 |
Correct |
29 ms |
1216 KB |
Output is correct |
25 |
Correct |
76 ms |
8284 KB |
Output is correct |
26 |
Correct |
78 ms |
8244 KB |
Output is correct |
27 |
Correct |
75 ms |
8092 KB |
Output is correct |
28 |
Correct |
76 ms |
8040 KB |
Output is correct |
29 |
Correct |
77 ms |
7864 KB |
Output is correct |
30 |
Correct |
72 ms |
7456 KB |
Output is correct |
31 |
Correct |
68 ms |
7092 KB |
Output is correct |
32 |
Correct |
53 ms |
7088 KB |
Output is correct |
33 |
Correct |
8 ms |
1228 KB |
Output is correct |
34 |
Correct |
86 ms |
8540 KB |
Output is correct |
35 |
Correct |
73 ms |
8080 KB |
Output is correct |
36 |
Correct |
76 ms |
8244 KB |
Output is correct |
37 |
Correct |
76 ms |
8108 KB |
Output is correct |
38 |
Correct |
76 ms |
8008 KB |
Output is correct |
39 |
Correct |
78 ms |
8116 KB |
Output is correct |
40 |
Correct |
75 ms |
8096 KB |
Output is correct |
41 |
Correct |
25 ms |
328 KB |
Output is correct |
42 |
Correct |
64 ms |
7008 KB |
Output is correct |
43 |
Correct |
88 ms |
8248 KB |
Output is correct |
44 |
Correct |
26 ms |
332 KB |
Output is correct |
45 |
Correct |
72 ms |
8092 KB |
Output is correct |
46 |
Correct |
76 ms |
8352 KB |
Output is correct |
47 |
Correct |
77 ms |
8348 KB |
Output is correct |
48 |
Correct |
78 ms |
8396 KB |
Output is correct |