[CF896C]Willem, Chtholly and Seniorious(珂朵莉树)
https://www.cnblogs.com/WAMonster/p/10181214.html
主要用于支持含有较难维护的区间操作与查询的问题,要求其中区间赋值操作(assign())是纯随机的。
注意要先split(r+1)再split(l),最好最后设一个点(n+1,n+1,0)
#include<set>
#include<cstdio>
#include<algorithm>
#include<iostream>
#define rep(i,l,r) for (int i=(l); i<=(r); i++)
typedef long long ll;
using namespace std; const int N=;
int n,m,x,y,mx; ll seed;
struct P{ int l,r; mutable ll v; };
bool operator <(const P &a,const P &b){ return a.l<b.l; }
set<P>S;
typedef set<P>::iterator sit;
pair<ll,int>ve[N]; ll ksm(ll a,ll b,ll mod){
ll res=; a%=mod;
for (; b; a=a*a%mod,b>>=)
if (b & ) res=res*a%mod;
return res;
} sit split(int pos){
sit it=S.lower_bound((P){pos,,});
if (it!=S.end() && it->l==pos) return it;
it--; int l=it->l,r=it->r; ll v=it->v;
S.erase(it); S.insert((P){l,pos-,v});
return S.insert((P){pos,r,v}).first;
} void assign(int l,int r,ll v){
sit it2=split(r+),it1=split(l);
S.erase(it1,it2); S.insert((P){l,r,v});
} void add(int l,int r,ll v){
sit it2=split(r+),it1=split(l);
for (sit it=it1; it!=it2; it++) it->v+=v;
} ll kth(int l,int r,int k){
sit it2=split(r+),it1=split(l); int tot=;
for (sit it=it1; it!=it2; it++) ve[++tot]=pair<ll,int>(it->v,(it->r)-(it->l)+);
sort(ve+,ve+tot+);
rep(i,,tot){
k-=ve[i].second;
if (k<=) return ve[i].first;
}
return ;
} ll que(int l,int r,int x,ll y){
sit it2=split(r+),it1=split(l);
ll res=;
for (sit it=it1; it!=it2; it++) res=(res+((it->r)-(it->l)+)*ksm(it->v,x,y))%y;
return res;
} int rnd(){ int ret=(int)seed; seed=(seed*+)%; return ret; } int main(){
freopen("CF896C.in","r",stdin);
freopen("CF896C.out","w",stdout);
cin>>n>>m>>seed>>mx;
rep(i,,n) S.insert((P){i,i,rnd()%mx+});
S.insert((P){n+,n+,});
rep(i,,m){
int op=rnd()%+,l=rnd()%n+,r=rnd()%n+;
if (l>r) swap(l,r);
if (op==) x=rnd()%(r-l+)+; else x=rnd()%mx+;
if (op==) y=rnd()%mx+;
if (op==) add(l,r,x);
if (op==) assign(l,r,x);
if (op==) cout<<kth(l,r,x)<<endl;
if (op==) cout<<que(l,r,x,y)<<endl;
}
return ;
}
[CF896C]Willem, Chtholly and Seniorious(珂朵莉树)的更多相关文章
- [Codeforces896C] Willem, Chtholly and Seniorious (ODT-珂朵莉树)
无聊学了一下珂朵莉树 珂朵莉树好哇,是可以维护区间x次方和查询的高效数据结构. 思想大致就是一个暴力(相对而言)的树形数据结构 lxl毒瘤太强了,发明了ODT算法(Old Driver Tree老司机 ...
- CF896C Willem, Chtholly and Seniorious(珂朵莉树)
中文题面 珂朵莉树的板子……这篇文章很不错 据说还有奈芙莲树和瑟尼欧里斯树…… 等联赛考完去学一下(逃 //minamoto #include<bits/stdc++.h> #define ...
- 【ODT】cf896C - Willem, Chtholly and Seniorious
仿佛没用过std::set Seniorious has n pieces of talisman. Willem puts them in a line, the i-th of which is ...
- 珂朵莉树(Chtholly Tree)学习笔记
珂朵莉树(Chtholly Tree)学习笔记 珂朵莉树原理 其原理在于运用一颗树(set,treap,splay......)其中要求所有元素有序,并且支持基本的操作(删除,添加,查找......) ...
- [CF896C]Willem, Chtholly and Seniorious
题目大意:有$n$个数,有$m$次$4$种操作: l r x :将$[l,r]$区间所有数加上$x$ l r x :将$[l,r]$区间所有数变成$x$ l r k :输出$[l,r]$区间第$k$大 ...
- [转]我的数据结构不可能这么可爱!——珂朵莉树(ODT)详解
参考资料: Chtholly Tree (珂朵莉树) (应某毒瘤要求,删除链接,需要者自行去Bilibili搜索) 毒瘤数据结构之珂朵莉树 在全是珂学家的珂谷,你却不知道珂朵莉树?来跟诗乃一起学习珂朵 ...
- 『珂朵莉树 Old Driver Tree』
珂朵莉树 珂朵莉树其实不是树,只是一个借助平衡树实现的数据结构,主要是对于有区间赋值的数据结构题,可以用很暴力的代码很高效地完成任务,当然这是建立在数据随机的基础上的. 即使数据不是随机的,写一个珂朵 ...
- 「学习笔记」珂朵莉树 ODT
珂朵莉树,也叫ODT(Old Driver Tree 老司机树) 从前有一天,珂朵莉出现了... 然后有一天,珂朵莉树出现了... 看看图片的地址 Codeforces可还行) 没错,珂朵莉树来自Co ...
- 洛谷AT2342 Train Service Planning(思维,动态规划,珂朵莉树)
洛谷题目传送门 神仙思维题还是要写点东西才好. 建立数学模型 这种很抽象的东西没有式子描述一下显然是下不了手的. 因为任何位置都以\(k\)为周期,所以我们只用关心一个周期,也就是以下数都在膜\(k\ ...
随机推荐
- 【转】Python之xml文档及配置文件处理(ElementTree模块、ConfigParser模块)
[转]Python之xml文档及配置文件处理(ElementTree模块.ConfigParser模块) 本节内容 前言 XML处理模块 ConfigParser/configparser模块 总结 ...
- Python之matplotlib库学习
matplotlib 是python最著名的绘图库,它提供了一整套和matlab相似的命令API,十分适合交互式地进行制图.而且也可以方便地将它作为绘图控件,嵌入GUI应用程序中. 它的文档相当完备, ...
- windows命令行中英文切换
Windows下cmd命令提示符窗口的语言设置(中英) 打开cmd命令提示窗口 输入 chcp 936 使用ping 命令 显示中文 2 同样 输入chcp 437 3 使用ping 命令
- 『实践』Matlab实现Flyod求最短距离及存储最优路径
Matlab实现Flyod求最短距离及存储最优路径 一.实际数据 已知图中所有节点的X.Y坐标. 图中的节点编号:矩阵中的编号 J01-J62:1-62; F01-F60:63-122; Z01-Z0 ...
- win32编程:L,_T() ,TEXT和_TEXT
L的使用: 在字符串前面的大写字母L,用来告诉编译器该字符串应该作为Unicode来编译.它用来将ASNI转换为Unicode,Unicode字符串中每个字符占16位(两个字节),而在ASNI中每个字 ...
- shiro设置session超时时间
系统默认超时时间是180000毫秒(30分钟) long timeout = SecurityUtils.getSubject().getSession().getTimeout(); System. ...
- Python poll IO多路复用
一.poll介绍 poll本质上和select没有区别,只是没有了最大连接数(linux上默认1024个)的限制,原因是它基于链表存储的. 本人的另一篇博客讲了 python select : ht ...
- sqlserver循环
普通while循环 1 循环5来修改学生信息 循环遍历修改记录 DECLARE @i int set @i=0 while @i<5 BEGIN update Student set demo ...
- Ex 3_25 图中每个顶点有一个相关价格..._十一次作业
(a)首先对有向无环图进行拓扑排序,再按拓扑排序的逆序依次计算每个顶点的cost值,每个顶点的cost值为自身的price值与相邻顶点间的cost值得最小值 (b)求出图中的每一个强连通分量,并把所有 ...
- vue系列之Vue-cli
Vue-cli是Vue的脚手架工具 vue-cli 地址:https://github.com/vuejs/vue-cli 安装 npm install -g vue-cli 使用 vue init ...