#include <iostream>
#include <cmath>
using namespace std;
long long n,q,x[2000010],ans[2000010],mp[2000010],w,cnt,dmin,dmax;
long long cb(long long b,long long e,long long val)
{
while(b<=e)
{
long long m=(b+e)/2;
if(abs(mp[m-1])+abs(mp[m])<val)
b=m+1;
else
e=m-1;
}
return b;
}
int main()
{
cin>>n>>q;
for(long long i=1;i<=n;++i)
{
cin>>x[i];
}
long long dp=0;
for(long long i=1;i<=q;++i)
{
cin>>w;
dp+=w;
if(dp<0)
{
if(mp[cnt]<0)
{
if(dp<mp[cnt])
mp[cnt]=dp;
}
else
{
if(dp<dmin)
{
mp[++cnt]=dp;
dmin=dp;
}
}
}
else if(dp>0)
{
if(mp[cnt]>0)
{
if(dp>mp[cnt])
mp[cnt]=dp;
}
else
{
if(dp>dmax)
{
mp[++cnt]=dp;
dmax=dp;
}
}
}
}
if(mp[cnt]<0)
{
ans[1]-=mp[cnt];
ans[n]+=mp[cnt-1];
}
else
{
ans[1]-=mp[cnt-1];
ans[n]+=mp[cnt];
}
for(long long i=1;i<n;++i)
{
long long b=cb(1,cnt,x[i+1]-x[i]);
if(b>cnt)
{
if(mp[cnt]<0)
{
ans[i+1]-=mp[cnt];
ans[i]+=mp[cnt-1];
}
else
{
ans[i+1]-=mp[cnt-1];
ans[i]+=mp[cnt];
}
}
else
{
if(mp[b]<0)
{
ans[i]+=mp[b-1];
ans[i+1]+=x[i+1]-x[i]-mp[b-1];
}
else
{
ans[i+1]-=mp[b-1];
ans[i]+=x[i+1]-x[i]+mp[b-1];
}
}
}
for(long long i=1;i<=n;++i)
{
cout<<ans[i]<<'\n';
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
332 KB |
Output is correct |
2 |
Correct |
2 ms |
332 KB |
Output is correct |
3 |
Correct |
2 ms |
308 KB |
Output is correct |
4 |
Correct |
4 ms |
316 KB |
Output is correct |
5 |
Correct |
3 ms |
332 KB |
Output is correct |
6 |
Correct |
2 ms |
332 KB |
Output is correct |
7 |
Correct |
3 ms |
332 KB |
Output is correct |
8 |
Correct |
2 ms |
332 KB |
Output is correct |
9 |
Correct |
3 ms |
332 KB |
Output is correct |
10 |
Correct |
2 ms |
332 KB |
Output is correct |
11 |
Correct |
3 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
3 ms |
332 KB |
Output is correct |
16 |
Correct |
3 ms |
332 KB |
Output is correct |
17 |
Correct |
2 ms |
332 KB |
Output is correct |
18 |
Correct |
0 ms |
300 KB |
Output is correct |
19 |
Correct |
2 ms |
308 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
332 KB |
Output is correct |
2 |
Correct |
2 ms |
332 KB |
Output is correct |
3 |
Correct |
2 ms |
308 KB |
Output is correct |
4 |
Correct |
4 ms |
316 KB |
Output is correct |
5 |
Correct |
3 ms |
332 KB |
Output is correct |
6 |
Correct |
2 ms |
332 KB |
Output is correct |
7 |
Correct |
3 ms |
332 KB |
Output is correct |
8 |
Correct |
2 ms |
332 KB |
Output is correct |
9 |
Correct |
3 ms |
332 KB |
Output is correct |
10 |
Correct |
2 ms |
332 KB |
Output is correct |
11 |
Correct |
3 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
3 ms |
332 KB |
Output is correct |
16 |
Correct |
3 ms |
332 KB |
Output is correct |
17 |
Correct |
2 ms |
332 KB |
Output is correct |
18 |
Correct |
0 ms |
300 KB |
Output is correct |
19 |
Correct |
2 ms |
308 KB |
Output is correct |
20 |
Correct |
84 ms |
2200 KB |
Output is correct |
21 |
Correct |
79 ms |
2120 KB |
Output is correct |
22 |
Correct |
76 ms |
1820 KB |
Output is correct |
23 |
Correct |
71 ms |
1828 KB |
Output is correct |
24 |
Correct |
76 ms |
2268 KB |
Output is correct |
25 |
Correct |
195 ms |
7044 KB |
Output is correct |
26 |
Correct |
192 ms |
7012 KB |
Output is correct |
27 |
Correct |
183 ms |
6824 KB |
Output is correct |
28 |
Correct |
198 ms |
6724 KB |
Output is correct |
29 |
Correct |
187 ms |
5872 KB |
Output is correct |
30 |
Correct |
160 ms |
5132 KB |
Output is correct |
31 |
Correct |
141 ms |
4668 KB |
Output is correct |
32 |
Correct |
140 ms |
4696 KB |
Output is correct |
33 |
Incorrect |
20 ms |
1092 KB |
Output isn't correct |
34 |
Halted |
0 ms |
0 KB |
- |