#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define pb push_back
int qpow(ll a,int b,int p){
int res=1;
for(a%=p;b;b>>=1,a=a*a%p)
if(b&1) res=1ll*res*a%p;
return res;
}
struct Seg{int l,r; ll x;};
vector<Seg> vec;
void split(int l,int r){
for(auto it=vec.begin();it!=vec.end();++it){
auto[u,v,w]=*it; if(u<l&&l<=v){
it->l=l,vec.insert(it,{u,l-1,w}); break; }
}
for(auto it=vec.begin();it!=vec.end();++it){
auto[u,v,w]=*it; if(u<=r&&r<v){
it->l=r+1,vec.insert(it,{u,r,w}); break; }
}
}
main(){
cin.tie(0)->sync_with_stdio(0);
int n,m,seed,vmax;
cin>>n>>m>>seed>>vmax;
auto rnd=[&](){
int ret=seed;
return seed=(1ll*seed*7+13)%(int)(1e9+7),ret;
}; for(int i=1;i<=n;++i) vec.pb({i,i,1ll*rnd()%vmax+1});
for(int op,l,r,x,y,wz1,wz2,ans;m--;){
op=rnd()%4+1,l=rnd()%n+1,r=rnd()%n+1,x=rnd();
if(l>r) swap(l,r); if(op^3) x%=vmax; else x%=r-l+1; ++x;
switch(op){
case 1:{ split(l,r);
for(auto&[u,v,w]:vec) if(l<=u&&v<=r) w+=x; break; }
case 2:{ split(l,r);
for(wz1=0;l>vec[wz1].l;) ++wz1;
for(wz2=wz1;wz2<vec.size()&&vec[wz2].r<=r;) ++wz2;
vec.erase(vec.begin()+wz1,vec.begin()+wz2);
vec.insert(vec.begin()+wz1,{l,r,x}); break; }
case 3:{ vector<pair<ll,int>> px;
for(auto[u,v,w]:vec) if(u<=r&&l<=v) px.pb({w,min(v,r)-max(u,l)+1});
sort(px.begin(),px.end()); for(auto[p,q]:px) if((x-=q)<=0){cout<<p<<'\n'; break;} break; }
case 4:{ y=rnd()%vmax+1,ans=0; for(auto[u,v,w]:vec) if(u<=r&&l<=v)
(ans+=1ll*(min(v,r)-max(u,l)+1)*qpow(w,x,y)%y)%=y; cout<<ans<<'\n'; break; }
}
}
}剪贴板
剪贴板 b7cdn7g6
剪贴板信息
剪贴板信息
- 收录
- 更新