疯狂 MLE 实在不能理解
查看原帖
疯狂 MLE 实在不能理解
203008
山田リョウ楼主2022/11/3 16:30
#include<stdio.h>
#include<map>
#include<random>
#include<time.h>
#include<ctype.h>
namespace fasti{
	char buf[1<<21],*p1=buf,*p2=buf;
	inline char getc(){return p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*(p1++);}
	inline void read(int&x){
    	char c=getc(),f=0;
    	for(;!isdigit(c);c=getc())f^=!(c^'-');
    	for(x=0;isdigit(c);c=getc())x=x*10+(c^48);
    	if(f)x=-x;
	}
	template<typename... Args>
	inline void read(int&x,Args&...args){read(x),read(args...);}
}
using fasti::getc;
using fasti::read;
const int tot=23;
std::map<int,unsigned>key[tot];
typedef unsigned long long ll;
ll c[tot][300001];int n;unsigned a[tot][300001];
inline unsigned rd(){static std::mt19937 rnd(time(nullptr));return rnd();}
inline unsigned getkey(int i,int x){return key[i].find(x)!=key[i].end()?key[i][x]:key[i][x]=rd();}
inline void ins(int i,int x,unsigned y){
	for(;x<=n;x+=(x&-x))c[i][x]+=y;
}
inline void del(int i,int x,unsigned y){
	for(;x<=n;x+=(x&-x))c[i][x]-=y;
}
inline ll sum(int i,int x){ll s=0;for(;x;x-=(x&-x))s+=c[i][x];return s;}
int main(){
	int q,x;
	read(n,q);
	for(int i=1;i<=n;++i){
		read(x);
		for(int j=0;j<tot;++j)ins(j,i,a[j][i]=getkey(j,x));
	}
	for(;q--;){
		int op,l,r,k;
		read(op);
		if(op==1){read(k,x);for(int i=0;i<tot;++i)del(i,k,a[i][k]),ins(i,k,a[i][k]=getkey(i,x));}
		else{read(l,r,k);int flag=1;for(int i=0;i<tot;++i)flag&=((sum(i,r)-sum(i,l-1))%k==0);puts(flag?"YES":"NO");}
	}
	return 0;
}
2022/11/3 16:30
加载中...