在一群报分数线的人中,我弱弱的问个问题qwq
  • 板块灌水区
  • 楼主Tachibana27
  • 当前回复1
  • 已保存回复1
  • 发布时间2024/11/19 17:05
  • 上次更新2024/11/19 19:19:18
查看原帖
在一群报分数线的人中,我弱弱的问个问题qwq
663199
Tachibana27楼主2024/11/19 17:05

rt,请问为什么在下面这份代码中,将 FAST_ 修改为 true 会 WA?

可以确定的是错误就处在快读那里

/*
	君指尖跃动の光は、私の一生不変の信仰に、唯私の超電磁砲永世生き! 
*/

#include<bits/stdc++.h>
#define DEBUG false
#define XLTX true
#define FILE_ false
#define FAST_ false
#if FAST_
	char *p1;
	char *p2;
	char buf[5000086];
	#define getchar() (p1==p2 and (p2=(p1=buf)+fread(buf,1,5000085,stdin),p1==p2)?EOF:*p1++)
#endif
#if DEBUG
	bool Memory_Start;
    void Deb();

#endif

#if XLTX
	inline int read(){
		int s=0;
		int w=1;
		char ch=getchar();
		for(;ch<'0'||ch>'9';ch=getchar())
	    	if(ch=='-')
				w=-1;
		for(;ch>='0' and ch<='9';ch=getchar())
			s=s*10+ch-'0';
		return s*w;
	}
	void write(int x){
		if(x<0){
			putchar('-');
			x=-x;
		}
		if(x>9)
	    	write(x/10);
		putchar(x%10+'0');
		return;
	}
#else
	inline int read(){
		int reader;
		std::cin>>reader;
		return reader;
	}
	void write(int x){
		std::cout<<x;
		return;
	}
#endif

void file_(std::string s,bool flag){
	if(not flag)
		return;
	freopen((s+".in").c_str(),"r",stdin);
	freopen((s+".out").c_str(),"w",stdout);
	return;
}

int t;

int n;
int a[1000086];
int q;
class node{
	public:
		int l;
		int r;
		int id;
		int ans;
}qwq[1000086];
class Block{
	public:
		int len;
		int id[1000086];
		inline void ini(){
			len=sqrt(n);
			for(int i=1;i<=n;i++)
				id[i]=(i-1)/len+1;
			return;
		}
}blk;
inline bool cmp(node a,node b){
	return blk.id[a.l]==blk.id[b.l]?blk.id[a.l] bitand 1?a.r<b.r:a.r>b.r:blk.id[a.l]<blk.id[b.l];
}
int awa;
int tog[1000086];
inline void del(int x){
	tog[x]--;
	if(not tog[x])
		awa--;
	return;
}
inline void add(int x){
	tog[x]++;
	if(tog[x]==1)
		awa++;
	return;
}
inline bool opcmp(node a,node b){
	return a.id<b.id;
}
int main(){
	file_("",FILE_);
	// t=read();
	t=1;
	while(t--){
		//code here
		n=read();
		for(int i=1;i<=n;i++)
			a[i]=read();
		q=read();
		for(int i=1;i<=q;i++){
			std::cin>>qwq[i].l>>qwq[i].r;
			qwq[i].id=i;
		}
		blk.ini();
		std::sort(qwq+1,qwq+1+q,cmp);
		int l=1;
		int r=0;
		for(int i=1;i<=q;i++){
			while(l<qwq[i].l)
				del(a[l++]);
			while(l>qwq[i].l)
				add(a[--l]);
			while(r<qwq[i].r)
				add(a[++r]);
			while(r>qwq[i].r)
				del(a[r--]);
			qwq[i].ans=awa;
		}
		std::sort(qwq+1,qwq+1+q,opcmp);
		for(int i=1;i<=q;i++)
			std::cout<<qwq[i].ans<<"\n";
	}


#if DEBUG
    Deb();
#endif
    return 0;
}
#if DEBUG
bool Memory_End;
void Deb(){
	std::cout<<"\n\n=========================================\nTime: "<<clock()<<" ms\nMemory: "<<abs(&Memory_End-&Memory_Start)/1024.0/1024.0<<" Mb";
	return;
}
#endif

//Tachibana27 is too vegetable...

2024/11/19 17:05
加载中...