Chtholly Tree (珂朵莉树) ODT
ODT,OldDriverTree,又名ChthollyTree" role="presentation" style="position: relative;">ODT,OldDriverTree,又名ChthollyTreeODT,OldDriverTree,又名ChthollyTree
−关键操作推平一段区间" role="presentation" style="position: relative;">−关键操作推平一段区间−关键操作推平一段区间
1. CF 896C Willem, Chtholly and Seniorious
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int MOD7 = 1e9 + 7;
const int MOD9 = 1e9 + 9;
const int imax_n = 1e5 + 7;
//大数相加
LL add(LL a, LL b, LL mod)
{
LL res = 0;
LL ans = a;
while (b)
{
if (b&1) res = (res + ans) % mod;
ans = (ans + ans) % mod;
b>>=1;
}
return res;
}
//快速幂
LL pow(LL a, LL b, LL mod)
{
LL res = 1;
LL ans = a % mod;
while (b)
{
if (b&1) res = res * ans % mod;
ans = ans * ans % mod;
b>>=1;
}
return res;
}
struct node {
int l,r;
mutable LL v;
node(int L, int R=-1, LL V=0):l(L), r(R), v(V){}
bool operator<(const node& o) const {
return l < o.l;
}
};
set<node> s;
// 拆分操作
set<node>::iterator split(int pos)
{
auto it = s.lower_bound(node(pos));
if (it != s.end() && it->l == pos) return it;
--it;
if (pos > it->r) return s.end();
int L = it->l, R = it->r;
LL V = it->v;
s.erase(it);
s.insert(node(L, pos-1, V));
return s.insert(node(pos, R, V)).first;
// pair<iterator, bool> insert(const value_type& val);
}
//区间加操作
void add(int l, int r, LL val=1)
{
split(l);
auto itr = split(r+1), itl = split(l);
for (; itl != itr; ++itl) itl->v += val;
}
//区间赋值操作
void assign_val(int l, int r, LL val=0)
{
split(l);
auto itr = split(r+1), itl = split(l);
s.erase(itl, itr);
s.insert(node(l, r, val));
}
//求区间第K大值,reversed控制顺序与逆序
LL rank_(int l, int r, int k, bool reversed=0)
{
vector<pair<LL, int>> vp;
if (reversed) k = r - l + 2 - k;
split(l);
auto itr = split(r+1), itl = split(l);
vp.clear();
for (; itl != itr; ++itl)
vp.push_back({itl->v, itl->r - itl->l + 1});
sort(vp.begin(), vp.end());
for (auto i: vp)
{
k -= i.second;
if (k <= 0) return i.first;
}
return -1LL;
}
//区间值求和操作
LL sum(int l, int r, int ex, int mod)
{
split(l);
auto itr = split(r+1), itl = split(l);
LL res = 0;
for (; itl != itr; ++itl)
res = (res + (LL)(itl->r - itl->l + 1) * pow(itl->v, LL(ex), LL(mod))) % mod;
return res;
}
int n, m;
LL seed, vmax;
LL rnd()
{
LL ret = seed;
seed = (seed * 7 + 13) % MOD7;
return ret;
}
LL a[imax_n];
int main()
{
cin>>n>>m>>seed>>vmax;
for (int i=1;i<=n;++i)
{
a[i] = (rnd() % vmax) + 1;
s.insert(node(i,i,a[i]));
}
s.insert(node(n+1, n+1, 0));
int lines = 0;
for (int i =1; i <= m; ++i)
{
int op = int(rnd() % 4) + 1;
int l = int(rnd() % n) + 1;
int r = int(rnd() % n) + 1;
if (l > r)
swap(l,r);
int x, y;
// cout<<i<<" op = "<<op<<" ";
if (op == 3)
x = int(rnd() % (r-l+1)) + 1;
else
x = int(rnd() % vmax) +1;
if (op == 4)
y = int(rnd() % vmax) + 1;
if (op == 1)
add(l, r, LL(x));
else if (op == 2)
assign_val(l, r, LL(x));
else if (op == 3)
{
// cout<<"lines"<<++lines<<endl;
cout<<rank_(l, r, x)<<endl;
}
else
{
// cout<<"lines"<<++lines<<endl;
cout<<sum(l, r, x, y)<<endl;
}
}
return 0;
}
Chtholly Tree (珂朵莉树) ODT的更多相关文章
- [转]我的数据结构不可能这么可爱!——珂朵莉树(ODT)详解
参考资料: Chtholly Tree (珂朵莉树) (应某毒瘤要求,删除链接,需要者自行去Bilibili搜索) 毒瘤数据结构之珂朵莉树 在全是珂学家的珂谷,你却不知道珂朵莉树?来跟诗乃一起学习珂朵 ...
- 「学习笔记」珂朵莉树 ODT
珂朵莉树,也叫ODT(Old Driver Tree 老司机树) 从前有一天,珂朵莉出现了... 然后有一天,珂朵莉树出现了... 看看图片的地址 Codeforces可还行) 没错,珂朵莉树来自Co ...
- 珂朵莉树(ODT)笔记
珂朵莉树,又叫老司机树($Old\, Driver \, Tree$) 是一种暴力出奇迹,就怕数据不随机的数据结构. 适用 需要用线段树维护一些区间修改的信息…… 像是区间赋值(主要),区间加…… 原 ...
- 珂朵莉树(Chtholly Tree)学习笔记
珂朵莉树(Chtholly Tree)学习笔记 珂朵莉树原理 其原理在于运用一颗树(set,treap,splay......)其中要求所有元素有序,并且支持基本的操作(删除,添加,查找......) ...
- 『珂朵莉树 Old Driver Tree』
珂朵莉树 珂朵莉树其实不是树,只是一个借助平衡树实现的数据结构,主要是对于有区间赋值的数据结构题,可以用很暴力的代码很高效地完成任务,当然这是建立在数据随机的基础上的. 即使数据不是随机的,写一个珂朵 ...
- [数据结构]ODT(珂朵莉树)实现及其应用,带图
[数据结构]ODT(珂朵莉树)实现及其应用,带图 本文只发布于博客园,其他地方若出现本文均是盗版 算法引入 需要一种这样的数据结构,需要支持区间的修改,区间不同值的分别操作. 一般的,我们会想到用线段 ...
- CF896C Willem, Chtholly and Seniorious(珂朵莉树)
中文题面 珂朵莉树的板子……这篇文章很不错 据说还有奈芙莲树和瑟尼欧里斯树…… 等联赛考完去学一下(逃 //minamoto #include<bits/stdc++.h> #define ...
- 题解 P3372 【【模板】线段树 1】(珂朵莉树解法)
这道题可以用珂朵莉树做,但是由于数据比较不随机,而我也没有手写一颗平衡树,所以就被卡掉了,只拿了70分. 珂朵莉树是一种基于平衡树的(伪)高效数据结构. 它的核心操作是推平一段区间. 简而言之,就是把 ...
- 洛谷AT2342 Train Service Planning(思维,动态规划,珂朵莉树)
洛谷题目传送门 神仙思维题还是要写点东西才好. 建立数学模型 这种很抽象的东西没有式子描述一下显然是下不了手的. 因为任何位置都以\(k\)为周期,所以我们只用关心一个周期,也就是以下数都在膜\(k\ ...
随机推荐
- 【APUE】信号量、互斥体和自旋锁
http://www.cnblogs.com/biyeymyhjob/archive/2012/07/21/2602015.html http://blog.chinaunix.net/uid-205 ...
- 重载和重写在jvm运行中的区别(一)
1.重载(overload)方法 对重载方法的调用主要看静态类型,静态类型是什么类型,就调用什么类型的参数方法. 2.重写(override)方法 对重写方法的调用主要看实际类型.实际类型如果实现了该 ...
- java实用技能 上传文件 等等
1.IOS AES对称加密,加密结果不同,问题解决 IOS http post请求,使用AFNetworing 框架,默认请求content-type为application/json ,所以无法使 ...
- Hackrank Kingdom Division 树形DP
题目链接:传送门 题意: 给你一棵树,n个点 每个点可以染成红色和蓝色 但是红色的点与其相邻的点中必须有红色节点,蓝色也是 问你有多少种染色的方案 题解: 树形dp 先转化为有根树,取1为根 设定dp ...
- 安全相关的head头
与安全相关的head头包括 参考网站:https://developer.mozilla.org/en-US/docs/Web/HTTP Content-Security-Policy(CSP):禁止 ...
- 闲得蛋疼,JavaScript版本BadApple
参考Vim版本的BadApple改写而成.由于加载数据比较大,可能网速不给力的童鞋效果不太好,多刷新几次就好了,^_^.运行环境:支持HTML5 Canvas的浏览器.1. 代码:$(functio ...
- 使用JSTL 对在页面上对 0,0,1 的分割处理 forTokens
使用JSTL 对在页面上对 0,0,1 的分割处理 <tr onmouseover="currentcolor=this.style.backgroundColor;this.styl ...
- linux下的git安装及配置
一.yum安装方式 1.安装 $ yum install curl-devel expat-devel gettext-devel openssl-devel zlib-devel $ yum -y ...
- 数据库sqlite3的使用-代码实例应用
一.使用代码的方式批量添加(导入)数据到数据库中 1.执行SQL语句在数据库中添加一条信息 插入一条数据的sql语句: 点击run执行语句之后,刷新数据 2.在ios项目中使用代码批量添加多行数据 ...
- 并不对劲的LCT
LCT,是连猫树(link-cat-tree)的缩写.它是树链剖分和splay的结合版本. 由于有很多关于LCT的文章以及这并不是对劲的文章,并不对劲的人并不打算讲得太详细. 推荐:详细的LCT-&g ...