MLE!!!!!
查看原帖
MLE!!!!!
483879
hyman00楼主2022/11/21 17:04

用动态开点线段树+类欧写MLE

#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define sz(a) ((int)a.size())
#define re return
#define all(a) a.begin(),a.end()
#define INT long long
#define rept(i,a,b) for(INT i=(a);i<(b);i++)
#define rep(i,a) rept(i,0,a)
#define vi vector<INT>
#define pii pair<INT,INT>
#define F first
#define S second
#define elif else if
using namespace std;
const INT MOD=1000000007,INF=1000000000000000000;
template<typename T>inline void Mx(T &a,T b){a=max(a,b);}
template<typename T>inline void Mi(T &a,T b){a=min(a,b);}
inline INT ad(INT &a,INT b,INT c=MOD){re a=(a+b)%c;}
template<typename T>inline T read(){T a;cin>>a;re a;}
inline bool is_digit(INT msk,INT d){re (msk>>d)&1;}
const INT dx[4]={-1,1,0,0},dy[4]={0,0,-1,1};
void FILEIO(string s){
	freopen((s+".in").c_str(),"r",stdin);
	freopen((s+".out").c_str(),"w",stdout);
}
#define emp nullptr
INT f(INT a,INT b,INT c,INT n){
	if(a>=c||b>=c)
		re f(a%c,b%c,c,n)+n*(n+1)/2*(a/c)+(b/c)*(n+1);
	if(a==0)
		re (b/c)*(n+1);
	INT m=(a*n+b)/c;
//	cout<<"		"<<a<<" "<<b<<" "<<c<<" "<<n<<" "<<n*(m+1)-f(c,c-b-1,a,m)<<"\n";
	re n*m-f(c,c-b-1,a,m-1);
}
INT getprf(INT a,INT b,INT c,INT n){
	re n*(n+1)/2*a+b*(n+1)-f(a,b,c,n)*c;
}
INT getseg(INT a,INT b,INT l,INT r){
//	cout<<"	"<<a<<" "<<b<<" "<<l<<" "<<r<<" "<<getprf(a%b,(l*a)%b,b,r-l)<<"\n";
	re getprf(a%b,(l*a)%b,b,r-l);
}
struct seg{
	struct Node{
		Node *ls,*rs;
		INT val;
		int a,b,l,r;
		void pu(){
			val=0;
			if(ls!=emp)val+=ls->val;
			if(rs!=emp)val+=rs->val;
		}
		void calc(){
			if(a>=0)val=getseg(a,b,l,r);
		}
	};
	Node *root;
	Node *getnew(INT val){
		Node *x=new Node;
		x->val=val;
		x->ls=x->rs=emp;
		x->a=-1;
		re x;
	}
	void pd(Node *cur){
		if(cur->a<0)re;
		if(cur->ls==emp)cur->ls=getnew(0);
		if(cur->rs==emp)cur->rs=getnew(0);
		cur->ls->a=cur->rs->a=cur->a;
		cur->ls->b=cur->rs->b=cur->b;
		INT m=(cur->l+cur->r)/2;
		cur->ls->l=cur->l;
		cur->ls->r=m;
		cur->rs->l=m+1;
		cur->rs->r=cur->r;
		cur->ls->calc();
		cur->rs->calc();
		cur->a=-1;
	}
	void upd(Node *cur,INT l,INT r,INT ql,INT qr,INT a,INT b){
		if(l>=ql&&r<=qr){
			cur->a=a;
			cur->b=b;
			cur->l=l-ql+1;
			cur->r=r-ql+1;
			cur->calc();
			re;
		}
		INT m=(l+r)/2;
		pd(cur);
		if(ql<=m){
			if(cur->ls==emp)cur->ls=getnew(0);
			upd(cur->ls,l,m,ql,qr,a,b);
		}
		if(qr>m){
			if(cur->rs==emp)cur->rs=getnew(0);
			upd(cur->rs,m+1,r,ql,qr,a,b);
		}
		cur->pu();
	}
	INT qry(Node *cur,INT l,INT r,INT ql,INT qr){
		if(l>=ql&&r<=qr)
			re cur->val;
		INT m=(l+r)/2,ans=0;
		pd(cur);
		if(ql<=m){
			if(cur->ls!=emp)
				ans+=qry(cur->ls,l,m,ql,qr);
		}
		if(qr>m){
			if(cur->rs!=emp)
				ans+=qry(cur->rs,m+1,r,ql,qr);
		}
		re ans;
	}
}S;
void run(){
//	FILEIO("ginko");
	S.root=S.getnew(0);
	INT n,q;
	cin>>n>>q;
	while(q--){
		INT t,l,r,a,b;
		cin>>t>>l>>r;
		if(t==1){
			cin>>a>>b;
			S.upd(S.root,1,n,l,r,a,b);
		}
		else{
			cout<<S.qry(S.root,1,n,l,r)<<"\n";
		}
	}
}
signed main()
{
//	ios::sync_with_stdio(0);
//	cin.tie(0);cout.tie(0);
//	for(INT tc=read<INT>();tc;tc--)
		run();
	re 0;
}
 
2022/11/21 17:04
加载中...