求助 UB
查看原帖
求助 UB
383791
Others楼主2022/8/9 09:50

评测机说我样例输出 0,但是实际输出正确,这应该是 UB,但是真的不知道哪里错了,求大佬帮忙。

#include <bits/stdc++.h>
#define ll long long
#define int long long
#define wr(x,ch) write(x),putchar(ch)
using namespace std;
namespace IO{//by cyffff
	char ibuf[(1<<20)+1],*iS,*iT,out[(1<<23)+1];
	#if ONLINE_JUDGE
	#define gh() (iS==iT?iT=(iS=ibuf)+fread(ibuf,1,(1<<20)+1,stdin),(iS==iT?EOF:*iS++):*iS++)
 	#else
	#define gh() getchar()
	#endif
	inline ll read(){
		char ch=gh(),t=0;
		ll x=0;
		while(ch<'0'||ch>'9')   t|=ch=='-',ch=gh();
		while(ch>='0'&&ch<='9') x=x*10+(ch^48),ch=gh();
		return t?-x:x;
	}
	void write(ll x){
		if(x<0)putchar('-'),x=-x;
		if(x>9)write(x/10);
		putchar(x%10^48);
	}
}
using IO::read;
using IO::write;
struct node {
	int l,r;
	mutable int val;
	bool operator<(const node &p) const {
		return l<p.l;
	}
};set<node> st;
struct node2 {
	int val,len;
	bool operator<(const node2 &p) const {
		return val<p.val;
	}
};
set<node2> st2;
int sd,n,m,vmax,op,l,r,x,y,a[1];
int rnd() {
	int rt=sd;
	sd=(sd*7ll+13ll)%1000000007ll;
	return rt;
}
set<node>::iterator split(int x) {
	if(x>n) return st.end();
	auto it=--st.upper_bound((node){x,x,1});
	int l=it->l,r=it->r,val=it->val;
	if(it->l==x) return it;
	st.erase(it);
	st.insert((node){l,x-1,val});
	return st.insert((node){x,r,val}).first;
}
int qpow(int x,int y,int z) {
	int ans=1;
	while(y) {
		if(y&1) ans=ans*x%z;
		x=x*x%z,y>>=1;
	}
	return ans;
}
signed main() {
	n=read(),m=read(),sd=read(),vmax=read();
	for(int i=1;i<=n;i++) {
		a[i]=(rnd()%vmax)+1ll;
		st.insert((node){i,i,a[i]}); 
	}
	for(int i=1;i<=m;i++) {
		op=(rnd()%4)+1ll;
		l=rnd()%n+1ll;
		r=rnd()%n+1ll;
		if(l>r) l^=r^=l^=r;
		auto itr=split(r+1ll),itl=split(l);
		if(op==1) {
			x=rnd()%vmax+1;
			for(auto i=itl;i!=itr;i++) i->val+=x;
		} else if(op==2) {
			x=rnd()%vmax+1ll;
			st.erase(itl,itr);
			st.insert((node){l,r,x});
		} else if(op==3) {
			st2.clear();
			x=rnd()%(r-l+1ll)+1ll;
			for(auto i=itl;i!=itr;i++) st2.insert((node2){i->val,(i->r)-(i->l)+1});
			while(x>st2.begin()->len) x-=st2.begin()->len;
			wr(st2.begin()->val,'\n');
		} else {
			x=rnd()%vmax+1ll;
			y=rnd()%vmax+1ll; 
			ll ans=0;
			for(auto i=itl;i!=itr;i++) ans=(ans+((i->l)-(i->r)+1)*qpow(i->val,x,y)%y)%y;
			wr(ans,'\n');
		}
	}
	return 0;
}


2022/8/9 09:50
加载中...