无聊学了一下珂朵莉树

珂朵莉树好哇,是可以维护区间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. sublime快捷键的使用

    Sublime text 3是码农最喜欢的代码编辑器,每天和代码打交道,必先利其器,掌握基本的代码编辑器的快捷键,能让你打码更有效率.刚开始可能有些生疏,只要花一两个星期坚持使用并熟悉这些常用的快捷键 ...

  2. win10ssh连接ubuntu服务器并本地绘图

    update @ 2018-11-07 00:36:38 用xrdp+tigervnc等的组合,可以使用原生unity桌面.具体教程见ubuntu日常使用指南 工具准备 win10上: xshell, ...

  3. PaperNotes Instance-Level Salient Object Segmentation

    title: PaperNotes Instance-Level Salient Object Segmentation comments: true date: 2017-12-20 13:53:1 ...

  4. https://www.cnblogs.com/zoro-robin/p/6110188.html

    https://www.cnblogs.com/zoro-robin/p/6110188.html https://blog.csdn.net/kongxx/article/details/65435 ...

  5. HDFS的一些配置文件修改

    sbin/start-dfs.sh 和 sbin/stop-dfs.sh 在第二行增加如下内容 HDFS_DATANODE_USER=root HDFS_DATANODE_SECURE_USER=hd ...

  6. Flink--将表转换为DataStream或DataSet

    A Table可以转换成a DataStream或DataSet.通过这种方式,可以在Table API或SQL查询的结果上运行自定义的DataStream或DataSet程序 将表转换为DataSt ...

  7. net core体系-web应用程序-4net core2.0大白话带你入门-7asp.net core日志组件(Logger和Nlog)

    asp.net core日志组件   日志介绍 Logging的使用 1. appsettings.json中Logging的介绍 Logging的配置信息是保存在appsettings.json配置 ...

  8. Codeforces 822E Liar dp + SA (看题解)

    Liar 刚开始感觉只要开个dp[ i ][ j ][ 0 / 1 ]表示处理了s的前 i 个用了 k 段, i 是否是最后一段的最后一个字符 的 t串最长匹配长度, 然后wa24, 就gg了.感觉这 ...

  9. Codeforces 1016G Appropriate Team 数论 FWT

    原文链接https://www.cnblogs.com/zhouzhendong/p/CF1016G.html 题目传送门 - CF1016G 题意 给定 $n,x,y$ ,以及一个含有 $n$ 个元 ...

  10. Codeforces 452E Three strings 字符串 SAM

    原文链接https://www.cnblogs.com/zhouzhendong/p/CF542E.html 题目传送门 - CF452E 题意 给定三个字符串 $s1,s2,s3$ ,对于所有 $L ...