[Codeforces896C] Willem, Chtholly and Seniorious (ODT-珂朵莉树)
无聊学了一下珂朵莉树
珂朵莉树好哇,是可以维护区间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-珂朵莉树)的更多相关文章
- CF896C Willem, Chtholly and Seniorious(珂朵莉树)
中文题面 珂朵莉树的板子……这篇文章很不错 据说还有奈芙莲树和瑟尼欧里斯树…… 等联赛考完去学一下(逃 //minamoto #include<bits/stdc++.h> #define ...
- [数据结构]ODT(珂朵莉树)实现及其应用,带图
[数据结构]ODT(珂朵莉树)实现及其应用,带图 本文只发布于博客园,其他地方若出现本文均是盗版 算法引入 需要一种这样的数据结构,需要支持区间的修改,区间不同值的分别操作. 一般的,我们会想到用线段 ...
- ODT珂朵莉树
关于ODT,据说是毒瘤lxl发明的,然后毒瘤鱼鱼因为我用ODT误导人D了我一回-- 这是一种基于 \(set\) 的暴力数据结构. 在使用时请注意,没看见这2东西千万别用-- 1.保证数据随机 2.有 ...
- ODT 珂朵莉树 入门
#include<iostream> #include<stdio.h> #include<string.h> #include<algorithm> ...
- 珂朵莉树(Chtholly Tree)学习笔记
珂朵莉树(Chtholly Tree)学习笔记 珂朵莉树原理 其原理在于运用一颗树(set,treap,splay......)其中要求所有元素有序,并且支持基本的操作(删除,添加,查找......) ...
- 「学习笔记」珂朵莉树 ODT
珂朵莉树,也叫ODT(Old Driver Tree 老司机树) 从前有一天,珂朵莉出现了... 然后有一天,珂朵莉树出现了... 看看图片的地址 Codeforces可还行) 没错,珂朵莉树来自Co ...
- [转]我的数据结构不可能这么可爱!——珂朵莉树(ODT)详解
参考资料: Chtholly Tree (珂朵莉树) (应某毒瘤要求,删除链接,需要者自行去Bilibili搜索) 毒瘤数据结构之珂朵莉树 在全是珂学家的珂谷,你却不知道珂朵莉树?来跟诗乃一起学习珂朵 ...
- 珂朵莉树(ODT)笔记
珂朵莉树,又叫老司机树($Old\, Driver \, Tree$) 是一种暴力出奇迹,就怕数据不随机的数据结构. 适用 需要用线段树维护一些区间修改的信息…… 像是区间赋值(主要),区间加…… 原 ...
- 『珂朵莉树 Old Driver Tree』
珂朵莉树 珂朵莉树其实不是树,只是一个借助平衡树实现的数据结构,主要是对于有区间赋值的数据结构题,可以用很暴力的代码很高效地完成任务,当然这是建立在数据随机的基础上的. 即使数据不是随机的,写一个珂朵 ...
随机推荐
- Python模拟人猜数过程(折半查找)
import random# (0,1000)随机产生一个数key = random.randint(1,1000)# 用来统计猜的次数count = 0 # 定义一个折半查找的函数def BinSe ...
- bootstrap 三个文件的引入
<!-- 新 Bootstrap 核心 CSS 文件 --> <link rel="stylesheet" href="//cdn.bootcss.co ...
- The.Glory.of.Innovation 创新之路2科学基石
犹太民族很早就确立了他们的生存法则:资源.土地,以及一切有形的东西都会消失,一个人最重要的财富是自己的头脑.是知识.是创造. 有些选择是被动的,有些选择是主动的,一旦决心要把技术变成自己的,独立的 ...
- idea svn配置报错:Can't use Subversion command line client:svn
1. 在Intellij IDEA里checkout东西时出先这个错误提示:Can't use Subversion command line client:svnSubversion command ...
- 使用 cacti 监控 windows 服务器硬盘的 I/O 状况
https://blog.csdn.net/m0_37814112/article/details/80742433
- Javascript面向对象编程:非构造函数的继承
今天是最后一个部分,介绍不使用构造函数实现"继承". 一.什么是"非构造函数"的继承? 比如,现在有一个对象,叫做"中国人". var Ch ...
- Linux查找当前目录5天的文件并打包
find . -name "*.sh" -mtime -5 |xargs tar zcvf /tmp/log.tar.gz 解释: *.sh是查找以.sh结尾的文件,也可以是其他如 ...
- CAS和ABA问题
一.引言 ...
- mysql-索引-日志
索引:基于元数据之上的在某个字段或多个字段取出来,索引是加速读操作的,但对写操作时有副作用的 BTree 索引:抽取出来重新排序,是左前缀索引每一个叶子结点到根结点的距离相同: 哈希索引:基于键查找值 ...
- 使用VMware通过vmdk文件创建XP虚拟机
一.打开VMware workstation10,转到主页,选择“创建新的虚拟机”,然后选择“自定义(高级)”选项 二.虚拟机硬件兼容性选择默认兼容10.0模式,下一步之后,选择“稍后安装操作系统” ...