ODT模板题,ODT适合随机数据下具有维护区间推平操作的序列维护题目,时间复杂度较为玄学。。

代码如下

#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()
using namespace std;
const int maxn=1e5+10;
const int mod=1e9+7;
typedef long long LL;
LL fpow(LL a,LL b,LL c){
LL ret=1%c;
for(;b;b>>=1,a=a*a%c)if(b&1)ret=ret*a%c;
return ret;
} int n,m;
LL seed,vmax;
LL rnd(){
LL ret=seed;
seed=(seed*7+13)%mod;
return ret;
}
struct node{
int l,r;
mutable LL val;
node(int x=0,int y=0,LL z=0):l(x),r(y),val(z){}
bool operator<(const node &rhs)const{
return this->l<rhs.l;
}
};
set<node> s;
auto split(int pos){
auto it=s.lower_bound(node(pos));
if(it!=s.end()&&it->l==pos)return it;
--it;
int l=it->l,r=it->r;
LL val=it->val;
s.erase(it);
s.insert(node(l,pos-1,val));
return s.insert(node(pos,r,val)).first;
}
void add(int l,int r,LL x){
auto itr=split(r+1),itl=split(l);
for(auto it=itl;it!=itr;it++)it->val+=x;
}
void assign(int l,int r,LL x){
auto itr=split(r+1),itl=split(l);
s.erase(itl,itr);
s.insert(node(l,r,x));
}
LL kth(int l,int r,int k){
auto itr=split(r+1),itl=split(l);
vector<pair<LL,int>> v;v.clear();
for(auto it=itl;it!=itr;it++){
v.pb(mp(it->val,it->r-it->l+1));
}
sort(all(v));
for(auto p:v){
k-=p.second;
if(k<=0)return p.first;
}
return -1;
}
LL sum(int l,int r,int x,int y){
auto itr=split(r+1),itl=split(l);
LL ret=0;
for(auto it=itl;it!=itr;it++){
ret=(ret+fpow(it->val%y,x,y)*(it->r-it->l+1)%y)%y;
}
return ret;
} int main(){
scanf("%d%d%lld%lld",&n,&m,&seed,&vmax);
for(int i=1;i<=n;i++){
s.insert(node(i,i,rnd()%vmax+1));
}
s.insert(node(n+1,n+1,0)); while(m--){
int opt=rnd()%4+1,l=rnd()%n+1,r=rnd()%n+1,x,y;
if(l>r)swap(l,r);
if(opt==3)x=rnd()%(r-l+1)+1;
else x=rnd()%vmax+1;
if(opt==4)y=rnd()%vmax+1;
if(opt==1)add(l,r,x);
else if(opt==2)assign(l,r,x);
else if(opt==3)printf("%lld\n",kth(l,r,x));
else if(opt==4)printf("%lld\n",sum(l,r,x,y));
} return 0;
}

【CF896C】Willem, Chtholly and Seniorious的更多相关文章

  1. 【题解】Willem, Chtholly and Seniorious Codeforces 896C ODT

    Prelude ODT这个东西真是太好用了,以后写暴力骗分可以用,写在这里mark一下. 题目链接:ヽ(✿゚▽゚)ノ Solution 先把原题解贴在这里:(ノ*・ω・)ノ 简单地说,因为数据是全部随 ...

  2. 【Luogu】P3933 Chtholly Nota Seniorious

    [题意]将n*m矩阵分成两个区域,要求满足一定条件,求两区域内部极差较大值最小.n,m<=2000 [算法]二分 [题解]极差的数值满足单调性,所以考虑二分极差. 对于给定的极差,将所有数值排序 ...

  3. 【Cf #449 C】Willem, Chtholly and Seniorious(set维护线段)

    这里介绍以个小$trick$,民间流传为$Old Driver Tree$,实质上就是$set$维护线段. 我们将所有连续一段权值相同的序列合并成一条线段,扔到$set$里去,于是$set$里的所有线 ...

  4. Willem, Chtholly and Seniorious

    Willem, Chtholly and Seniorious https://codeforces.com/contest/897/problem/E time limit per test 2 s ...

  5. CF&&CC百套计划1 Codeforces Round #449 C. Willem, Chtholly and Seniorious (Old Driver Tree)

    http://codeforces.com/problemset/problem/896/C 题意: 对于一个随机序列,执行以下操作: 区间赋值 区间加 区间求第k小 区间求k次幂的和 对于随机序列, ...

  6. 【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 ...

  7. 题解 CF896C 【Willem, Chtholly and Seniorious】

    貌似珂朵莉树是目前为止(我学过的)唯一一个可以维护区间x次方和查询的高效数据结构. 但是这玩意有个很大的毛病,就是它的高效建立在数据随机的前提下. 在数据随机的时候assign操作比较多,所以它的复杂 ...

  8. 【模板】珂朵莉树(ODT)(Codeforces 896C Willem, Chtholly and Seniorious)

    题意简述 维护一个数列,支持区间加,区间赋值,区间求第k小,区间求幂和 数据随机 题解思路 ODT是一种基于std::set的暴力数据结构. 每个节点对应一段区间,该区间内的数都相等. 核心操作spl ...

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

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

随机推荐

  1. WPF图标拾取器

    <Grid x:Name="LayoutRoot"> <Border BorderBrush="> <Border.Effect> & ...

  2. 阶段3 2.Spring_04.Spring的常用注解_2 常用IOC注解按照作用分类

    注解配置和xml的配置要实现的功能都是一样的.都是要降低程序间的耦合,只不过配置的形式不一样 打包方式改成jar 加入spring 的依赖 复制之前的代码过来 复制到我们新建的工程里 resurces ...

  3. GitHub Port 443 Refused

    最近在本地Github上传和更新远程仓库的时候老是显示 GitHub - failed to connect to github 443 windows/ Failed to connect to g ...

  4. Java Stream流排序null以及获取指定条数数据

    Java8的Stream流的一些用法, //排序 carerVehEntityList = carerVehEntityList.stream().sorted( Comparator.compari ...

  5. Node.js使用redis进行订阅发布管理

    redis NPM 官方介绍地址:https://www.npmjs.com/package/redis let redis = require('redis'); let subscriber; l ...

  6. 【转】mysql用sql实现split函数

    关键词:mysql split mysql根据逗号将一行数据拆分成多行数据1.原始数据演示 2.处理结果演示 3.sql语句 SELECT a.id , a.NAME , substring_inde ...

  7. 【2019CSP-S游记】咕了好久了撒

    对,证书已经发下来了,我才想起来写游记(虽然我个蒟蒻明明就是在写反思) 终于和父母商议好了以后怎么办,顺带找了一下班主任,在机房的电脑敲出来的(我来找教练,然后完全没找着,淦) 79分,众所周知CCF ...

  8. 洛谷 P3388 割点(割顶) 题解

    题面:     割点性质:     节点 u 如果是割点,当且仅当存在 u 的一个子树,子树中没有连向 u 的祖先的边(返祖边).     换句话说,如果对于一个点u,它的子节点是v,如果low[v] ...

  9. 【优质blog、网址】置顶

    一.大公司等技术blog:   blog1: http://blog.csdn.net/mfcing/article/details/51577173 blog2: http://blog.csdn. ...

  10. [Vue] vue的一些面试题4

    1.你知道 nextTick 的原理吗? 用法:在下次 DOM 更新循环结束之后执行延迟回调.在修改数据之后立即使用这个方法,获取更新后的 DOM. 异步更新队列提到 DOM 的更新是异步执行的,只要 ...