[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\ ...
随机推荐
- 数组Array的一些方法
数组对象属性和方法的概述:1> arr.push() 将参数添加至数组的末尾,返回的是新数组的长度2> arr.unshift() 将参数添加到数组的开头,返回新数组的长度3> ar ...
- keras例子-matchnet
2015CVPR:MatchNet_ Unifying Feature and Metric Learning for Patch-Based Matching 主要是基于patch的图像特征匹配,基 ...
- ES系列二、CentOS7安装ES head6.3.1
1.Head插件简介 ElasticSearch-head是一个H5编写的ElasticSearch集群操作和管理工具,可以对集群进行傻瓜式操作. 显示集群的拓扑,并且能够执行索引和节点级别操作 搜索 ...
- oracle巡检脚本备份
重做日志生成情况,一天生成日志大小:select round(sum(blocks*block_size)/1024/1024/1024,2) BLOCK from v\$archived_log w ...
- git 的入门使用到团队协作
1.git 的安装.下载---安装,esay. 下载地址:https://git-for-windows.github.io/ 2.创建一个自己的身份 git config --global user ...
- Go语言规格说明书 之 类型声明(Type declarations)
go version go1.11 windows/amd64 本文为阅读Go语言中文官网的规则说明书(https://golang.google.cn/ref/spec)而做的笔记,完整的介绍Go语 ...
- Android设计模式-观察者模式
原文地址 http://blog.csdn.net/qq_25806863/article/details/69218968 观察者模式是一种使用频率非常高的设计模式,最常用的地方就是订阅-发布系统. ...
- main.js 里的/* eslint-disable no-new */
注意项目中的这个,它的作用是: 在js里面,new 一个对象,需要赋值给某个值(变量),用Vue实例化的时候,不需要赋值给值(变量),所以要单独给配一条规则,给new Vue这行代码上面加这个注释,把 ...
- flask的orm框架(SQLAlchemy)-一对多查询以及多对多查询
一对多,多对多是什么? 一对多.例如,班级与学生,一个班级对应多个学生,或者多个学生对应一个班级. 多对多.例如,学生与课程,可以有多个学生修同一门课,同时,一门课也有很多学生. 一对多查询 如果一个 ...
- 【ES】代码例子
#!/usr/bin/env python #coding=utf-8 from elasticsearch import Elasticsearch from elasticsearch_dsl i ...