# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
692603 |
2023-02-02T01:46:42 Z |
owoovo |
Snowball (JOI21_ho_t2) |
C++14 |
|
264 ms |
12712 KB |
#include<bits/stdc++.h>
#define ll long long
using namespace std;
pair<ll,ll> BITmax[200010],BITmin[200010];
ll ori[200010],ans[200010]={};
void modify(pair<ll,ll> x,ll p){
while(p<=200005){
if(BITmax[p].first<x.first){
BITmax[p]=x;
}
if(BITmin[p].first>x.first){
BITmin[p]=x;
}
p+=p&(-p);
}
return ;
}
pair<pair<ll,ll>,pair<ll,ll>> q(ll p){
pair<ll,ll> ansmax={0,0},ansmin={0,0};
while(p){
if(ansmax.first<BITmax[p].first){
ansmax=BITmax[p];
}
if(ansmin.first>BITmin[p].first){
ansmin=BITmin[p];
}
p-=p&(-p);
}
return make_pair(ansmax,ansmin);
}
int main(){
cin.tie(0);
ios::sync_with_stdio(0);
ll n,m;
cin>>n>>m;
for(ll i=1;i<=n;i++){
cin>>ori[i];
}
ll now=0;
for(ll i=1;i<=m;i++){
ll a;
cin>>a;
now+=a;
modify(make_pair(now,i),i);
}
ll l=q(200005).second.first,r=q(200005).first.first;
ans[1]+=abs(l);
ans[n]+=abs(r);
for(ll i=1;i<n;i++){
ll dis=ori[i+1]-ori[i];
if(ori[i+1]-ori[i]>=abs(l)+abs(r)){
ans[i]+=abs(r);
ans[i+1]+=abs(l);
}else{
ll L=0,R=200005;
while(L!=R){
ll M=(L+R)/2;
ll h=abs(q(M).first.first)+abs(q(M).second.first);
if(h<=dis){
L=M+1;
}else{
R=M;
}
}
pair<ll,ll> u=q(L).first,v=q(L).second;
if(u.second<v.second){
ans[i]+=u.first;
ans[i+1]+=dis-u.first;
}else{
ans[i+1]+=abs(v.first);
ans[i]+=dis-abs(v.first);
}
}
}
for(int i=1;i<=n;i++){
cout<<ans[i]<<"\n";
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
468 KB |
Output is correct |
2 |
Correct |
1 ms |
468 KB |
Output is correct |
3 |
Correct |
1 ms |
468 KB |
Output is correct |
4 |
Correct |
2 ms |
472 KB |
Output is correct |
5 |
Correct |
3 ms |
476 KB |
Output is correct |
6 |
Correct |
2 ms |
476 KB |
Output is correct |
7 |
Correct |
2 ms |
476 KB |
Output is correct |
8 |
Correct |
2 ms |
468 KB |
Output is correct |
9 |
Correct |
2 ms |
468 KB |
Output is correct |
10 |
Correct |
2 ms |
468 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
324 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
2 ms |
468 KB |
Output is correct |
16 |
Correct |
2 ms |
468 KB |
Output is correct |
17 |
Correct |
2 ms |
472 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
468 KB |
Output is correct |
2 |
Correct |
1 ms |
468 KB |
Output is correct |
3 |
Correct |
1 ms |
468 KB |
Output is correct |
4 |
Correct |
2 ms |
472 KB |
Output is correct |
5 |
Correct |
3 ms |
476 KB |
Output is correct |
6 |
Correct |
2 ms |
476 KB |
Output is correct |
7 |
Correct |
2 ms |
476 KB |
Output is correct |
8 |
Correct |
2 ms |
468 KB |
Output is correct |
9 |
Correct |
2 ms |
468 KB |
Output is correct |
10 |
Correct |
2 ms |
468 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
324 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
2 ms |
468 KB |
Output is correct |
16 |
Correct |
2 ms |
468 KB |
Output is correct |
17 |
Correct |
2 ms |
472 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
344 KB |
Output is correct |
20 |
Correct |
35 ms |
7840 KB |
Output is correct |
21 |
Correct |
45 ms |
7872 KB |
Output is correct |
22 |
Correct |
40 ms |
7868 KB |
Output is correct |
23 |
Correct |
31 ms |
7968 KB |
Output is correct |
24 |
Correct |
48 ms |
8316 KB |
Output is correct |
25 |
Correct |
264 ms |
12616 KB |
Output is correct |
26 |
Correct |
215 ms |
12540 KB |
Output is correct |
27 |
Correct |
233 ms |
12348 KB |
Output is correct |
28 |
Correct |
222 ms |
12324 KB |
Output is correct |
29 |
Correct |
226 ms |
12244 KB |
Output is correct |
30 |
Correct |
197 ms |
11824 KB |
Output is correct |
31 |
Correct |
157 ms |
10304 KB |
Output is correct |
32 |
Correct |
63 ms |
6704 KB |
Output is correct |
33 |
Correct |
17 ms |
1868 KB |
Output is correct |
34 |
Correct |
210 ms |
12648 KB |
Output is correct |
35 |
Correct |
254 ms |
12416 KB |
Output is correct |
36 |
Correct |
231 ms |
12648 KB |
Output is correct |
37 |
Correct |
223 ms |
12392 KB |
Output is correct |
38 |
Correct |
212 ms |
12580 KB |
Output is correct |
39 |
Correct |
197 ms |
12384 KB |
Output is correct |
40 |
Correct |
154 ms |
12364 KB |
Output is correct |
41 |
Correct |
41 ms |
4792 KB |
Output is correct |
42 |
Correct |
58 ms |
5176 KB |
Output is correct |
43 |
Correct |
118 ms |
12596 KB |
Output is correct |
44 |
Correct |
39 ms |
7908 KB |
Output is correct |
45 |
Correct |
63 ms |
12432 KB |
Output is correct |
46 |
Correct |
112 ms |
12712 KB |
Output is correct |
47 |
Correct |
105 ms |
9676 KB |
Output is correct |
48 |
Correct |
113 ms |
9636 KB |
Output is correct |