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. JavaEE-实验二 Java集合框架实验

    该博客仅专为我的小伙伴提供参考而附加,没空加上代码具体解析,望各位谅解 1.  使用类String类的分割split 将字符串  “Solutions to selected exercises ca ...

  2. linux 下载jdk 、maven、git

    jdk: wget --no-check-certificate --no-cookies --header "Cookie: oraclelicense=accept-secureback ...

  3. SweetAlert(弹出层插件)

    怀着非常.非常恼火的心情写下这个博文.我深深怀疑有一些人只会瞎粘贴复制别人的博文,自己试都不试就发布到网上,左右看的人想法,就此深通恶绝!! 废话不多说. SweetAlert是一个简洁好用的自制Al ...

  4. apache虚拟目录配置实例

    apache虚拟目录配置实例 一.首先,开启虚拟主机配置 在文件httpd.conf中找到: include conf/extra/httpd-vhosts.conf #开启 二.对httpd-vho ...

  5. 网站换VPS wdcp操作记录

    http://www.wdlinux.cn/bbs/thread-2795-1-1.html 分种情况1 从别的环境迁移到wdcp的环境2 从老的wdcp迁移到新的wdcp环境 对于第一个,没有较好的 ...

  6. (转)使用JMeter对秒杀示例进行性能测试

    背景 秒杀是我们ServiceComb开源团队以领域驱动设计(DDD)为背景,从零开始构建一个微服务架构的示例项目:在<秒杀开发历程>系列博文中提到它作为一个高并发压力场景的应用,采用了C ...

  7. python 并发编程 基于gevent模块实现并发的套接字通信

    之前线程池是通过操作系统切换线程,现在是程序自己控制,比操作系统切换效率要高 服务端 from gevent import monkey;monkey.patch_all() import geven ...

  8. tableau单机版安装

    参考: https://help.tableau.com/current/server-linux/zh-cn/requ.htm   先将服务器防火墙80级8850端口打开 临时关闭SELinux/防 ...

  9. Maven - Maven3实战学习笔记(3)使用maven构建Web应用

    1.jetty-maven-plugin自动化测试Web应用工具 <plugin> <groupId>org.mortbay.jetty</groupId> < ...

  10. java 不可变对象 final Collections guava 简单样例

    本地环境 jdk1.8 连接 Google Guava官方教程(中文版) journaldev 说明 java的final关键字大家都了解,但是final修饰的如果是引用类型,那么不可修改的其实只是重 ...