求调神秘WA
查看原帖
求调神秘WA
591863
Lofty楼主2024/8/20 16:42

目前已过,问题大概是 bs 数组开的不够大,似乎存在溢出,但不知道哪里会溢出。

代码如下:

bool _Start;//
#define DEBUG
#include<cmath>
#include<vector>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
namespace IO
{
	#define TP template<typename T>
	#define TP_ template<typename T,typename ... T_>
	#ifdef DEBUG
	#define gc() (getchar())
	void pc(const char &c)
	{
		putchar(c);
	}
	#else
	char buf[1<<20],*p1,*p2;
	#define gc() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<20,stdin),p1==p2)?EOF:*p1++)
	char pbuf[1<<20],*pp=pbuf;
	inline void pc(const char &c)
	{
		if(pp-pbuf==1<<20)
			fwrite(pbuf,1,1<<20,stdout),pp=pbuf;
		*pp++=c;
	}
	struct IO{~IO(){fwrite(pbuf,1,pp-pbuf,stdout);}}_;
	#endif
	TP inline void read(T &x)
	{
		x=0;static int f;f=0;static char ch;ch=gc();
		for(;ch<'0'||ch>'9';ch=gc())ch=='-'&&(f=1);
		for(;ch>='0'&&ch<='9';ch=gc())x=(x<<1)+(x<<3)+(ch&15);
		f&&(x=-x);
	}
	TP void write(T x)
	{
		if(x<0)
			pc('-'),x=-x;
		static T sta[40],top;top=0;
		do
			sta[++top]=x%10,x/=10;
		while(x);
		while(top)
			pc(sta[top--]^48);
	}
	TP_ inline void read(T &x,T_&...y){read(x);read(y...);}
	TP void writeln(const T x){write(x);pc('\n');}
	TP void writesp(const T x){write(x);pc(' ');}
	TP_ void writesp(const T x,const T_ ...y){writesp(x);writesp(y...);}
	TP_ void writeln(const T x,const T_ ...y){writesp(x);writeln(y...);}
	void writest(const std::string &a){static int i;for(i=0;a[i];i++)pc(a[i]);}
	TP inline T max(const T &a,const T &b){return a>b?a:b;}
	TP_ inline T max(const T &a,const T_&...b){return max(a,max(b...));}
	TP inline T min(const T &a,const T &b){return a<b?a:b;}
	TP_ inline T min(const T &a,const T_&...b){return min(a,min(b...));}
	TP inline void swap(T &a,T &b){static T t;t=a;a=b;b=t;}
	TP inline T abs(const T &a){return a>0?a:-a;}
	#undef TP
	#undef TP_
}
using namespace IO;
using std::cerr;
using LL=long long;
#define reg register
constexpr int N=1e9+3,M=1e2+5;
constexpr LL P=1e9+7;
constexpr int intinf=0x3f3f3f3f;
constexpr LL LLinf=0x3f3f3f3f3f3f3f3f;
namespace Lofty//(:)
{
	int n,m,s,l,ans;
	unsigned long long bs[(N>>6)+10],tmp[65];
	inline int count(unsigned long long x)
	{
		reg int res=0;
		while(x)
		{
			res+=x&1;
			x>>=1;
		}
		return res;
	}
	void work()
	{
		scanf("%d%d",&n,&s);
		m=(n>>6)+1;
		while(s--)
		{
			scanf("%d",&l);
			if(l<64)
			{
				memset(tmp,0,sizeof(tmp));
				for(reg int i=0;i<(l<<6);i+=l)
					tmp[i>>6]|=1ull<<(i&63);
				for(reg int i=0;i<=m;i+=l)
					for(reg int j=0;j<l;++j)
						bs[i+j]|=tmp[j];
			}
			else
				for(reg int i=0;i<=n;i+=l)
					bs[i>>6]|=1ull<<(i&63);
		}
		--m;
		if((n&63)!=63)
			bs[m]&=(1ull<<(n+1-(m<<6)))-1;
		bs[0]&=-2ull;
		for(reg int i=0;i<=m;++i)
			ans+=count(bs[i]&(bs[i]<<1)&(bs[i]<<2));
		for(reg int i=1;i<=m;++i)
			ans+=count(bs[i]&(bs[i-1]>>62)&((bs[i-1]>>63)|(bs[i]<<1)));
		printf("%d",ans);
	}
}
bool _End;//
int main()
{
	// #ifndef ONLINE_JUDGE
	// 	freopen("test.in","r",stdin);
	// #endif
	// fprintf(stderr,"%.2lf MB\n",(&_End-&_Start)/1048576.0);
	Lofty::work();
	return 0;
}
2024/8/20 16:42
加载中...