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\ ...
随机推荐
- 【scrapy】Item Pipeline
After an item has been scraped by a spider,it is sent to the Item Pipeline which process it through ...
- Python 基础语法(和Java相比)
Python变量和数据类型 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 ...
- react 开发 PC 端项目(一)项目环境搭建 及 处理 IE8 兼容问题
步骤一:项目环境搭建 首先,你不应该使用 React v15 或更高版本.使用仍然支持 IE8 的 React v0.14 即可. 技术选型: 1.react@0.14 2.bootstrap3 3. ...
- poj 1426 Find The Multiple ( BFS+同余模定理)
Find The Multiple Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 18390 Accepted: 744 ...
- 鸡肋的JdbcRDD
今天准备将mysql的数据倒腾到RDD.非常早曾经就知道有一个JdbcRDD.就想着使用一下,结果发现却是鸡肋一个. 首先,看看JdbcRDD的定义: * An RDD tha ...
- 【JAVA】java中Future、FutureTask的使用
如今的系统基本都是分布式的,各个系统各司其职的,不可能一个系统干了全部系统的事. 所以系统之间的交互就越来越多了.那么系统之间的交互仅仅有通过网络来交互了,而网络必定会存在延时的情况. 比方A系统的一 ...
- WAMP的端口修改
wamp集成了开源的利器mysql+apache+php,真的是有越来越火的趋势了,可是有些人,安装php的集成开发环境WAMP的时候,出现端口被占用了,无法连接服务器的时候, 这时,如果要修改WAM ...
- 20170111 ABAP技术小结(全半角转换)
DATA: it_po LIKE it_alv OCCURS 0 WITH HEADER LINE.************************************************** ...
- Unable to resolve dependency for ':app@debug/compileClasspath': Could not resolve com.android.support.constraint:constraint-layout:1.1.0. Could not resolve com.android.support.constraint:constraint-l
File->Settings->Build, Execution, Deployment->Gradle->取消选中 Offline work 按钮
- CMake使用总结【转】
本文转载自:https://www.mawenbao.com/note/cmake.html 总结CMake的常用命令,并介绍有用的CMake资源. CMake意为cross-platform mak ...