珂朵莉树模板(珂朵莉树)
学会了一个叫做mutable的关键字
关键操作:Split,将指定位置的区间拆开
洛谷CF896C Willem, Chtholly and Seniorious
#include<bits/stdc++.h>
#define LL long long
#define I inline
#define R register int
using namespace std;
struct Node{
mutable int l,r;mutable LL v;
I Node(R a,R b=0,LL c=0):l(a),r(b),v(c){}
I bool operator<(const Node&a)const{
return l<a.l;
}
};
typedef set<Node>::iterator IT;
set<Node>s;
IT d[100009];
I bool operator<(const IT&a,const IT&b){
return a->v<b->v;
}
I IT Split(R p){
IT it=s.lower_bound(Node(p));
if(it!=s.end()&&it->l==p)return it;
R r=(--it)->r;it->r=p;
return s.insert(Node(p,r,it->v)).first;
}
int n,m,seed,vmax;
I int Rand(){
R ret=seed;
seed=((LL)seed*7+13)%1000000007;
return ret;
}
I LL Pow(LL b,R k,LL YL,LL a=1){
for(b%=YL;k;k>>=1,b=b*b%YL)
if(k&1)a=a*b%YL;
return a;
}
int main(){
ios::sync_with_stdio(0);
cin>>n>>m>>seed>>vmax;
for(R i=1;i<=n;++i)
s.insert(Node(i,i+1,Rand()%vmax+1));
for(R i=1;i<=m;++i){
R op=Rand()%4+1,l=Rand()%n+1,r=Rand()%n+1,p=0;
if(l>r)swap(l,r);++r;
R x=Rand()%(op==3?r-l:vmax)+1;
IT it=Split(l),en=r>n?s.end():Split(r);
switch(op){
case 1:
for(;it!=en;++it)it->v+=x;
break;
case 2:
s.erase(it,en);
s.insert(Node(l,r,x));
break;
case 3:
for(;it!=en;++it)d[++p]=it;
sort(d+1,d+p+1);
for(p=1;x>0;++p)x-=d[p]->r-d[p]->l;
cout<<d[p-1]->v<<'\n';
break;
case 4:
LL YL=Rand()%vmax+1,ans=0;
for(;it!=en;++it)ans=(ans+Pow(it->v,x,YL)*(it->r-it->l))%YL;
cout<<ans<<endl;
}
}
return 0;
}
分类:
OI——算法模板
, 数据结构——平衡树——珂朵莉树
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
· 一个奇形怪状的面试题:Bean中的CHM要不要加volatile?
· [.NET]调用本地 Deepseek 模型
· 一个费力不讨好的项目,让我损失了近一半的绩效!
· 在鹅厂做java开发是什么体验
· 百万级群聊的设计实践
· WPF到Web的无缝过渡:英雄联盟客户端的OpenSilver迁移实战
· 永远不要相信用户的输入:从 SQL 注入攻防看输入验证的重要性
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析