CF896C Willem, Chtholly and Seniorious(珂朵莉树)
珂朵莉树的板子……这篇文章很不错
据说还有奈芙莲树和瑟尼欧里斯树……
等联赛考完去学一下(逃
//minamoto
#include<bits/stdc++.h>
#define IT set<node>::iterator
#define ll long long
using namespace std;
const int mod7=1e9+,mod9=1e9+,N=1e5+;
ll ksm(ll a,ll b,ll mod){
ll res=;a%=mod;
while(b){
if(b&) res=res*a%mod;
a=a*a%mod,b>>=;
}
return res;
}
struct node{
int l,r;mutable ll v;
node(int L,int R=-,ll V=):l(L),r(R),v(V){}
inline bool operator<(const node &b)const
{return l<b.l;}
};
set<node> s;
IT split(int pos){
IT it=s.lower_bound(node(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(node(l,pos-,v));
return s.insert(node(pos,r,v)).first;
}
void add(int l,int r,ll val=){
IT itr=split(r+),itl=split(l);
for(;itl!=itr;++itl) itl->v+=val;
}
void assign(int l,int r,ll val=){
IT itr=split(r+),itl=split(l);
s.erase(itl,itr),s.insert(node(l,r,val));
}
ll rk(int l,int r,int k){
vector<pair<ll,int> > mp;
IT itr=split(r+),itl=split(l);
mp.clear();
for(;itl!=itr;++itl)
mp.push_back(pair<ll,int>(itl->v,itl->r-itl->l+));
sort(mp.begin(),mp.end());
for(vector<pair<ll,int> >::iterator it=mp.begin();it!=mp.end();++it){
k-=it->second;
if(k<=) return it->first;
}
return -1ll;
}
ll sum(int l,int r,int ex,int mod){
IT itr=split(r+),itl=split(l);ll res=;
for(;itl!=itr;++itl)
res=(res+1ll*(itl->r-itl->l+)*ksm(itl->v,ex,mod))%mod;
return res;
}
int n,m;ll seed,vmax;
ll rnd(){
ll res=seed;seed=(seed*+)%mod7;
return res;
}
ll a[N];
int main(){
// freopen("testdata.in","r",stdin);
scanf("%d %d %lld %lld",&n,&m,&seed,&vmax);
for(int i=;i<=n;++i){
a[i]=(rnd()%vmax)+,s.insert(node(i,i,a[i]));
}
s.insert(node(n+,n+,));
int lines=;
for(int i=;i<=m;++i){
int op=int(rnd()%)+;
int l=int(rnd()%n)+;
int r=int(rnd()%n)+;
if(l>r) swap(l,r);int x,y;
if(op==) x=int(rnd()%(r-l+))+;
else x=int(rnd()%vmax)+;
if(op==) y=int(rnd()%vmax)+;
switch(op){
case :add(l,r,x);break;
case :assign(l,r,x);break;
case :printf("%lld\n",rk(l,r,x));break;
case :printf("%lld\n",sum(l,r,x,y));break;
}
}
return ;
}
CF896C Willem, Chtholly and Seniorious(珂朵莉树)的更多相关文章
- [CF896C]Willem, Chtholly and Seniorious(珂朵莉树)
https://www.cnblogs.com/WAMonster/p/10181214.html 主要用于支持含有较难维护的区间操作与查询的问题,要求其中区间赋值操作(assign())是纯随机的. ...
- [Codeforces896C] Willem, Chtholly and Seniorious (ODT-珂朵莉树)
无聊学了一下珂朵莉树 珂朵莉树好哇,是可以维护区间x次方和查询的高效数据结构. 思想大致就是一个暴力(相对而言)的树形数据结构 lxl毒瘤太强了,发明了ODT算法(Old Driver Tree老司机 ...
- 【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
xml模块定义:实现不同语言或程序之间进行数据交换的协议.格式如下:通过<>节点来区别数据结构如:<load-on-startup(这个是标签) test="value&q ...
- 几道hash题
1: UVa 10887 - Concatenation of Languages map 可以做 ,但是输入实在恶心,有空串之类的HASH模板: int Hash(char *s){ int s ...
- JAVA_构造方法
构造方法: 作用:是给对象的数据进行初始化用的. 特点:1 必须和类的名字一样. 2 和真正的方法是有所不同的,构造方法是没有返回值的类型的 eg: 方法:public void User ( ...
- Spring + RMI
服务端: RmiServer.xml <?xml version="1.0" encoding="UTF-8"?> <beans xmlns= ...
- java集合框架 hashMap 简单使用
参考文章:http://blog.csdn.net/itm_hadf/article/details/7497462 通常,默认加载因子 (.75) 在时间和空间成本上寻求一种折衷. 加载因 ...
- 【深度探索c++对象模型】Function语义学之成员函数调用方式
非静态成员函数 c++的设计准则之一就是:非静态成员函数至少和一般的非成员函数有相同的效率.编译器内部已将member函数实体转换为对等的nonmember函数实体. 转化步骤: 1.改写函数原型以安 ...
- Vue调试工具 vue-devtools
vue-devtools是一款基于chrome浏览器的插件,可以帮我们快速调试vue项目 vue-devtools手动安装: 第一步:找到vue-devtools的github项目(https://g ...
- mysql查看所有存储过程,函数,视图,触发器,表,分页
查询数据库中的存储过程和函数 方法一: select `name` from mysql.proc where db = 'your_db_name' and `type` = 'PROCEDURE' ...
- hdoj2680 Choose the best route
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission ...
- .net面试整理
NET程序员的层次:http://blog.csdn.net/dinglang_2009/article/details/6913852 .NET牛人应该知道些什么http://www.douban. ...