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的更多相关文章

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

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

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

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

  3. 珂朵莉树(ODT)笔记

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

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

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

  5. 『珂朵莉树 Old Driver Tree』

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

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

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

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

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

  8. 题解 P3372 【【模板】线段树 1】(珂朵莉树解法)

    这道题可以用珂朵莉树做,但是由于数据比较不随机,而我也没有手写一颗平衡树,所以就被卡掉了,只拿了70分. 珂朵莉树是一种基于平衡树的(伪)高效数据结构. 它的核心操作是推平一段区间. 简而言之,就是把 ...

  9. 洛谷AT2342 Train Service Planning(思维,动态规划,珂朵莉树)

    洛谷题目传送门 神仙思维题还是要写点东西才好. 建立数学模型 这种很抽象的东西没有式子描述一下显然是下不了手的. 因为任何位置都以\(k\)为周期,所以我们只用关心一个周期,也就是以下数都在膜\(k\ ...

随机推荐

  1. java.util.MissingResourceException: Can't find resource for bundle oracle.sysman.db.rsc.LoginResourc

    http://blog.itpub.net/197458/viewspace-1055358/   oracle 10.2.0.4 windows 2003 X64 平台 系统安装EMCA正常.第一次 ...

  2. Duplicate property mapping of contactPhone found in

    启动的时候报Duplicate property mapping of contactPhone found in com....的错误,是因为在建立实体对象的时候,有字段重复了,有的是继承了父类的字 ...

  3. iOS开发--URL中汉字出现乱码

    NSURL *nurl=[[NSURL alloc] initWithString:[urlString stringByAddingPercentEscapesUsingEncoding:NSUTF ...

  4. Project Euler:Problem 61 Cyclical figurate numbers

    Triangle, square, pentagonal, hexagonal, heptagonal, and octagonal numbers are all figurate (polygon ...

  5. OFbiz实体引擎

    安全可靠的数据存储是数据管理战略的关键业务,OFbiz认真对待数据管理.不把全部繁琐和easy出错的数据管理任务留给应用开发人员.OFbiz在设计和实现阶段非常好的贯彻了这个理念. 实体引擎是数据库无 ...

  6. [Spring实战系列](19)Servlet不同版本号之间的差别

    1.   2.3版本号 2.3版本号 <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application ...

  7. web 开发之js---ajax 中的两种返回状态 xmlhttp.status和 xmlhttp.readyState

    (1)xmlhttp.status xmlHttp.status的值(HTTP状态表)0**:未被始化 1**:请求收到,继续处理 2**:操作成功收到,分析.接受 3**:完成此请求必须进一步处理 ...

  8. unable to instantiate activity...

    Activity跳转到Activity,后来由于项目需要将第二个Activity改成继承FragmentActivity,跳转报错...无法初始化Activity,找不到class云云.. 最后是将b ...

  9. How can I pass data from Flask to JavaScript in a template?

    https://stackoverflow.com/questions/11178426/how-can-i-pass-data-from-flask-to-javascript-in-a-templ ...

  10. 在调试状态查看DateTable里的数据信息