# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
523322 |
2022-02-07T12:55:25 Z |
lucri |
Snowball (JOI21_ho_t2) |
C++17 |
|
208 ms |
6904 KB |
#include <iostream>
#include <cmath>
#define ll long long
#define int ll
using namespace std;
int n,q,x[200010],ans[200010],mp[200010],w,cnt,dmin,dmax;
int cb(int b,int e,int val)
{
while(b<=e)
{
int m=(b+e)/2;
if(abs(mp[m-1])+abs(mp[m])<val)
b=m+1;
else
e=m-1;
}
return b;
}
main()
{
cin>>n>>q;
for(int i=1;i<=n;++i)
{
cin>>x[i];
}
int dp=0;
for(int 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(int i=1;i<n;++i)
{
int 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(int i=1;i<=n;++i)
{
cout<<ans[i]<<'\n';
}
return 0;
}
Compilation message
Main.cpp:19:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
19 | main()
| ^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
332 KB |
Output is correct |
2 |
Correct |
2 ms |
312 KB |
Output is correct |
3 |
Correct |
2 ms |
332 KB |
Output is correct |
4 |
Correct |
3 ms |
332 KB |
Output is correct |
5 |
Correct |
3 ms |
308 KB |
Output is correct |
6 |
Correct |
3 ms |
348 KB |
Output is correct |
7 |
Correct |
2 ms |
332 KB |
Output is correct |
8 |
Correct |
3 ms |
332 KB |
Output is correct |
9 |
Correct |
2 ms |
316 KB |
Output is correct |
10 |
Correct |
2 ms |
332 KB |
Output is correct |
11 |
Correct |
2 ms |
304 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 |
204 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 |
204 KB |
Output is correct |
19 |
Correct |
2 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
332 KB |
Output is correct |
2 |
Correct |
2 ms |
312 KB |
Output is correct |
3 |
Correct |
2 ms |
332 KB |
Output is correct |
4 |
Correct |
3 ms |
332 KB |
Output is correct |
5 |
Correct |
3 ms |
308 KB |
Output is correct |
6 |
Correct |
3 ms |
348 KB |
Output is correct |
7 |
Correct |
2 ms |
332 KB |
Output is correct |
8 |
Correct |
3 ms |
332 KB |
Output is correct |
9 |
Correct |
2 ms |
316 KB |
Output is correct |
10 |
Correct |
2 ms |
332 KB |
Output is correct |
11 |
Correct |
2 ms |
304 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 |
204 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 |
204 KB |
Output is correct |
19 |
Correct |
2 ms |
332 KB |
Output is correct |
20 |
Correct |
103 ms |
2136 KB |
Output is correct |
21 |
Correct |
77 ms |
2108 KB |
Output is correct |
22 |
Correct |
70 ms |
2188 KB |
Output is correct |
23 |
Correct |
76 ms |
2192 KB |
Output is correct |
24 |
Correct |
89 ms |
2672 KB |
Output is correct |
25 |
Correct |
200 ms |
6852 KB |
Output is correct |
26 |
Correct |
206 ms |
6904 KB |
Output is correct |
27 |
Correct |
208 ms |
6620 KB |
Output is correct |
28 |
Correct |
194 ms |
6596 KB |
Output is correct |
29 |
Correct |
197 ms |
6148 KB |
Output is correct |
30 |
Correct |
170 ms |
5328 KB |
Output is correct |
31 |
Correct |
136 ms |
4900 KB |
Output is correct |
32 |
Correct |
143 ms |
4916 KB |
Output is correct |
33 |
Incorrect |
23 ms |
1172 KB |
Output isn't correct |
34 |
Halted |
0 ms |
0 KB |
- |