Submission #925419

# Submission time Handle Problem Language Result Execution time Memory
925419 2024-02-11T15:08:37 Z Xiaoyang Snowball (JOI21_ho_t2) C++17
100 / 100
858 ms 12512 KB
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
 
#define fi first
#define se second
#define pii pair<int,int>
#define pll pair<long long,long long>
#define pb push_back
#define debug(x) cerr<<#x<<"="<<x<<endl
#define pq priority_queue
#define inf 1ll<<60
#define rep(i,a,b) for (ll i=a;i<(b);i++)
#define MP make_pair
#define SZ(x) (int(x.size()))
#define mod 1000000007
#define ALL(x) x.begin(),x.end()
#define endl "\n"
void inc(ll &a,ll b) {a=(a+b)%mod;}
void dec(ll &a,ll b) {a=(a-b+mod)%mod;}
int prod(ll a,ll b) {return ll(a)*ll(b)%mod;}
int lowbit(ll x) {return x&(-x);}
ll p0w(ll base,ll p) {ll ret=1;while(p>0){if (p%2ll==1ll) ret=ret*base%mod;base=base*base%mod;p/=2ll;}return ret;}
 
const ll maxn=222222;
ll a[maxn],pos[maxn],neg[maxn];


signed main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	ll n,q;cin>>n>>q;
	rep(i,1,n+1)cin>>a[i];
	a[n+1]=inf;
	ll curr=0,mx=0,mn=0;
	rep(i,1,q+1){
		ll x;cin>>x;
		curr+=x;
		mx=max(mx,curr);
		mn=min(mn,curr);
		pos[i]=mx;
		neg[i]=-mn;
	}
	ll prev=a[1]+mn;
	rep(i,1,n+1){
		ll L=max(prev,a[i]+mn);
		ll lo=a[i],hi=a[i+1];
		while(lo<hi){
			ll mid=(lo+hi+1)>>1;
			ll tmp=lower_bound(pos+1,pos+q+1,mid-a[i])-pos;
			ll tmpp=lower_bound(neg+1,neg+q+1,a[i+1]-mid+1)-neg;
			if(tmp<tmpp)lo=mid;
			else hi=mid-1;
		}
		//bsta for last point before overlap
		cout<<lo-L<<endl;
		prev=hi;
	}
	return 0;
}
/*
4 3
-2 3 5 8
2
-4
7
*/
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4604 KB Output is correct
4 Correct 6 ms 4444 KB Output is correct
5 Correct 5 ms 4604 KB Output is correct
6 Correct 5 ms 4444 KB Output is correct
7 Correct 4 ms 4592 KB Output is correct
8 Correct 5 ms 4444 KB Output is correct
9 Correct 3 ms 4444 KB Output is correct
10 Correct 2 ms 4444 KB Output is correct
11 Correct 1 ms 4508 KB Output is correct
12 Correct 1 ms 4440 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 6 ms 4444 KB Output is correct
16 Correct 5 ms 4444 KB Output is correct
17 Correct 5 ms 4444 KB Output is correct
18 Correct 1 ms 4440 KB Output is correct
19 Correct 2 ms 4444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4604 KB Output is correct
4 Correct 6 ms 4444 KB Output is correct
5 Correct 5 ms 4604 KB Output is correct
6 Correct 5 ms 4444 KB Output is correct
7 Correct 4 ms 4592 KB Output is correct
8 Correct 5 ms 4444 KB Output is correct
9 Correct 3 ms 4444 KB Output is correct
10 Correct 2 ms 4444 KB Output is correct
11 Correct 1 ms 4508 KB Output is correct
12 Correct 1 ms 4440 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 6 ms 4444 KB Output is correct
16 Correct 5 ms 4444 KB Output is correct
17 Correct 5 ms 4444 KB Output is correct
18 Correct 1 ms 4440 KB Output is correct
19 Correct 2 ms 4444 KB Output is correct
20 Correct 19 ms 6648 KB Output is correct
21 Correct 18 ms 6488 KB Output is correct
22 Correct 18 ms 6488 KB Output is correct
23 Correct 27 ms 6264 KB Output is correct
24 Correct 106 ms 6352 KB Output is correct
25 Correct 858 ms 10688 KB Output is correct
26 Correct 815 ms 10720 KB Output is correct
27 Correct 785 ms 10360 KB Output is correct
28 Correct 775 ms 10328 KB Output is correct
29 Correct 724 ms 10024 KB Output is correct
30 Correct 464 ms 9444 KB Output is correct
31 Correct 67 ms 8848 KB Output is correct
32 Correct 45 ms 8992 KB Output is correct
33 Correct 63 ms 5204 KB Output is correct
34 Correct 760 ms 10924 KB Output is correct
35 Correct 790 ms 10444 KB Output is correct
36 Correct 855 ms 10756 KB Output is correct
37 Correct 789 ms 10460 KB Output is correct
38 Correct 794 ms 10324 KB Output is correct
39 Correct 787 ms 10684 KB Output is correct
40 Correct 259 ms 10716 KB Output is correct
41 Correct 19 ms 7260 KB Output is correct
42 Correct 143 ms 8972 KB Output is correct
43 Correct 235 ms 12248 KB Output is correct
44 Correct 19 ms 7256 KB Output is correct
45 Correct 291 ms 10388 KB Output is correct
46 Correct 260 ms 12512 KB Output is correct
47 Correct 246 ms 12464 KB Output is correct
48 Correct 235 ms 12504 KB Output is correct