仿佛没用过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的更多相关文章

  1. cf896C. Willem, Chtholly and Seniorious(ODT)

    题意 题目链接 Sol ODT板子题.就是用set维护连续段的大暴力.. 然鹅我抄的板子本题RE提交AC??.. 具体来说,用50 50 658073485 946088556这个数据测试下面的代码, ...

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

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

  3. [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$大 ...

  4. CF896C Willem, Chtholly and Seniorious(珂朵莉树)

    中文题面 珂朵莉树的板子……这篇文章很不错 据说还有奈芙莲树和瑟尼欧里斯树…… 等联赛考完去学一下(逃 //minamoto #include<bits/stdc++.h> #define ...

  5. Willem, Chtholly and Seniorious

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

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

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

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

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

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

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

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

随机推荐

  1. (转)Rsync 排错案例解析

    Rsync 排错案例解析 原文:http://blog.51cto.com/irow10/1827306 错误一. 执行计划任务的备份脚本后没有看到备份的文件 1.首先查看crontab日志是否执行文 ...

  2. eureka的一点细节

    第二部分粗略的过一遍,还是有些模糊,再来相对系统的看一下: ---------------------------------------------------------------------- ...

  3. MySQL查询上个月数据

    SELECT * FROM order o WHERE o.payTime BETWEEN DATE_FORMAT(DATE_ADD(NOW(),INTERVAL MONTH),'%Y-%m-01') ...

  4. MVC中的验证码

    下面是一个完整的mvc controller类 public class CodeController : Controller { private const string CODE = " ...

  5. 初识JavaScriptOOP(js面向对象)

    初识JavaScriptOOP(js面向对象) Javascript是一种基于对象(object-based)的语言, 你遇到的所有东西几乎都是对象.但是,它又不是一种真正的面向对象编程(OOP)语言 ...

  6. PHP switch分支语句中省略break后还会执行其他case的原因分析

    请分析以下PHP代码的输出结果: $a= 'dog'; switch($a) { case 'cat': echo "\$a is cat"; case 'dog': echo & ...

  7. System Center Configuration Manager 2016 配置安装篇(Part3)

    SCCM 2016 配置管理系列(Part 1- 4) 介绍AD01上配置了Active Directory域服务(ADDS),然后将Configuration Manager服务器(CM16)加入到 ...

  8. isee图片专家批量处理图片大小教程

    经常用手机.照相机外出拍照片,然后再弄到电脑上面很占硬盘空间了,isee图片专家是一款非常专业的批量压缩图片大小工具,方便储存,给电脑减压,具有一次自动处理N张图片:程序小巧,资源占用低,处理速度快等 ...

  9. 有趣的回文数(Palindrome number)

    文章转自http://blog.163.com/hljmdjlln@126/blog/static/5473620620120412525181/ 做LC上的题"Palindrome num ...

  10. struts2表单提交Date数据无法接收

    问题:在Struts2环境下,提交含有Date类型数据表单,但是在action中没有接收到:String就可以直接接收到: --网络搜索后,说Struts2可以自己转,但是目前没发现有: 然后在狂搜, ...