# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
724922 |
2023-04-16T09:40:54 Z |
fdnfksd |
Snowball (JOI21_ho_t2) |
C++14 |
|
143 ms |
15300 KB |
#include<bits/stdc++.h>
#define TASKNAME "codeforce"
#define pb push_back
#define pli pair<int,int>
#define fi first
#define se second
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);
using namespace std;
using ll=long long;
const ll maxN=3e5;
const ll inf=1e18;
const ll mod=1e9+7;
ll n,m,x[maxN],mx[maxN],mn[maxN],pre[maxN],ans[maxN];
void solve()
{
cin >> n >> m;
for(int i=1;i<=n;i++) cin >> x[i];
mx[0]=mn[0]=0;
for(int i=1;i<=m;i++)
{
ll cc;
cin >> cc;
pre[i]=pre[i-1]+cc;
mx[i]=max(mx[i-1],pre[i]);
mn[i]=min(mn[i-1],pre[i]);
}
for(int i=1;i<n;i++)
{
ll low=0,high=m;
while(low<=high)
{
ll mid=low+high>>1;
if(x[i]+mx[mid]<=x[i+1]+mn[mid]) low=mid+1;
else high=mid-1;
}
if(high==m) ans[i]+=mx[high];
else
{
ans[i]+=max(mx[high],x[i+1]+mn[low]-x[i]);
}
}
for(int i=2;i<=n;i++)
{
ll low=0,high=m;
while(low<=high)
{
ll mid=low+high>>1;
if(x[i]+mn[mid]>=x[i-1]+mx[mid]) low=mid+1;
else high=mid-1;
}
if(high==m) ans[i]+=abs(mn[high]);
else
{
ans[i]+=max(abs(mn[high]),x[i]-(x[i-1]+mx[low]));
}
}
ans[1]+=abs(mn[m]);
ans[n]+=mx[m];
for(int i=1;i<=n;i++) cout << ans[i]<<'\n';
}
int main()
{
fastio
//freopen(TASKNAME".INP","r",stdin);
//freopen(TASKNAME".OUT","w",stdout);
solve();
}
Compilation message
Main.cpp: In function 'void solve()':
Main.cpp:32:23: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
32 | ll mid=low+high>>1;
| ~~~^~~~~
Main.cpp:47:23: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
47 | ll mid=low+high>>1;
| ~~~^~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
2 ms |
468 KB |
Output is correct |
5 |
Correct |
2 ms |
468 KB |
Output is correct |
6 |
Correct |
2 ms |
468 KB |
Output is correct |
7 |
Correct |
2 ms |
468 KB |
Output is correct |
8 |
Correct |
2 ms |
468 KB |
Output is correct |
9 |
Correct |
1 ms |
468 KB |
Output is correct |
10 |
Correct |
1 ms |
372 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 |
2 ms |
468 KB |
Output is correct |
17 |
Correct |
1 ms |
468 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
2 ms |
468 KB |
Output is correct |
5 |
Correct |
2 ms |
468 KB |
Output is correct |
6 |
Correct |
2 ms |
468 KB |
Output is correct |
7 |
Correct |
2 ms |
468 KB |
Output is correct |
8 |
Correct |
2 ms |
468 KB |
Output is correct |
9 |
Correct |
1 ms |
468 KB |
Output is correct |
10 |
Correct |
1 ms |
372 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 |
2 ms |
468 KB |
Output is correct |
17 |
Correct |
1 ms |
468 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
468 KB |
Output is correct |
20 |
Correct |
27 ms |
7104 KB |
Output is correct |
21 |
Correct |
27 ms |
6880 KB |
Output is correct |
22 |
Correct |
27 ms |
6684 KB |
Output is correct |
23 |
Correct |
23 ms |
6636 KB |
Output is correct |
24 |
Correct |
43 ms |
7084 KB |
Output is correct |
25 |
Correct |
129 ms |
13568 KB |
Output is correct |
26 |
Correct |
121 ms |
13376 KB |
Output is correct |
27 |
Correct |
125 ms |
12976 KB |
Output is correct |
28 |
Correct |
124 ms |
13124 KB |
Output is correct |
29 |
Correct |
119 ms |
12720 KB |
Output is correct |
30 |
Correct |
120 ms |
12028 KB |
Output is correct |
31 |
Correct |
70 ms |
11556 KB |
Output is correct |
32 |
Correct |
62 ms |
11608 KB |
Output is correct |
33 |
Correct |
12 ms |
1732 KB |
Output is correct |
34 |
Correct |
127 ms |
13712 KB |
Output is correct |
35 |
Correct |
132 ms |
13120 KB |
Output is correct |
36 |
Correct |
143 ms |
13408 KB |
Output is correct |
37 |
Correct |
123 ms |
13108 KB |
Output is correct |
38 |
Correct |
120 ms |
12948 KB |
Output is correct |
39 |
Correct |
121 ms |
13260 KB |
Output is correct |
40 |
Correct |
78 ms |
13204 KB |
Output is correct |
41 |
Correct |
30 ms |
7676 KB |
Output is correct |
42 |
Correct |
60 ms |
11640 KB |
Output is correct |
43 |
Correct |
82 ms |
14944 KB |
Output is correct |
44 |
Correct |
32 ms |
7616 KB |
Output is correct |
45 |
Correct |
68 ms |
13104 KB |
Output is correct |
46 |
Correct |
83 ms |
15068 KB |
Output is correct |
47 |
Correct |
80 ms |
15300 KB |
Output is correct |
48 |
Correct |
82 ms |
15296 KB |
Output is correct |