【CF896C】Willem, Chtholly and Seniorious
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的更多相关文章
- 【题解】Willem, Chtholly and Seniorious Codeforces 896C ODT
Prelude ODT这个东西真是太好用了,以后写暴力骗分可以用,写在这里mark一下. 题目链接:ヽ(✿゚▽゚)ノ Solution 先把原题解贴在这里:(ノ*・ω・)ノ 简单地说,因为数据是全部随 ...
- 【Luogu】P3933 Chtholly Nota Seniorious
[题意]将n*m矩阵分成两个区域,要求满足一定条件,求两区域内部极差较大值最小.n,m<=2000 [算法]二分 [题解]极差的数值满足单调性,所以考虑二分极差. 对于给定的极差,将所有数值排序 ...
- 【Cf #449 C】Willem, Chtholly and Seniorious(set维护线段)
这里介绍以个小$trick$,民间流传为$Old Driver Tree$,实质上就是$set$维护线段. 我们将所有连续一段权值相同的序列合并成一条线段,扔到$set$里去,于是$set$里的所有线 ...
- Willem, Chtholly and Seniorious
Willem, Chtholly and Seniorious https://codeforces.com/contest/897/problem/E time limit per test 2 s ...
- CF&&CC百套计划1 Codeforces Round #449 C. Willem, Chtholly and Seniorious (Old Driver Tree)
http://codeforces.com/problemset/problem/896/C 题意: 对于一个随机序列,执行以下操作: 区间赋值 区间加 区间求第k小 区间求k次幂的和 对于随机序列, ...
- 【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 ...
- 题解 CF896C 【Willem, Chtholly and Seniorious】
貌似珂朵莉树是目前为止(我学过的)唯一一个可以维护区间x次方和查询的高效数据结构. 但是这玩意有个很大的毛病,就是它的高效建立在数据随机的前提下. 在数据随机的时候assign操作比较多,所以它的复杂 ...
- 【模板】珂朵莉树(ODT)(Codeforces 896C Willem, Chtholly and Seniorious)
题意简述 维护一个数列,支持区间加,区间赋值,区间求第k小,区间求幂和 数据随机 题解思路 ODT是一种基于std::set的暴力数据结构. 每个节点对应一段区间,该区间内的数都相等. 核心操作spl ...
- [CF896C]Willem, Chtholly and Seniorious(珂朵莉树)
https://www.cnblogs.com/WAMonster/p/10181214.html 主要用于支持含有较难维护的区间操作与查询的问题,要求其中区间赋值操作(assign())是纯随机的. ...
随机推荐
- iOS charts CombinedChartView First and last bars are shown half only
charts 使用CombinedChartView 绘图时,发现第一个和最后一个bar只能显示一半的问题,解决方法: ChartXAxis *xAxis = chartView.xAxis; xAx ...
- Elastic Stack学习
原文链接 Elastic Stack简称ELK,在本教程你将学习如何快速搭建并运行Elastic Stack. 首先你要安装核心开源产品: Elasticsearch: Kibana: Beats: ...
- golang remote debug和docker debug
在编写 Go 代码的时候,因为很多时候都是需要调试服务器上的代码的,作为一个年长的工程师,肯定不能用 log.Printf 来调试问题,所以我选择了 delve 这个工具,通过 delve 我可以像本 ...
- js中的break,continue和return的用法及区别
为什么要说个?好像很简单,但是我也会迷糊,不懂有时候为什么要用return,然而break和continue也经常和他放在一起. 所以就一起来说一说,这三个看起来很简单,却常常会出错的关键词的具体用法 ...
- LeetCode.914-一副牌中的X(X of a Kind in a Deck of Cards)
这是悦乐书的第352次更新,第377篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第214题(顺位题号是914).在一副牌中,每张牌上都写有一个整数. 当且仅当您可以选择 ...
- ROS系统的安装以及卸载
ROS系统的安装 ROS系统的安装方式有两种,通过软件源和源码编译安装.软件源安装只需要通过简单的命令,因此,我们使用软件源来安装ROS 配置系统软件源 打开Ubuntu软件中心的软件源配置界面,勾选 ...
- webpack的插件 http-webpack-plugin。 webpack-dev-server
自动的生成: bundle.js 和 index.html 在该项目的目录下:npm init -yes npm install vue -D npm install webpack@3.12.0 ...
- Java中的模板设计模式,太实用了!
顾名思义,模板设计模式就是将许多公用的常用的代码封装成一个模板,我们只需要实现不同的业务需求的代码,然后和模板组合在一起,那么就得到完整的逻辑. 在我们的日常开发中,常用的模板模式有两种实现方式:继承 ...
- selenium与页面交互之二:webelement类的属性
webelement类的属性如下: element.size() 获取元素的大小 element.tag_name() 获取元素的HTML标签名称 element.text() 获取元素的文本 ...
- Codeforces 1209F. Koala and Notebook
传送门 考虑到达某个点时的数长度要尽量短,那么可以把边长看成此边十进制下的位数 那么对于最终答案我们只要考虑最短路 $DAG$ 上的情况 又发现其实边长都很小,所以可以暴力拆边,把边权都拆成 $1$, ...