标签:har wap second getchar pair mod iter lan end
#include <bits/stdc++.h> using namespace std; #define ll long long #define re register #define pb push_back #define fi first #define se second const int N=1e6+10; const int mod=998244353; const int mod7=1e9+7; void read(int &a) { a=0;int d=1;char ch; while(ch=getchar(),ch>‘9‘||ch<‘0‘) if(ch==‘-‘) d=-1; a=ch^48; while(ch=getchar(),ch>=‘0‘&&ch<=‘9‘) a=(a<<3)+(a<<1)+(ch^48); a*=d; } int n,m; ll seed,vmax; struct node { int l,r; mutable ll v; node(int L,int R=-1,ll V=0){l=L,r=R,v=V;} bool operator < (const node &x) const { return l<x.l; } }; ll quickmod(ll x,int y,int mod) { ll res=1; ll base=x%mod; while(y) { if(y&1) res=res*base%mod; base=base*base%mod; y>>=1; } return res; } set <node> s; set <node> :: iterator split(int pos) { auto it=s.lower_bound(node(pos)); if(it!=s.end()&&it->l==pos) return it; it--; if(pos>it->r) return s.end(); int L=it->l,R=it->r; ll V=it->v; s.erase(it); s.insert(node(L,pos-1,V)); return s.insert(node(pos,R,V)).first; } void add(int l,int r,ll val) { auto it1=split(l),it2=split(r+1); for(;it1!=it2;it1++) it1->v+=val; } void ass(int l,int r,ll val) { auto it1=split(l),it2=split(r+1); s.erase(it1,it2); s.insert(node(l,r,val)); } ll rk(int l,int r,int k) { vector <pair <ll,int> > tmp; auto it1=split(l),it2=split(r+1); tmp.clear(); for(;it1!=it2;it1++) tmp.pb({it1->v,it1->r-it1->l+1}); sort(tmp.begin(),tmp.end()); for(auto it=tmp.begin();it!=tmp.end();it++) { k-=it->se; if(k<=0) return it->fi; } } ll sum(int l,int r,int k,int mod) { auto it1=split(l),it2=split(r+1); ll res=0; for(;it1!=it2;it1++) res=(res+1ll*(it1->r-it1->l+1)*quickmod(it1->v,k,mod)%mod)%mod; return res; } ll rd() { ll res=seed; seed=(seed*7+13)%mod7; return res; } int main() { read(n),read(m); scanf("%I64d %I64d",&seed,&vmax); for(re int i=1;i<=n;i++) { ll x=(rd()%vmax)+1; s.insert(node(i,i,x)); } s.insert({n+1,n+1,0}); for(re int i=1;i<=m;i++) { int op=rd()%4+1; int l=rd()%n+1; int r=rd()%n+1; if(l>r) swap(l,r); int x,y; if(op==3) x=rd()%(r-l+1)+1; else x=rd()%vmax+1; if(op==4) y=rd()%vmax+1; if(op==1) add(l,r,(ll)x); else if(op==2) ass(l,r,(ll)x); else if(op==3) printf("%I64d\n",rk(l,r,x)); else printf("%I64d\n",sum(l,r,x,y)); } return 0; }
标签:har wap second getchar pair mod iter lan end
原文地址:https://www.cnblogs.com/acm1ruoji/p/11837045.html