QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#176469#6794. Sequence to SequencekkioCompile Error//C++172.1kb2023-09-11 17:53:242023-09-11 17:53:25

Judging History

你现在查看的是最新测评结果

  • [2023-09-11 17:53:25]
  • 评测
  • [2023-09-11 17:53:24]
  • 提交

answer

#include <bits/stdc++.h>
#define int long long 
using namespace std;
const int maxn=1e5+10,inf=1e18;
int n;
int s[maxn],t[maxn];
int ql[maxn],h1,t1,qr[maxn],al[maxn],ar[maxn],h2,t2;
int x,y,ptr,ans;
int cnt=0;
inline void upd(int LEF)
{
	while(h1<=t1&&ql[h1]<LEF)h1++;
	while(h2<=t2&&qr[h2]<LEF)h2++;
	while(ptr<=n+1&&x>=al[ptr]&&x<=ar[ptr])
	{
		ptr++;
		while(h1<t1&&al[ql[t1]]<=al[ptr])t1--;
		ql[++t1]=ptr;
		while(h2<t2&&ar[qr[t2]]>=ar[ptr])t2--;
		qr[++t2]=ptr;
	}
}
bool flag=0;
void solve()
{
	scanf("%lld",&n);
	for(int i=1;i<=n;i++)scanf("%lld",&s[i]);
	for(int i=1;i<=n;i++)scanf("%lld",&t[i]);
	for(int i=1;i<=n;i++)
		if(s[i]==0&&t[i]>0)
		{
			puts("-1");
			return;
		}
		else if(s[i]>t[i])
		{
			if(t[i]==0)al[i]=s[i],ar[i]=inf;
			else al[i]=s[i]-t[i],ar[i]=s[i]-1;
		}
		else 
		{
			al[i]=0,ar[i]=s[i]-1;
		}
	al[n+1]=ar[n+1]=0;
	ptr=1,ans=0;
	x=0,y=0; 
	h1=h2=1,t1=t2=0;
	while(h1<t1&&al[ql[t1]]<=al[1])t1--;
	ql[++t1]=1;
	while(h2<t2&&ar[qr[t2]]>=ar[1])t2--;
	qr[++t2]=1;
	for(int i=1;i<=n;i++)
	{
	//	printf("%d %d %d %d\n",x,y,al[i],ar[i]);
		upd(i);int dx;
		if(t[i]==0){if(i==ptr)ans+=al[i]-x,x=al[i];upd(i);continue;}
		ans+=abs(dx=(s[i]-t[i]-x+y));
	//	printf("!%d\n",dx);
		if(x<al[i])
		{
			if(dx<0)dx=0;
			while(ptr<=n+1&&x<al[ptr])
			{
				int lim;
				if((lim=(h2<=t2?ar[qr[h2]]:inf))<al[ptr]){x=min(lim,x+dx);break;}
				else if(x+dx<al[i]){if(i==ptr)ans+=(al[i]-x-dx)*2,x=al[i];else x+=dx;break;}
				else {dx-=al[ptr]-x;x=al[ptr];upd(i);}
			}
		}
		else if(x>al[i])
		{
			if(dx>0)dx=0;dx=-dx;
			while(ptr<=n+1&&x>ar[ptr])
			{
				int lim;
				if((lim=(h1<=t1?al[ql[h1]]:0))>ar[ptr]){x=max(lim,x-dx);break;}
				else if(x-dx>ar[i]){if(i==ptr)ans+=(x-dx-ar[i])*2,x=ar[i];else x-=dx;break;}
				else {dx-=x-ar[ptr];x=ar[ptr];upd(i);}
			}
		}
		y=t[i]-s[i]+x;
	//	printf("%d %d\n",x,y);
	}ans+=x+y;
	cnt++;
	if(cnt==334&&flag){for(int i=1;i<=n;i++)print("%d %d\n",s[i],t[i]);}
	if(!flag)printf("%lld\n",ans/2); 
}
signed main()
{
	int T;
	scanf("%lld",&T);
	if(T>1000)flag=1;
	while(T--)solve();
	return 0;
}

Details

answer.code: In function ‘void solve()’:
answer.code:85:49: error: ‘print’ was not declared in this scope; did you mean ‘rint’?
   85 |         if(cnt==334&&flag){for(int i=1;i<=n;i++)print("%d %d\n",s[i],t[i]);}
      |                                                 ^~~~~
      |                                                 rint
answer.code:26:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   26 |         scanf("%lld",&n);
      |         ~~~~~^~~~~~~~~~~
answer.code:27:35: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   27 |         for(int i=1;i<=n;i++)scanf("%lld",&s[i]);
      |                              ~~~~~^~~~~~~~~~~~~~
answer.code:28:35: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   28 |         for(int i=1;i<=n;i++)scanf("%lld",&t[i]);
      |                              ~~~~~^~~~~~~~~~~~~~
answer.code: In function ‘int main()’:
answer.code:91:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   91 |         scanf("%lld",&T);
      |         ~~~~~^~~~~~~~~~~