# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
377306 |
2021-03-13T19:24:45 Z |
YJU |
Snowball (JOI21_ho_t2) |
C++14 |
|
176 ms |
9836 KB |
#include<bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector,Ofast")
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;
const ll MOD=1e9+7;
const ll MOD2=998244353;
const ll N=2e5+5;
const ld pi=acos(-1);
const ll INF=(1LL<<60);
#define SQ(i) ((i)*(i))
#define REP(i,n) for(ll i=0;i<n;i++)
#define REP1(i,n) for(ll i=1;i<=n;i++)
#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define setp setprecision
#define lwb lower_bound
#define SZ(_a) (ll)_a.size()
ll n,q,u[N],loc,r[N],l[N],ans[N],x[N];
int main(){
ios_base::sync_with_stdio(0);cin.tie(0);
cin>>n>>q;
u[0]=-INF,u[n+1]=INF;
REP1(i,n)cin>>u[i];
REP1(i,q){
cin>>x[i];
loc+=x[i];
r[i]=max(r[i-1],loc);
l[i]=min(l[i-1],loc);
}
ll L,R;
REP1(i,n){
L=0,R=q+1;
while(R-L>1){
ll mid=(R+L)>>1;
if(u[i-1]+r[mid]<=u[i]+l[mid]){
L=mid;
}else{
R=mid;
}
}
if(i==1)ans[i]+=abs(l[L]);
else ans[i]+=abs(l[L])+(x[L+1]<0?u[i]+l[L]-u[i-1]-r[L]:0);
L=0,R=q+1;
while(R-L>1){
ll mid=(R+L)>>1;
if(u[i]+r[mid]<=u[i+1]+l[mid]){
L=mid;
}else{
R=mid;
}
}
if(i==n)ans[i]+=abs(r[L]);
else ans[i]+=abs(r[L])+(x[L+1]>0?u[i+1]+l[L]-u[i]-r[L]:0);
cout<<ans[i]<<"\n";
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
492 KB |
Output is correct |
5 |
Correct |
2 ms |
492 KB |
Output is correct |
6 |
Correct |
2 ms |
492 KB |
Output is correct |
7 |
Correct |
1 ms |
492 KB |
Output is correct |
8 |
Correct |
1 ms |
492 KB |
Output is correct |
9 |
Correct |
1 ms |
512 KB |
Output is correct |
10 |
Correct |
1 ms |
492 KB |
Output is correct |
11 |
Correct |
2 ms |
492 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
2 ms |
492 KB |
Output is correct |
16 |
Correct |
2 ms |
492 KB |
Output is correct |
17 |
Correct |
2 ms |
492 KB |
Output is correct |
18 |
Correct |
1 ms |
364 KB |
Output is correct |
19 |
Correct |
1 ms |
492 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
492 KB |
Output is correct |
5 |
Correct |
2 ms |
492 KB |
Output is correct |
6 |
Correct |
2 ms |
492 KB |
Output is correct |
7 |
Correct |
1 ms |
492 KB |
Output is correct |
8 |
Correct |
1 ms |
492 KB |
Output is correct |
9 |
Correct |
1 ms |
512 KB |
Output is correct |
10 |
Correct |
1 ms |
492 KB |
Output is correct |
11 |
Correct |
2 ms |
492 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
2 ms |
492 KB |
Output is correct |
16 |
Correct |
2 ms |
492 KB |
Output is correct |
17 |
Correct |
2 ms |
492 KB |
Output is correct |
18 |
Correct |
1 ms |
364 KB |
Output is correct |
19 |
Correct |
1 ms |
492 KB |
Output is correct |
20 |
Correct |
30 ms |
5100 KB |
Output is correct |
21 |
Correct |
31 ms |
5100 KB |
Output is correct |
22 |
Correct |
29 ms |
5100 KB |
Output is correct |
23 |
Correct |
27 ms |
5100 KB |
Output is correct |
24 |
Correct |
47 ms |
5612 KB |
Output is correct |
25 |
Correct |
176 ms |
9836 KB |
Output is correct |
26 |
Correct |
164 ms |
9708 KB |
Output is correct |
27 |
Correct |
171 ms |
9600 KB |
Output is correct |
28 |
Correct |
166 ms |
9708 KB |
Output is correct |
29 |
Correct |
166 ms |
9452 KB |
Output is correct |
30 |
Correct |
137 ms |
8940 KB |
Output is correct |
31 |
Correct |
113 ms |
8812 KB |
Output is correct |
32 |
Correct |
101 ms |
8708 KB |
Output is correct |
33 |
Correct |
12 ms |
1388 KB |
Output is correct |
34 |
Correct |
160 ms |
9836 KB |
Output is correct |
35 |
Correct |
168 ms |
9708 KB |
Output is correct |
36 |
Correct |
173 ms |
9716 KB |
Output is correct |
37 |
Correct |
169 ms |
9580 KB |
Output is correct |
38 |
Correct |
170 ms |
9580 KB |
Output is correct |
39 |
Correct |
146 ms |
9708 KB |
Output is correct |
40 |
Correct |
120 ms |
9580 KB |
Output is correct |
41 |
Correct |
32 ms |
5100 KB |
Output is correct |
42 |
Correct |
100 ms |
8556 KB |
Output is correct |
43 |
Correct |
119 ms |
9836 KB |
Output is correct |
44 |
Correct |
33 ms |
5100 KB |
Output is correct |
45 |
Correct |
109 ms |
9672 KB |
Output is correct |
46 |
Correct |
119 ms |
9836 KB |
Output is correct |
47 |
Correct |
121 ms |
9836 KB |
Output is correct |
48 |
Correct |
121 ms |
9836 KB |
Output is correct |