QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#99707#6355. 518MichaelWA 8ms32404kbC++143.5kb2023-04-23 15:27:172023-04-23 15:27:19

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-04-23 15:27:19]
  • 评测
  • 测评结果:WA
  • 用时:8ms
  • 内存:32404kb
  • [2023-04-23 15:27:17]
  • 提交

answer

#include<bits/stdc++.h>
#define LL long long
using namespace std;
const int MxN=200002,MxV=MxN*2+20;
int n,s,s1=0,t,i0=0,i1=1,res=0;
LL ans=0;
int a[MxN],st[MxV],ed[MxV];
map<int,int> mp;
map<int,int>::iterator it;
typedef pair<int,int> P;
vector<P> tmp;
vector<P> pre[MxV];
vector<P> vec[2][MxV];
template<class T>void read(T &x)
{
	x=0;int f=0;char ch=getchar();
	while(ch<'0' || ch>'9')f|=(ch=='-'),ch=getchar();
	while(ch>='0' && ch<='9')x=(x<<3)+(x<<1)+(ch^48),ch=getchar();
	x=f? -x:x;return ;
}
inline void clear()
{
	for(int i=0;i<=s1;++i)vec[i1][i].clear();
}
inline vector<P> merge(vector<P> &A,vector<P> &B)
{
	if(!A.size())return B;
	if(!B.size())return A;
	vector<P> C;
	int tA=0,tB=0;
	P p;
	for(;tA<A.size() && tB<B.size();)
	{
		if(A[tA].first<B[tB].first)p=A[tA],++tA;
		else p=B[tB],++tB;
		f1:
		if(tA<A.size() && A[tA].first<=p.second)
		{
			p.second=max(p.second,A[tA].second),++tA;
			goto f1;
		}
		if(tB<B.size() && B[tB].first<=p.second)
		{
			p.second=max(p.second,B[tB].second),++tB;
			goto f1;
		}
		C.push_back(p);
	}
	for(;tA<A.size();)
	{
		p=A[tA],++tA;
		f2:
		if(tA<A.size() && A[tA].first<=p.second)
		{
			p.second=max(p.second,A[tA].second),++tA;
			goto f2;
		}
		C.push_back(p);
	}
	for(;tB<B.size();)
	{
		p=B[tB],++tB;
		f3:
		if(tB<B.size() && B[tB].first<=p.second)
		{
			p.second=max(p.second,B[tB].second),++tB;
			goto f3;
		}
		C.push_back(p);
	}
	return C;
}
inline void print()
{
	printf("vec:\n");
	for(int i=0;i<=s1;++i)if(vec[i0][i].size())
	{
		printf(" %d:",i);
		for(int j=0;j<vec[i0][i].size();++j)printf("(%d,%d)%c",vec[i0][i][j].first,vec[i0][i][j].second,j+1==vec[i0][i].size()? '\n':' ');
	}
}
inline void RSH(vector<P> &vec,int o)
{
	for(int i=0;i<vec.size();++i)vec[i].first+=o,vec[i].second+=o;
}
inline void solve1()
{
	int a=abs((*it).first),b=(*it).second,sgn=((*it).first<0? -1:1);
	//printf("a:%d b:%d sgn:%d\n",a,b,sgn);
	clear();
	if(sgn>0)s1+=a*b;
	for(int i=0,x;i<=s1;++i)
	{
		x=i/a,st[i]=x,ed[i]=x-b*sgn;
		if(st[i]>ed[i])swap(st[i],ed[i]);
	}
	for(int i=0;i<a;++i)
	{
		int tot=(s1-i)/a;
		for(int j=i;j<=s1;j+=a)
		{
			int x=j/a;
			pre[x]=vec[i0][j];
			RSH(pre[x],-x*sgn);
		}
		for(int j=0;j<=tot;++j)
		{
			if(!(j%b))tmp=pre[j];
			else tmp=merge(tmp,pre[j]);
			if(sgn>0)vec[i1][j*a+i]=tmp;
			else if((j-b)*a+i>=0)vec[i1][(j-b)*a+i]=tmp;
		}
		if(sgn<0)for(int j=tot-b+1;j<=tot && j%b;++j)if(j*a+i>=0)vec[i1][j*a+i]=tmp;
		tmp.clear();
		for(int j=tot;j>=0;--j)
		{
			if(!((j+1)%b))tmp=pre[j];
			else tmp=merge(tmp,pre[j]);
			if(sgn>0)
			{
				if((j+b)*a+i<=s1)vec[i1][(j+b)*a+i]=merge(vec[i1][(j+b)*a+i],tmp);
			}
			else vec[i1][j*a+i]=merge(vec[i1][j*a+i],tmp);
		}
	}
	for(int i=0;i<=s1;++i)RSH(vec[i1][i],(i/a)*sgn);
	i0^=1,i1^=1;
}
inline void solve3()
{
	for(int i=s1;~i;--i)vec[i0][i+n-s/5+1]=vec[i0][i];
	for(int i=(*it).second-1;~i;--i)vec[i0][i].clear();
	s1+=(*it).second,solve1();
}
int main()
{
	//freopen("L.in","r",stdin);
	read(n),read(s);
	for(int i=1;i<=n;++i)read(a[i]),res+=(!a[i])-(a[i]==1);
	
	//res=-1;
	
	if(res<0)for(int i=1;i<=n;++i)--a[i];
	for(int i=1;i<=n;++i)++mp[a[i]];
	t=mp[0],vec[0][0].push_back(P(0,t));
	for(it=mp.end();it!=mp.begin();)
	{
		--it;
		if(!(*it).first)continue;
		if((*it).first>0)solve1();
		else solve3();
		//print();
	}
	for(int i=0;i<=s1;++i)for(int j=0;j<vec[i0][i].size();++j)ans+=vec[i0][i][j].second-vec[i0][i][j].first+1;
	return 0&printf("%lld",ans);
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 31808kb

input:

7 9
0 0 0 1 1 2 5

output:

42

result:

ok 1 number(s): "42"

Test #2:

score: 0
Accepted
time: 8ms
memory: 31688kb

input:

10 33
9 9 8 1 1 1 1 1 1 1

output:

48

result:

ok 1 number(s): "48"

Test #3:

score: -100
Wrong Answer
time: 4ms
memory: 32404kb

input:

10 14
2 4 4 1 0 1 0 1 0 1

output:

77

result:

wrong answer 1st numbers differ - expected: '81', found: '77'