UOJ #119. 【UR #8】决战圆锥曲线
Description
Solution
此题解题关键在于数据随机,根据这个进行复杂度分析
不想写题解了
#include<bits/stdc++.h>
#define ls (o<<1)
#define rs (o<<1|1)
using namespace std;
typedef long long ll;
const int N=2e5+10;
int n,m,x0,mx[N*4],mn[N*4];bool rev[N*4];
int seed(){x0=(1ll*100000005*x0+20150609)%998244353;return x0/100;}
void R(int &x){x=100000-x;}
void mark(int o){rev[o]^=1;swap(mx[o],mn[o]);R(mx[o]);R(mn[o]);}
void pushdown(int o){if(!rev[o])return ;rev[o]=0;mark(ls);mark(rs);}
void upd(int o){mx[o]=max(mx[ls],mx[rs]);mn[o]=min(mn[ls],mn[rs]);}
void ins(int l,int r,int o,int sa,int t){
if(l==r){mx[o]=mn[o]=t;return ;}
int mid=(l+r)>>1;pushdown(o);
if(sa<=mid)ins(l,mid,ls,sa,t);
else ins(mid+1,r,rs,sa,t);upd(o);
}
void Rev(int l,int r,int o,int sa,int se){
if(sa<=l && r<=se){mark(o);return ;}
int mid=(l+r)>>1;pushdown(o);
if(se<=mid)Rev(l,mid,ls,sa,se);
else if(sa>mid)Rev(mid+1,r,rs,sa,se);
else Rev(l,mid,ls,sa,mid),Rev(mid+1,r,rs,mid+1,se);upd(o);
}
ll ans=0,a,b,c;
ll calc(int x,int y){return a*x+b*y+c*x*y;}
void qry(int l,int r,int o,int sa,int se){
int mid=(l+r)>>1;pushdown(o);
if(sa<=l && r<=se){
if(l==r){ans=max(ans,calc(l,mx[o]));return ;}
if(calc(r,mx[rs])>ans)qry(mid+1,r,rs,mid+1,se);
if(calc(mid,mx[ls])>ans)qry(l,mid,ls,sa,mid);
}
else if(se<=mid)qry(l,mid,ls,sa,se);
else if(sa>mid)qry(mid+1,r,rs,sa,se);
else qry(l,mid,ls,sa,mid),qry(mid+1,r,rs,mid+1,se);upd(o);
}
int main(){
freopen("pp.in","r",stdin);
freopen("pp.out","w",stdout);
char op[2];int x,y;
cin>>n>>m>>x0;
for(int i=1;i<=n;i++)ins(1,n,1,i,seed()%100001);
while(m--){
scanf("%s",op);
x=seed();y=seed();
if(op[0]=='C')x=x%n+1,y%=100001,ins(1,n,1,x,y);
else{
x=x%n+1,y=y%n+1;if(x>y)swap(x,y);
if(op[0]=='R')Rev(1,n,1,x,y);
else {
scanf("%lld%lld%lld",&a,&b,&c);ans=0;
qry(1,n,1,x,y);printf("%lld\n",ans);
}
}
}
return 0;
}