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. Dart 基本语法

    ?? // 如果b为null则赋值,否则保持原样 b ??= value; 级联符号.. querySelector('#confirm') // Get an object. ..text = 'C ...

  2. mysql主从复制架构配置

    第一个mysql1.下载mysql,解压,移动解压后的目录到指定目录下. 如:mv /usr/local/src/mysql-5.1.. /usr/local/mysql 创建mysql用户, use ...

  3. Unity3D 旋转

    Unity有两种设置物体旋转的方式,一种时用Rotate()函数来旋转,另一种时直接构造目标Quaternion来直接赋予rotation. 好吧,不知到写什么,各种旋转和unity2D差不多.在国内 ...

  4. 【Deep Learning Nanodegree Foundation笔记】第 7 课:NEURAL NETWORKS Intro to Neural Networks

    In this lesson, you'll dive deeper into the intuition behind Logistic Regression and Neural Networks ...

  5. htc 手机

    是否解锁locked unlocked 然后刷入REC

  6. 小程序图片预览 wx.previewImage

      list: [ 'http://img5.imgtn.bdimg.com/it/u=3300305952,1328708913&fm=26&gp=0.jpg', 'http://i ...

  7. ucloud建新主机

    系统盘默认20G,可调到40不增加费用.需建好主机后关机才能更改. root密码按统一的设 设好主机名,选好分组

  8. [转帖]目标管理的S.M.A.R.T.理念

    目标管理的S.M.A.R.T.理念 https://blog.csdn.net/gehantao/article/details/1593510     目标管理(MBO)是一种管理战略,它使用的是S ...

  9. Flink初探-为什么选择Flink

    本文主要记录一些关于Flink与storm,spark的区别, 优势, 劣势, 以及为什么这么多公司都转向Flink. What Is Flink 一个通俗易懂的概念: Apache Flink 是近 ...

  10. POJ 2955 Brackets 区间DP 入门

    dp[i][j]代表i->j区间内最多的合法括号数 if(s[i]=='('&&s[j]==')'||s[i]=='['&&s[j]==']') dp[i][j] ...