仿佛没用过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. Java异常处理学习

    今天才开通了博客园的博客,希望可以记录自己学习的点点滴滴.最近去处理了一些私人事情,有点烦人,希望自己不要被这些破事所影响. 最近在看马士兵老师的Java基础的视频,(中断了一周)发现本科时候的胡老师 ...

  2. 基于log4net自定义异步logging组件

    我们在做开发的时候,需要把一些信息记录下来,方便问题排查.数据分析和统计.通常我们使用log4net作为logging的工具,但是大部分时候需要加以封装,以便更加方便的使用,并且不妨碍主业务程序的运行 ...

  3. 执行ORACLE SQL时如何 忽略替换变量(转载)

    你想在SQL*Plus里执行一个脚本,脚本里包含了一些看起来像替换变量的元素,但实际上你并不是想把它们当替换变量来处理.这时你想让解析器忽略它们而不是提示用户输入.解决方案1有一种解决方案就是在&am ...

  4. git分布式的理解----简单服务端搭建

    Git是分布式的,并没有服务端跟客户端之分,所谓的服务端安装的其实也是git.Git支持四种协议,file,ssh,git,http.ssh是使用较多的,下面使用ssh搭建一个免密码登录的服务端. 1 ...

  5. linux 统计TCP 连接各状态总数

    netstat  -n|awk '/^tcp/ {++s[$NF]} END {for(k in s) print k, s[k]}' 以前经常只是从笔记中复制下, 这次打算 研究下 awk 语法 . ...

  6. Day7下

    T1 我直接就用的LCA ,可能慢点.反正数据试过了. T2 期望dp不会啊. T3 好麻烦.

  7. [JAVA][Liferay] Configure sharding in multiple sites

    create databases first portal-ext.properties配置 hibernate.dialect=org.hibernate.dialect.PostgreSQLDia ...

  8. Linux如何上查看和退出tomcat实时日志

    1.先切换到:cd usr/local/tomcat/logs 目录下 2.tail -f catalina.out Ctrl+c 是退出tail命令. alt+E+R重置.

  9. c# cook book -Linq 关于Object的比较

    实际项目中经常用到 Union,Distinct,INtersect,Execpt对列表进行处理 一般来说要首先重写 Equals 和GetHashCode方法 首先看为重写的情况: namespac ...

  10. as3.0 动态文本属性大全

    var my_fmt = new TextFormat();//常用样式 my_fmt.align = "center"; my_fmt.blockIndent = 50; //区 ...