无聊学了一下珂朵莉树

珂朵莉树好哇,是可以维护区间x次方和查询的高效数据结构。

思想大致就是一个暴力(相对而言)的树形数据结构

lxl毒瘤太强了,发明了ODT算法(Old Driver Tree老司机算法)

这里有一个大佬ACDreamer的题解

附上链接https://www.luogu.org/blog/ACdreamer/solution-cf896c

还有一个B站的讲解视频

附上链接https://www.bilibili.com/video/av21651173

我不会用珂朵莉树,但是就是大致了解了一下吧

毕竟普及蒟蒻听不懂省选算法。

这里附上大佬的程序

#include<cstdio>
#include<set>
#include<vector>
#include<utility>
#include<algorithm>
#define IT set<node>::iterator
using std::set;
using std::vector;
using std::pair;
typedef long long LL;
const int MOD7 = 1e9 + ;
const int MOD9 = 1e9 + ;
const int imax_n = 1e5 + ; LL pow(LL a, LL b, LL mod)
{
LL res = ;
LL ans = a % mod;
while (b)
{
if (b&) res = res * ans % mod;
ans = ans * ans % 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) {}
bool operator<(const node& o) const
{
return l < o.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 itl = split(l),itr = split(r+);
for (; itl != itr; ++itl) itl->v += val;
} void assign_val(int l, int r, LL val=)
{
IT itl = split(l),itr = split(r+);
s.erase(itl, itr);
s.insert(node(l, r, val));
} LL rank(int l, int r, int k)
{
vector<pair<LL, int> > vp;
IT itl = split(l),itr = split(r+);
vp.clear();
for (; itl != itr; ++itl)
vp.push_back(pair<LL,int>(itl->v, itl->r - itl->l + ));
std::sort(vp.begin(), vp.end());
for (vector<pair<LL,int> >::iterator it=vp.begin();it!=vp.end();++it)
{
k -= it->second;
if (k <= ) return it->first;
}
return -1LL;
} LL sum(int l, int r, int ex, int mod)
{
IT itl = split(l),itr = split(r+);
LL res = ;
for (; itl != itr; ++itl)
res = (res + (LL)(itl->r - itl->l + ) * pow(itl->v, LL(ex), LL(mod))) % mod;
return res;
} int n, m;
LL seed, vmax; LL rnd()
{
LL ret = seed;
seed = (seed * + ) % MOD7;
return ret;
} LL a[imax_n]; int main()
{
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)
std::swap(l,r);
int x, y;
if (op == )
x = int(rnd() % (r-l+)) + ;
else
x = int(rnd() % vmax) +;
if (op == )
y = int(rnd() % vmax) + ;
if (op == )
add(l, r, LL(x));
else if (op == )
assign_val(l, r, LL(x));
else if (op == )
printf("%lld\n",rank(l, r, x));
else
printf("%lld\n",sum(l, r, x, y));
}
return ;
}

[Codeforces896C] Willem, Chtholly and Seniorious (ODT-珂朵莉树)的更多相关文章

  1. CF896C Willem, Chtholly and Seniorious(珂朵莉树)

    中文题面 珂朵莉树的板子……这篇文章很不错 据说还有奈芙莲树和瑟尼欧里斯树…… 等联赛考完去学一下(逃 //minamoto #include<bits/stdc++.h> #define ...

  2. [数据结构]ODT(珂朵莉树)实现及其应用,带图

    [数据结构]ODT(珂朵莉树)实现及其应用,带图 本文只发布于博客园,其他地方若出现本文均是盗版 算法引入 需要一种这样的数据结构,需要支持区间的修改,区间不同值的分别操作. 一般的,我们会想到用线段 ...

  3. ODT珂朵莉树

    关于ODT,据说是毒瘤lxl发明的,然后毒瘤鱼鱼因为我用ODT误导人D了我一回-- 这是一种基于 \(set\) 的暴力数据结构. 在使用时请注意,没看见这2东西千万别用-- 1.保证数据随机 2.有 ...

  4. ODT 珂朵莉树 入门

    #include<iostream> #include<stdio.h> #include<string.h> #include<algorithm> ...

  5. 珂朵莉树(Chtholly Tree)学习笔记

    珂朵莉树(Chtholly Tree)学习笔记 珂朵莉树原理 其原理在于运用一颗树(set,treap,splay......)其中要求所有元素有序,并且支持基本的操作(删除,添加,查找......) ...

  6. 「学习笔记」珂朵莉树 ODT

    珂朵莉树,也叫ODT(Old Driver Tree 老司机树) 从前有一天,珂朵莉出现了... 然后有一天,珂朵莉树出现了... 看看图片的地址 Codeforces可还行) 没错,珂朵莉树来自Co ...

  7. [转]我的数据结构不可能这么可爱!——珂朵莉树(ODT)详解

    参考资料: Chtholly Tree (珂朵莉树) (应某毒瘤要求,删除链接,需要者自行去Bilibili搜索) 毒瘤数据结构之珂朵莉树 在全是珂学家的珂谷,你却不知道珂朵莉树?来跟诗乃一起学习珂朵 ...

  8. 珂朵莉树(ODT)笔记

    珂朵莉树,又叫老司机树($Old\, Driver \, Tree$) 是一种暴力出奇迹,就怕数据不随机的数据结构. 适用 需要用线段树维护一些区间修改的信息…… 像是区间赋值(主要),区间加…… 原 ...

  9. 『珂朵莉树 Old Driver Tree』

    珂朵莉树 珂朵莉树其实不是树,只是一个借助平衡树实现的数据结构,主要是对于有区间赋值的数据结构题,可以用很暴力的代码很高效地完成任务,当然这是建立在数据随机的基础上的. 即使数据不是随机的,写一个珂朵 ...

随机推荐

  1. HTML CSS JavaScript 工作笔记

    1. onclick方法如何传递多个参数 "<a href='#' onclick=\"applied_status('" + ids + "', '&q ...

  2. 饮冰三年-人工智能-linux-06 系统启动流程及安全

    系统启动流程 BOIS(Basic Input/Output System)基本输入输出系统:硬件和软件之间的接口,而且是很基本的接口. grub(Grand Unified BootLoader)多 ...

  3. 饮冰三年-人工智能-linux-02 初始Linux

    参考博客:https://www.cnblogs.com/linhaifeng/articles/6045600.html 1:初始Linux命令 右击,开启终端,或者ctrl+alt[F1-F6]的 ...

  4. Python初探list

    今天要说一个新概念--list,中文可以翻译成列表,是用来处理一组有序项目的数据结构.想象一下你的购物清单.待办工作.手机通讯录等等,它们都可以看作是一个列表.说它是新概念也不算确切,因为我们之前已经 ...

  5. map映射巧用 A-B Problems

    A-B problem Description 大家都非常熟悉 A+B Problem! 题目看多了也有审美疲劳,于是我舍弃了,改用 A-B problem! 题目是这样的:给出一串数以及一个数字 C ...

  6. 20165206 2017-2018-2 《Java程序设计》第七周学习总结

    20165206 2017-2018-2 <Java程序设计>第七周学习总结 教材学习内容总结 MySqL:是世界上最流行的开源数据管理系统. 配置启动MySQL. 连接数据库:Conne ...

  7. mysql 简称

    一:DTS(Data Transformation Service) 数据转换服务 大多数组织都使用多种格式和多个位置来存储数据. 为了支持决策.改善系统性能或对现有系统进行升级,经常必须将数据从一个 ...

  8. 三 os模块

    os模块是与操作系统交互的一个接口 os.getcwd() 获取当前工作目录,即当前python脚本工作的目录路径 os.chdir("dirname") 改变当前脚本工作目录:相 ...

  9. 009-Python-面向对象

    1.面向对象: 1.1什么是类? 类:把一类事物的相同的特征和动作整合到一起就是类,类是一个抽象的概念: 1.2什么是对象? 对象:就是基于类而创建的一个具体事物(具体存在的)也是特征和动作整合到一起 ...

  10. Aws云服务EMR使用

    Aws云服务EMR使用 创建表结构 创建abc库下的abc_user_i表字段s3://abc-server/abc-emr/shell/ABC_USER_HIVE.q: EXTERNAL 指定为外部 ...