#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
//#include<bits/extc++.h>
//__gnu_pbds
vector<ll> minn;
vector<ll> maxn;
vector<ll> loc;
int n,q;
int whichone(ll x){
if(x>loc[n-1]){
if(x<=loc[n-1]+maxn[q]) return n-1;
return -1;
}else if(x<=loc[0]){
if(x>loc[0]-minn[q]) return 0;
return -1;
}else{
int rp = lower_bound(loc.begin(),loc.end(),x)-loc.begin();
int lp = rp-1;
int lt = 0;
int rt = 0;
if(loc[lp]+maxn[q]<x) lt=-1;
else lt = lower_bound(maxn.begin(),maxn.end(),x-loc[lp])-maxn.begin();
if(loc[rp]-minn[q]>=x) rt = -1;
else rt = upper_bound(minn.begin(),minn.end(),loc[rp]-x)-minn.begin();
if(lt==-1 && rt==-1) return -1;
if(lt==-1) return rp;
if(rt==-1) return lp;
if(lt<rt) return lp;
else return rp;
}
}
int main(){
ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
cin>>n>>q;
loc.resize(n,0);
minn.resize(q+1,1e18);
maxn.resize(q+1,-1e18);
for(int i=0;i<n;i++) cin>>loc[i];
vector<ll> sum(q+1,0);
for(int i=1;i<=q;i++){
cin>>sum[i];
sum[i]+=sum[i-1];
}
minn[0]=0;
maxn[0]=0;
for(int i=1;i<=q;i++){
minn[i] = min(minn[i-1],sum[i]);
maxn[i] = max(maxn[i-1],sum[i]);
}
for(int i=1;i<=q;i++) minn[i] = -minn[i];
for(int i=0;i<n;i++){
ll ans = 0;
if(whichone(loc[i])==i){
ll l=0;ll r = minn[q];
while(r-l>1){
ll mid = l+((r-l)/2);
if(whichone(loc[i]-mid)==i) l = mid;
else r = mid;
}
ans+=l+1;
}
if(whichone(loc[i]+1)==i){
ll l = 1;ll r = maxn[q]+1;
while(r-l>1){
ll mid=l+((r-l)/2);
if(whichone(loc[i]+mid)==i) l =mid;
else r = mid;
}
ans+=l;
}
cout<<ans<<"\n" ;
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
2 ms |
328 KB |
Output is correct |
4 |
Correct |
9 ms |
408 KB |
Output is correct |
5 |
Correct |
8 ms |
328 KB |
Output is correct |
6 |
Correct |
7 ms |
400 KB |
Output is correct |
7 |
Correct |
6 ms |
424 KB |
Output is correct |
8 |
Correct |
6 ms |
332 KB |
Output is correct |
9 |
Correct |
5 ms |
340 KB |
Output is correct |
10 |
Correct |
2 ms |
416 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
10 ms |
340 KB |
Output is correct |
16 |
Correct |
9 ms |
340 KB |
Output is correct |
17 |
Correct |
8 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
336 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
2 ms |
328 KB |
Output is correct |
4 |
Correct |
9 ms |
408 KB |
Output is correct |
5 |
Correct |
8 ms |
328 KB |
Output is correct |
6 |
Correct |
7 ms |
400 KB |
Output is correct |
7 |
Correct |
6 ms |
424 KB |
Output is correct |
8 |
Correct |
6 ms |
332 KB |
Output is correct |
9 |
Correct |
5 ms |
340 KB |
Output is correct |
10 |
Correct |
2 ms |
416 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
10 ms |
340 KB |
Output is correct |
16 |
Correct |
9 ms |
340 KB |
Output is correct |
17 |
Correct |
8 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
336 KB |
Output is correct |
20 |
Correct |
22 ms |
7052 KB |
Output is correct |
21 |
Correct |
20 ms |
6868 KB |
Output is correct |
22 |
Correct |
27 ms |
6680 KB |
Output is correct |
23 |
Correct |
35 ms |
6608 KB |
Output is correct |
24 |
Correct |
179 ms |
6848 KB |
Output is correct |
25 |
Correct |
1600 ms |
11984 KB |
Output is correct |
26 |
Correct |
1569 ms |
11832 KB |
Output is correct |
27 |
Correct |
1499 ms |
11484 KB |
Output is correct |
28 |
Correct |
1477 ms |
11640 KB |
Output is correct |
29 |
Correct |
1361 ms |
11120 KB |
Output is correct |
30 |
Correct |
824 ms |
10544 KB |
Output is correct |
31 |
Correct |
153 ms |
9992 KB |
Output is correct |
32 |
Correct |
66 ms |
10100 KB |
Output is correct |
33 |
Correct |
119 ms |
1512 KB |
Output is correct |
34 |
Correct |
1411 ms |
12208 KB |
Output is correct |
35 |
Correct |
1408 ms |
11704 KB |
Output is correct |
36 |
Correct |
1613 ms |
11864 KB |
Output is correct |
37 |
Correct |
1502 ms |
11628 KB |
Output is correct |
38 |
Correct |
1518 ms |
11460 KB |
Output is correct |
39 |
Correct |
1518 ms |
11648 KB |
Output is correct |
40 |
Correct |
1031 ms |
11584 KB |
Output is correct |
41 |
Correct |
22 ms |
7708 KB |
Output is correct |
42 |
Correct |
61 ms |
10100 KB |
Output is correct |
43 |
Correct |
679 ms |
13508 KB |
Output is correct |
44 |
Correct |
25 ms |
7500 KB |
Output is correct |
45 |
Correct |
527 ms |
11540 KB |
Output is correct |
46 |
Correct |
744 ms |
13524 KB |
Output is correct |
47 |
Correct |
661 ms |
13812 KB |
Output is correct |
48 |
Correct |
572 ms |
13752 KB |
Output is correct |