답안 #856865

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
856865 2023-10-04T17:58:14 Z StefanSebez Snowball (JOI21_ho_t2) C++14
100 / 100
172 ms 20144 KB
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define ll long long
const ll inf=1e17+50000;
int main()
{
    ll n,q;cin>>n>>q;
    ll a[n+1];for(ll i=1;i<=n;i++)cin>>a[i];
    ll w[q+1],pref[q+1]={0},mn[q+1],maks[q+1];
    mn[0]=inf;
    maks[0]=-inf;
    /*map<int,int>mapa;
    set<int>st;*/
    for(ll i=1;i<=q;i++)
	{
		cin>>w[i];
		pref[i]=pref[i-1]+w[i];
		mn[i]=min(mn[i-1],pref[i]);
		maks[i]=max(maks[i-1],pref[i]);
		//if(pref[i]>=0) st.insert(pref[i]);
	}
	/*for(int i=q;i>=1;i--) mapa[pref[i]]=i;
	vector<int>b;
	while(!st.empty())
	{
		int x=*st.begin();
		b.pb(x);
		st.erase(x);
	}
	for(auto i:b) printf("%i ",i);
	printf("\n");
	for(int i=1;i<=q;i++) printf("%i: %i %i\n",i,mn[i],maks[i]);*/
	ll L[n+1]={0},R[n+1]={0};
    for(ll i=1;i<n;i++)
	{
		ll l=1,r=q,mid=(l+r)/2,ind=0;
		while(l<=r)
		{
			ll x=maks[mid],y=-mn[mid];
			if(x<0) x=0;
			if(y<0) y=0;
			if(a[i+1]-a[i]>=x+y)
			{
				R[i]=x;
				L[i+1]=y;
				l=mid+1;
			}
			else
			{
				ind=mid;
				r=mid-1;
			}
			mid=(l+r)/2;
		}
		if(ind==0) continue;
		if(pref[ind]>=0) R[i]=a[i+1]-a[i]-L[i+1];
		else L[i+1]=a[i+1]-a[i]-R[i];
		/*int l=0,r=lower_bound(b.begin(),b.end(),a[i+1]-a[i]+1)-b.begin()-1,mid=(l+r)/2;
		while(l<=r)
		{
			int j=mapa[b[mid]];
			printf("%i %i %i %i: %i %i\n",i,l,mid,r,b[mid],j);
			if(a[i]+b[mid]<=a[i+1]+mn[j])
			{
				R[i]=b[mid];
				l=mid+1;
			}
			else r=mid-1;
			mid=(l+r)/2;
		}*/
	}
	R[n]=maks[q];if(R[n]<0) R[n]=0;
	L[1]=-mn[q];if(L[1]<0) L[1]=0;
	/*for(int i=2;i<=n;i++)
	{
		if(mn[q]>=0) {L[i]=0;continue;}
		L[i]=min(-mn[q],a[i]-a[i-1]-R[i-1]);
	}*/
	/*for(int i=1;i<=n;i++) cout<<L[i]<<" ";
	printf("\n");
	for(int i=1;i<=n;i++) cout<<R[i]<<" ";
	printf("\n");*/
	ll res[n+1]={0};
	for(ll i=1;i<=n;i++)
	{
		res[i]=R[i]+L[i];
		cout<<res[i]<<" ";
	}
	printf("\n");
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 2 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 2 ms 348 KB Output is correct
5 Correct 2 ms 556 KB Output is correct
6 Correct 2 ms 344 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 460 KB Output is correct
9 Correct 2 ms 468 KB Output is correct
10 Correct 2 ms 344 KB Output is correct
11 Correct 2 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 2 ms 604 KB Output is correct
16 Correct 2 ms 604 KB Output is correct
17 Correct 2 ms 604 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 476 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 2 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 2 ms 348 KB Output is correct
5 Correct 2 ms 556 KB Output is correct
6 Correct 2 ms 344 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 460 KB Output is correct
9 Correct 2 ms 468 KB Output is correct
10 Correct 2 ms 344 KB Output is correct
11 Correct 2 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 2 ms 604 KB Output is correct
16 Correct 2 ms 604 KB Output is correct
17 Correct 2 ms 604 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 476 KB Output is correct
20 Correct 63 ms 8804 KB Output is correct
21 Correct 63 ms 8568 KB Output is correct
22 Correct 62 ms 8184 KB Output is correct
23 Correct 51 ms 8528 KB Output is correct
24 Correct 58 ms 8988 KB Output is correct
25 Correct 159 ms 18164 KB Output is correct
26 Correct 161 ms 17960 KB Output is correct
27 Correct 159 ms 17704 KB Output is correct
28 Correct 158 ms 17968 KB Output is correct
29 Correct 156 ms 17440 KB Output is correct
30 Correct 155 ms 16908 KB Output is correct
31 Correct 112 ms 16308 KB Output is correct
32 Correct 118 ms 16436 KB Output is correct
33 Correct 16 ms 2140 KB Output is correct
34 Correct 172 ms 18584 KB Output is correct
35 Correct 156 ms 18000 KB Output is correct
36 Correct 168 ms 18244 KB Output is correct
37 Correct 157 ms 18004 KB Output is correct
38 Correct 152 ms 17752 KB Output is correct
39 Correct 154 ms 17896 KB Output is correct
40 Correct 135 ms 17948 KB Output is correct
41 Correct 77 ms 9344 KB Output is correct
42 Correct 121 ms 16420 KB Output is correct
43 Correct 166 ms 19672 KB Output is correct
44 Correct 72 ms 9044 KB Output is correct
45 Correct 130 ms 17968 KB Output is correct
46 Correct 162 ms 19748 KB Output is correct
47 Correct 168 ms 20024 KB Output is correct
48 Correct 172 ms 20144 KB Output is correct