【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 an integer ai.
In order to maintain it, Willem needs to perform m operations.
There are four types of operations:
- 1 l r x: For each i such that l ≤ i ≤ r, assign ai + x to ai.
- 2 l r x: For each i such that l ≤ i ≤ r, assign x to ai.
- 3 l r x: Print the x-th smallest number in the index range [l, r], i.e. the element at the x-th position if all the elements ai such that l ≤ i ≤ r are taken and sorted into an array of non-decreasing integers. It's guaranteed that 1 ≤ x ≤ r - l + 1.
- 4 l r x y: Print the sum of the x-th power of ai such that l ≤ i ≤ r, modulo y, i.e.
.
Input
The only line contains four integers n, m, seed, vmax (1 ≤ n, m ≤ 105, 0 ≤ seed < 109 + 7, 1 ≤ vmax ≤ 109).
The initial values and operations are generated using following pseudo code:
def rnd(): ret = seed
seed = (seed * 7 + 13) mod 1000000007
return ret for i = 1 to n: a[i] = (rnd() mod vmax) + 1 for i = 1 to m: op = (rnd() mod 4) + 1
l = (rnd() mod n) + 1
r = (rnd() mod n) + 1 if (l > r):
swap(l, r) if (op == 3):
x = (rnd() mod (r - l + 1)) + 1
else:
x = (rnd() mod vmax) + 1 if (op == 4):
y = (rnd() mod vmax) + 1
Here op is the type of the operation mentioned in the legend.
Output
For each operation of types 3 or 4, output a line containing the answer.
题目分析
ODT的入门例题。
ODT实际上是将区间缩成点,用平衡树来维护区间的过程。这个东西的“复杂度”只能够依赖于数据随机。
具体可以参考:【毒瘤Warning】Chtholly Tree珂朵莉树详解
#include<bits/stdc++.h>
typedef long long ll;
const int maxn = ; struct node
{
int l,r;
mutable ll val;
node(int a=, int b=, ll c=):l(a),r(b),val(c) {}
bool operator < (node a) const
{
return l < a.l;
}
};
typedef std::set<node>::iterator itr;
int n,m,p,seed,vmax,a[maxn];
std::set<node> s; int rand()
{
int ret = seed;
seed = (seed*7ll+)%;
return ret;
}
ll qmi(ll a, ll b)
{
ll ret = ;
for (a%=p; b; b>>=,a=1ll*a*a%p)
if (b&) ret = 1ll*ret*a%p;
return ret;
}
itr split(int pos)
{
itr loc = s.lower_bound(node(pos));
if (loc!=s.end()&&(*loc).l==pos) return loc;
--loc;
int l = (*loc).l, r = (*loc).r;
ll val = (*loc).val;
s.erase(loc);
s.insert(node(l, pos-, val));
return s.insert(node(pos, r, val)).first;
}
void merge(int l, int r, int val)
{
itr rpos = split(r+), lpos = split(l);
s.erase(lpos, rpos);
s.insert(node(l, r, val));
}
void modify(int l, int r, int val)
{
itr rpos = split(r+), lpos = split(l);
for (; lpos!=rpos; ++lpos) (*lpos).val += val;
}
ll getRank(int l, int r, int k)
{
itr rpos = split(r+), lpos = split(l);
std::vector<std::pair<ll, int> > mp;
for (; lpos!=rpos; ++lpos)
mp.push_back(std::make_pair((*lpos).val, (*lpos).r-(*lpos).l+));
std::sort(mp.begin(), mp.end());
for (int i=,mx=mp.size(); i<mx; i++)
{
k -= mp[i].second;
if (k <= ) return mp[i].first;
}
return -;
}
int calc(int l, int r, int x)
{
int ret = ;
itr rpos = split(r+), lpos = split(l);
for (; lpos!=rpos; ++lpos)
ret = (ret+1ll*qmi((*lpos).val, x)*((*lpos).r-(*lpos).l+)%p)%p;
return ret;
}
int main()
{
scanf("%d%d%d%d",&n,&m,&seed,&vmax);
for (int i=; i<=n; i++)
{
a[i] = rand()%vmax+;
s.insert(node(i, i, a[i]));
}
s.insert(node(n+, n+, ));
for (int i=,x; i<=m; i++)
{
int opt = rand()%+, l = rand()%n+, r = rand()%n+;
if (l > r) std::swap(l, r);
if (opt==) x = rand()%(r-l+)+;
else x = (rand()%vmax)+;
if (opt==) modify(l, r, x);
else if (opt==) merge(l, r, x);
else if (opt==) printf("%lld\n",getRank(l, r, x));
else{
p = rand()%vmax+;
printf("%d\n",calc(l, r, x));
}
}
return ;
}
END
【ODT】cf896C - Willem, Chtholly and Seniorious的更多相关文章
- cf896C. Willem, Chtholly and Seniorious(ODT)
题意 题目链接 Sol ODT板子题.就是用set维护连续段的大暴力.. 然鹅我抄的板子本题RE提交AC??.. 具体来说,用50 50 658073485 946088556这个数据测试下面的代码, ...
- [CF896C]Willem, Chtholly and Seniorious(珂朵莉树)
https://www.cnblogs.com/WAMonster/p/10181214.html 主要用于支持含有较难维护的区间操作与查询的问题,要求其中区间赋值操作(assign())是纯随机的. ...
- [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$大 ...
- CF896C Willem, Chtholly and Seniorious(珂朵莉树)
中文题面 珂朵莉树的板子……这篇文章很不错 据说还有奈芙莲树和瑟尼欧里斯树…… 等联赛考完去学一下(逃 //minamoto #include<bits/stdc++.h> #define ...
- Willem, Chtholly and Seniorious
Willem, Chtholly and Seniorious https://codeforces.com/contest/897/problem/E time limit per test 2 s ...
- 【CF896E】Welcome home, Chtholly 暴力+分块+链表
[CF896E]Welcome home, Chtholly 题意:一个长度为n的序列ai,让你支持两种操作: 1.l r x:将[l,r]中ai>x的ai都减去x.2.l r x:询问[l,r ...
- CF&&CC百套计划1 Codeforces Round #449 C. Willem, Chtholly and Seniorious (Old Driver Tree)
http://codeforces.com/problemset/problem/896/C 题意: 对于一个随机序列,执行以下操作: 区间赋值 区间加 区间求第k小 区间求k次幂的和 对于随机序列, ...
- 【题解】Willem, Chtholly and Seniorious Codeforces 896C ODT
Prelude ODT这个东西真是太好用了,以后写暴力骗分可以用,写在这里mark一下. 题目链接:ヽ(✿゚▽゚)ノ Solution 先把原题解贴在这里:(ノ*・ω・)ノ 简单地说,因为数据是全部随 ...
- 【模板】珂朵莉树(ODT)(Codeforces 896C Willem, Chtholly and Seniorious)
题意简述 维护一个数列,支持区间加,区间赋值,区间求第k小,区间求幂和 数据随机 题解思路 ODT是一种基于std::set的暴力数据结构. 每个节点对应一段区间,该区间内的数都相等. 核心操作spl ...
随机推荐
- OneDrive撸5T硬盘空间教程
注意:要注册多个账户获取网盘的,用无痕模式打开临时教育邮箱网址.打开之后不要关闭,等会用来接收验证码. 1.需要office 365注册这时候需要教育邮箱: 临时教育邮箱:http://sysu.ed ...
- JEECMS站群管理系统-- Jeecms项目导入myeclipse
1.在myeclipse中新建一个项目jeecms,将服务器中jeecms项目下web-inf文件夹下内容拷到新建项目中 解压缩jeecms-3.0.2-final-src,在src文件夹下会看到有三 ...
- C#操作Excel报错:服务器出现意外情况。
C#操作Excel表格时,如遇以下错误: 服务器出现意外情况.(异常来自 HRESULT:0x80010105(RPC_E_SERVERFAULT)) 解决方案: 打开你电脑中的Office-Exce ...
- schema的元素数据类型(复杂数据类型)
1.简单元素的声明 <xs:element name="元素名称" type="xs:string" default="默认值" mi ...
- Java基础入门 - 三种注释及文档注释详解
类似C/C++,Java也支持单行和多行注释 注释中的字符在编译时会被忽略 注释通常为类.变量和方法的主要描述 单行注释 // 注释内容 多行注释 /* 注释内容 */ /* * 注释内容 */ 文档 ...
- Android Studio快捷键【Android学习入门】
Studio快捷键[Android学习入门]" title="Android Studio快捷键[Android学习入门]"> 提示 Ctrl+P方法参数提示 Ct ...
- 安装Android模拟器Genymotion【Android学习入门】
安装Android模拟器Genymotion 推荐教程:一个强大的Android模拟器Genymotion具体内容如下: 相信很多Android开发者一定受够了速度慢.体验差效率及其地下的官方模拟器了 ...
- Mat转化为IplImage类型的方法
Mat image_mat; IplImage imgTmp = image_mat; IplImage *img = cvCloneImage(&imgTmp);
- mysql启动报错,与selinux相关
mysql启动报错,与selinux相关 如果遇到报错,可能的情况是 selinux 的关系,可以安装 setroubleshoot-server 工具,使用 sealert -a /var/log/ ...
- 水晶报表分组,统计,求和,sum()函数使用
--Sum()函数统计的是明细所有的和 Sum(字段名) --根据分组字段统计的和 Sum ({xh_Getdinggoudan;1.Djine} ,{xh_Getdinggoudan;1.Ddgda ...