【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 ...
随机推荐
- OpenStack Weekly Rank 2015.08.03
Module Reviews Drafted Blueprints Completed Blueprints Filed Bugs Resolved Bugs Cinder 7 1 1 7 11 Sw ...
- vue-cli构建项目在index.html中使用静态文件
在vue-cli构建的项目中,且使用在移动端,我们希望每一个页面加载时都可以使用flexible.js来适配手机. 那么这个flexible.js被import到每一个组件中就不合适了. 好的方法是直 ...
- pat1057. Stack (30)
1057. Stack (30) 时间限制 100 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Stack is one of ...
- 文本框只允许输入数字.net/javascript
<input type="text" name="test" onKeyUp="test1.value=(this.value=this.val ...
- POJ 3259——Wormholes——————【最短路、SPFA、判负环】
Wormholes Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Submit St ...
- 斗鱼扩展--localStorage备份与导出(九)
之前我们都把数据 放在了 localStorage 里,但扩展一旦卸载,数据就会被清空, 在Console里备份,一次只能输出一条,小白操作起来很不方便,所以能不能 导入,导出文件来进行备份还原呢? ...
- sql数据库基础知识整理,常用函数及常用语法
1常用数据库聚合函数max()min()sum()avg()count() 2字符串处理函数len() 与 datalength() 区别:len是返回字符长度 datalength是返回字节长度 ...
- 微信小程序电商实战-首页(上)
嗨,大家好!经过近两周的精心准备终于开始微信小程序电商实战之路喽.那么最终会做成什么样呢?当然可以肯定不会只做一个静态demo哦,先把我们小程序电商实战的整体架构发出来晒一下,请看下图: 架构图. ...
- css改变透明背景png图片的图标颜色
HTML: <p><strong>原始图标</strong></p> <i class="icon icon-del"> ...
- Android Studio快捷键【Android学习入门】
Studio快捷键[Android学习入门]" title="Android Studio快捷键[Android学习入门]"> 提示 Ctrl+P方法参数提示 Ct ...