[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』
珂朵莉树 珂朵莉树其实不是树,只是一个借助平衡树实现的数据结构,主要是对于有区间赋值的数据结构题,可以用很暴力的代码很高效地完成任务,当然这是建立在数据随机的基础上的. 即使数据不是随机的,写一个珂朵 ...
随机推荐
- salt上编写了备份日志的脚本
我在salt上编写了备份日志的脚本,在/opt/CardServer下的主程序目录只保留当天的日志,/opt/log_del目录会保存7天的日志.salt * state.sls script.log ...
- 应用程序池--IIS最大工作进程数
IIS 6.0允许将应用程序池配置成一个Web园(Web Garden).要理解Web园的概念,可以设想这样一种情形:假设有一个IIS 5.0服务器和三个Web网站,每一个Web网站运行着相同的应用程 ...
- vi/vim键盘对应图
来源:http://www.runoob.com/linux/linux-vim.html
- MQ消息队列之MSMQ
主要参考文章: 消息队列(Message Queue)简介及其使用
- 最大子数组(I, II, III,IV,V)和最大子数组乘积 (动态规划)
I 找一个连续最大子数组,sum加到nums[i], 如果前面子数组和<0则舍去,从头开始. class Solution { public: /** * @param nums: A list ...
- Maya闪退
电脑上装的Maya2015突然就打不开了,窗口闪一下就关闭,也没有任何提示. 将15卸载装了Maya2016还是一样. 再彻底卸载16,装了15,还不行... 将系统环境变量中PYTHONHOME和P ...
- alpha冲刺8/10
目录 摘要 团队部分 个人部分 摘要 队名:小白吃 组长博客:hjj 作业博客:冲刺倒计时之8 团队部分 后敬甲(组长) 过去两天完成了哪些任务 首页重新设计 课程时间线确定 答辩准备 接下来的计划 ...
- NEST 中的距离单位
Distance units Version: 5.x 英文原文地址:Distance units 当我们需要指定距离时(地理位置查询),可以使用一个双精度的数字来表示,它的默认单位是米(meters ...
- Python mysql sql基本操作
一.创建数据库,编码格式为utf-8 create database s12day9 charset utf8; 二.表操作 1.创建表 use s12day9; create table stude ...
- playbook role应用
参考: ansible中文权威指南 1. 动态Include 结合when等判断,在满足某个条件的时候加载. - include: test.yml when: ...... handler 中也可以 ...