警示后人......又或是求助
查看原帖
警示后人......又或是求助
889845
Wunsch楼主2023/7/20 18:38

我妄想用普通的bitset把这题卡过去...

于是卡了一下午的常...

(现在的代码已经穷的只剩一个头文件了)

这里有两份代码,一份是普通快读快写,一份是炒鸡快读快写:

#include<bitset>

//普通的

using namespace std;

const long long ztt=1e9+7;

long long rd(){
    long long x=0;
    char c=getchar();
    while(c<'0'||c>'9'){
        c=getchar();
    }


    while(c<='9'&&c>='0'){
        x=x*10+(c-'0');
        c=getchar();
    }
    return x;
}

long long n=rd();
long long s=rd();
long long a,tmp,ans;

bitset <ztt> vis;

char sss[30];
void write(long long x)
{
	if (!x) putchar('0');
    else 
	{
	    short len=0;  
	    while (x) sss[++len]=x%10+'0',x/=10;
	  	while (len) putchar(sss[len--]);
	} 
	putchar('\n');
}

int main(){
    for(short i=1;i<=s;i++){
        a=rd();
        tmp=a;
        if(tmp==1){ans=n-2;break;}
        while(tmp<=n){
            if(vis[tmp]){tmp+=a;continue;}
            vis[tmp]=1;
            if(vis[tmp+1]){
                if(vis[tmp+2]){
                    ++ans;
                }
                if( vis[tmp-1]){
                    ++ans;
                }
            }
            if(tmp==2){tmp+=a;continue;}
            if(vis[tmp-2]&&vis[tmp-1]){
                ++ans;
            }
            tmp+=a;
        }
    }
    write(ans);
    return 0;
}

#include<bitset>
  
//炒鸡快读快写

using namespace std;

namespace FastIO
{

class FastIOBase
{
 protected:
#ifdef OPENIOBUF
	static const int BUFSIZE=1<<16;
	char buf[BUFSIZE+1];
	int buf_p=0;
#endif
	FILE *target;
 public:
#ifdef OPENIOBUF
	virtual void flush()=0;
#endif
	FastIOBase(FILE *f): target(f){}
	~FastIOBase()=default;
};

class FastOutput final: public FastIOBase
{
#ifdef OPENIOBUF
 public:
	inline void flush()
	{ fwrite(buf,1,buf_p,target),buf_p=0; }
#endif
 private:
	inline void __putc(char x)
	{
#ifdef OPENIOBUF
		if(buf[buf_p++]=x,buf_p==BUFSIZE)flush();
#else
		putc(x,target);
#endif
	}
	template<typename T>
	inline void __write(T x)
	{
		static char stk[64],*top;top=stk;
		if(x<0) return __putc('-'),__write(-x);
		do *(top++)=x%10,x/=10; while(x);
		for(;top!=stk;__putc(*(--top)+'0'));
	}
 public:
	FastOutput(FILE *f=stdout): FastIOBase(f){}
#ifdef OPENIOBUF
	~FastOutput(){ flush(); }
#endif
	inline FastOutput &operator <<(char x)
	{ return __putc(x),*this; }
	inline FastOutput &operator <<(const char *s)
	{ for(;*s;__putc(*(s++)));return *this; }
	inline FastOutput &operator <<(const string &s)
	{ return (*this)<<s.c_str(); }
	template<typename T>
	inline enable_if_t<is_integral<T>::value,FastOutput&> operator <<(const T &x)
	{ return __write(x),*this; }
	template<typename ...T>
	inline void writesp(const T &...x)
	{ initializer_list<int>{(this->operator<<(x),__putc(' '),0)...}; }
	template<typename ...T>
	inline void writeln(const T &...x)
	{ initializer_list<int>{(this->operator<<(x),__putc('\n'),0)...}; }
	template<typename Iter>
	inline void writesp(Iter begin,Iter end)
	{ while(begin!=end) (*this)<<*(begin++)<<' '; }
	template<typename Iter>
	inline void writeln(Iter begin,Iter end)
	{ while(begin!=end) (*this)<<*(begin++)<<'\n'; }

}qout;

class FastInput final: public FastIOBase
{
#ifdef OPENIOBUF
 public:
	inline void flush()
	{ buf[fread(buf,1,BUFSIZE,target)]=EOF,buf_p=0; }
#endif
 private:
	bool __eof,__ok;
	inline char __getc()
	{
		if(__eof) return EOF;
#ifdef OPENIOBUF
		if(buf_p==BUFSIZE) flush();
		return ~buf[buf_p]?buf[buf_p++]:(__eof=true,EOF);
#else
		char ch=getc(target);
		return ~ch?ch:(__eof=true,EOF);
#endif
	}
 public:
	FastInput(FILE *f=stdin): FastIOBase(f),__eof(false),__ok(true)
#ifdef OPENIOBUF
	{ buf_p=BUFSIZE; }
#else
	{}
#endif
	inline bool eof()const { return __eof; }
	inline char peek() { return __getc(); }
	explicit inline operator bool()const { return __ok; }
	inline FastInput &operator >>(char &x)
	{ while(isspace(x=__getc()));return *this; }
	template<typename T>
	inline enable_if_t<is_integral<T>::value,FastInput&> operator >>(T &x)
	{
		char ch,sym=0;
		while(isspace(ch=__getc()));
		if(ch=='-') sym=1,ch=__getc();
		if(__eof) return __ok=false,*this;
		for(x=0;isdigit(ch);x=(x<<1)+(x<<3)+(ch^48),ch=__getc());
		return sym?x=-x:x,*this;
	}
	inline FastInput &operator >>(char *s)
	{
		while(isspace(*s=__getc()));
		if(__eof) return __ok=false,*this;
		for(;!isspace(*s) && !__eof;*(++s)=__getc());
		return *s='\0',*this;
	}
	inline FastInput &operator >>(string &s)
	{
		char str_buf[(1<<8)+1],*p=str_buf;
		char *const buf_end=str_buf+(1<<8);
		while(isspace(*p=__getc()));
		if(__eof) return __ok=false,*this;
		for(s.clear(),p++;;p=str_buf)
		{
			for(;p!=buf_end && !isspace(*p=__getc()) && !__eof;p++);
			*p='\0',s.append(str_buf);
			if(p!=buf_end) break;
		}
		return *this;
	}
	template<typename ...T>
	inline void read(T &...x)
	{ initializer_list<int>{(this->operator>>(x),0)...}; }
	template<typename Iter>
	inline void read(Iter begin,Iter end)
	{ while(begin!=end) (*this)>>*(begin++); }
}qin;

} 
using FastIO::qin,FastIO::qout;

const long long ztt=1e9+7;

long long a,tmp,ans,n,s;

bitset <ztt> vis;

int main(){
    qin>>n>>s;
    for(short i=1;i<=s;i++){
        qin>>a;
        tmp=a;
        if(tmp==1){ans=n-2;break;}
        while(tmp<=n){
            if(vis[tmp]){tmp+=a;continue;}
            vis[tmp]=1;
            if(vis[tmp+1]){
                if(vis[tmp+2]){
                    ++ans;
                }
                if( vis[tmp-1]){
                    ++ans;
                }
            }
            if(tmp==2){tmp+=a;continue;}
            if(vis[tmp-2]&&vis[tmp-1]){
                ++ans;
            }
            tmp+=a;
        }
    }

    qout<<ans;

    return 0;
}

这两份代码都有一个共性

就是主函数里面中间有个 if(tmp==1) 的特判,只要把这个特判//掉,就会在第26,28,30这三个点获得随机RE,因为 bitset 越界了。但如果不//掉,就会在第22,23个点获得TLE 2.01 的好成绩...

这常我是卡不下去了,(如果有一份炒鸡快写能把第一个代码里的除法优化一下的话或许还是有希望的)。

对了 for 循环里面加上 register 不知道为什么有时会更慢点

不知道有没有卡常代师来帮帮我

(虽然我已经在学正解了,但如果能卡过去那实在是太库辣!)

2023/7/20 18:38
加载中...