中文题面

珂朵莉树的板子……这篇文章很不错

据说还有奈芙莲树和瑟尼欧里斯树……

等联赛考完去学一下(逃

 //minamoto
#include<bits/stdc++.h>
#define IT set<node>::iterator
#define ll long long
using namespace std;
const int mod7=1e9+,mod9=1e9+,N=1e5+;
ll ksm(ll a,ll b,ll mod){
ll res=;a%=mod;
while(b){
if(b&) res=res*a%mod;
a=a*a%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){}
inline bool operator<(const node &b)const
{return l<b.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 itr=split(r+),itl=split(l);
for(;itl!=itr;++itl) itl->v+=val;
}
void assign(int l,int r,ll val=){
IT itr=split(r+),itl=split(l);
s.erase(itl,itr),s.insert(node(l,r,val));
}
ll rk(int l,int r,int k){
vector<pair<ll,int> > mp;
IT itr=split(r+),itl=split(l);
mp.clear();
for(;itl!=itr;++itl)
mp.push_back(pair<ll,int>(itl->v,itl->r-itl->l+));
sort(mp.begin(),mp.end());
for(vector<pair<ll,int> >::iterator it=mp.begin();it!=mp.end();++it){
k-=it->second;
if(k<=) return it->first;
}
return -1ll;
}
ll sum(int l,int r,int ex,int mod){
IT itr=split(r+),itl=split(l);ll res=;
for(;itl!=itr;++itl)
res=(res+1ll*(itl->r-itl->l+)*ksm(itl->v,ex,mod))%mod;
return res;
}
int n,m;ll seed,vmax;
ll rnd(){
ll res=seed;seed=(seed*+)%mod7;
return res;
}
ll a[N];
int main(){
// freopen("testdata.in","r",stdin);
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) swap(l,r);int x,y;
if(op==) x=int(rnd()%(r-l+))+;
else x=int(rnd()%vmax)+;
if(op==) y=int(rnd()%vmax)+;
switch(op){
case :add(l,r,x);break;
case :assign(l,r,x);break;
case :printf("%lld\n",rk(l,r,x));break;
case :printf("%lld\n",sum(l,r,x,y));break;
}
}
return ;
}

CF896C Willem, Chtholly and Seniorious(珂朵莉树)的更多相关文章

  1. [CF896C]Willem, Chtholly and Seniorious(珂朵莉树)

    https://www.cnblogs.com/WAMonster/p/10181214.html 主要用于支持含有较难维护的区间操作与查询的问题,要求其中区间赋值操作(assign())是纯随机的. ...

  2. [Codeforces896C] Willem, Chtholly and Seniorious (ODT-珂朵莉树)

    无聊学了一下珂朵莉树 珂朵莉树好哇,是可以维护区间x次方和查询的高效数据结构. 思想大致就是一个暴力(相对而言)的树形数据结构 lxl毒瘤太强了,发明了ODT算法(Old Driver Tree老司机 ...

  3. 【ODT】cf896C - Willem, Chtholly and Seniorious

    仿佛没用过std::set Seniorious has n pieces of talisman. Willem puts them in a line, the i-th of which is ...

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

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

  5. [CF896C]Willem, Chtholly and Seniorious

    题目大意:有$n$个数,有$m$次$4$种操作: l r x :将$[l,r]$区间所有数加上$x$ l r x :将$[l,r]$区间所有数变成$x$ l r k :输出$[l,r]$区间第$k$大 ...

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

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

  7. 『珂朵莉树 Old Driver Tree』

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

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

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

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

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

随机推荐

  1. poj 3041——Asteroids

    poj       3041——Asteroids Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 22604   Accep ...

  2. Palindrome Partitioning (回文子串题)

    Given a string s, partition s such that every substring of the partition is a palindrome. Return all ...

  3. Trac常用插件描述! - wang_xf的Study home - 博客频道 - CSDN.NET

    Trac常用插件描述! - wang_xf的Study home - 博客频道 - CSDN.NET

  4. linux 查找目录下的文件内容并替换(批量)

    2.sed和grep配合 命令:sed -i s/yyyy/xxxx/g `grep yyyy -rl --include="*.txt" ./` 作用:将当前目录(包括子目录)中 ...

  5. UVA 4857 Halloween Costumes 区间背包

    题目链接:https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_ ...

  6. 【C】字符串,字符和字节(C与指针第9章)

    C语言没有一种显式的数据类型是字符串的. C语言存储字符串:字符串常量(不能改动).字符数组或动态分配的内存(能够改动) *************************************** ...

  7. Android消息机制1-Handler(Java层)(转)

    转自:http://gityuan.com/2015/12/26/handler-message-framework/ 相关源码 framework/base/core/java/andorid/os ...

  8. 释怀我的诺亚尔 不用EF框架,完成完美实体映射,且便于维护!(AutoMapper,petapoco)

    释怀我的诺亚尔   不用EF框架,完成完美实体映射,且便于维护!(AutoMapper,petapoco) 最近,需要搭建一个新项目,在需求分析时确定数据库中需要创建多个存储过程.所以如果还是用原来E ...

  9. cocos2d-x调用scheduleUpdate()不执行update()方法的解决办法【转】

    原文地址:http://blog.csdn.net/somestill/article/details/9699377 前两天使用到每帧都更新动画的scheduleUpdate()方法,但通过cclo ...

  10. Codeforces Round #310 (Div. 1) C. Case of Chocolate (线段树)

    题目地址:传送门 这题尽管是DIV1的C. . 可是挺简单的. .仅仅要用线段树分别维护一下横着和竖着的值就能够了,先离散化再维护. 每次查找最大的最小值<=tmp的点,能够直接在线段树里搜,也 ...