求助/kel
查看原帖
求助/kel
160839
Prean楼主2020/10/11 14:36

换了快读常数大一截,我人傻了

求dalao康/kel

#include<algorithm>
#include<cstdio>
#include<cctype>
const int M=1e5+5,N=25005,SIZE=1<<21,table[256]={
0,1,1,2,1,2,2,3,1,2,2,3,2,3,3,4,1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5,
1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5,2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,
1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5,2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,
2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7,
1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5,2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,
2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7,
2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7,
3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7,4,5,5,6,5,6,6,7,5,6,6,7,6,7,7,8
};
class istream{
private:
    char buf[SIZE],*p1=buf,*p2=buf;
public:
    inline char getchar(){
        if(p1==p2)p2=(p1=buf)+fread(buf,1,SIZE,stdin);
        return p1==p2?-1:*p1++;
    }
    inline istream&operator>>(int&a){
        char s;
        a=0;
        while(!isdigit(s=getchar()));
        while(a=a*10+(s^48),isdigit(s=getchar()));
        return*this;
    }
}cin;
inline int popcount(unsigned long long a){
	int ans=0;
	while(a)ans+=table[a&255],a>>=8;
	return ans;
}
struct bitset{
	static const int M=1563;
	unsigned long long arr[M];
	inline void reset(){
		for(int i=0;i<M;++i)arr[i]=0;
	}
	inline void Modify(const int&val){
		arr[val>>6]^=1<<(val&63);
	}
	inline void operator&=(const bitset&a){
		for(int i=0;i<M;++i)arr[i]&=a.arr[i];
	}
	inline int count()const{
		int ans=0;
		for(int i=0;i<M;++i)ans+=popcount(arr[i]);
		return ans;
	}
}B[3*N+5],bit;
int n,m,p,ans[N+5],vis[N+5],cnt[M],lsh[M],val[M];
struct Query{
	int L,R,p,id;
	inline bool operator<(const Query&a)const{
		return p==a.p?R<a.R:L<a.L;
	}
}q[N+5];
inline double abs(const double&a){
	return a>0?a:-a;
}
inline double sqrt(const int&x){
	double x0=x*0.5;
	while(abs(x0*x0-x)>1e-3)x0-=(x0*x0-x)/(2*x0);
	return x0;
}
inline void add(const int&val){
	bit.Modify(val+cnt[val]++);
}
inline void del(const int&val){
	bit.Modify(val+--cnt[val]);
}
void Solve(const int&k){
	int i,L,R,tot=0;
	for(i=1;i<=n;++i)cnt[i]=0;p=n/sqrt(2.0*k/3);
	for(i=1;i<=k;++i){
		ans[i]=vis[i]=0;
		cin>>L>>R;q[++tot].p=L/p;
		ans[q[tot].id=i]+=(q[tot].R=R)-(q[tot].L=L)+1;
		cin>>L>>R;q[++tot].p=L/p;
		ans[q[tot].id=i]+=(q[tot].R=R)-(q[tot].L=L)+1;
		cin>>L>>R;q[++tot].p=L/p;
		ans[q[tot].id=i]+=(q[tot].R=R)-(q[tot].L=L)+1;
	}
	std::sort(q+1,q+tot+1);
	for(i=1;i<=tot;++i){
		const int&QL=(q+i)->L,&QR=(q+i)->R,&id=(q+i)->id;
		while(L<QL)del(val[L++]);
		while(L>QL)add(val[--L]);
		while(R<QR)add(val[++R]);
		while(R>QR)del(val[R--]);
		if(vis[id])B[id]&=bit;
		else B[id]=bit,vis[id]=1;
	}
	for(i=1;i<=k;++i)printf("%d\n",ans[i]-3*B[i].count());
	bit.reset();
}
signed main(){
	int i;
	cin>>n>>m;
	for(i=1;i<=n;++i)cin>>val[i],lsh[i]=val[i];
	std::sort(lsh+1,lsh+n+1);
	for(i=1;i<=n;++i)val[i]=std::lower_bound(lsh+1,lsh+n+1,val[i])-lsh;
	while(m){
		if(m<N)return Solve(m),0;
		Solve(N);m-=N;
	}
}
2020/10/11 14:36
加载中...