【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 ...
随机推荐
- 批量处理标签属性中document.getElementsByName()的替代方案
背景 今天在逛知乎时候,看到一个JavaScript方面的问题: 最近在学习JavaScript DOM,就好奇地查阅资料,以及请教学长,得到下面解答: http://www.w3help.org/z ...
- poj 1947 树形背包
重做这道题 http://blog.csdn.net/woshi250hua/article/details/7632785 http://blog.csdn.net/shuangde800/arti ...
- BZOJ4260: Codechef REBXOR (01Tire树)
题意 题目链接 Sol 首先维护出前缀xor和后缀xor 对每个位置的元素插入到Trie树里面,每次找到和该前缀xor起来最大的元素 正反各做一遍,取最大. 记得要开log倍空间qwq.. #incl ...
- Python基础 整形、布尔值、if条件判断、while循环、运算符、格式化输出
1,计算机基础.2,python历史. 宏观上:python2 与 python3 区别: python2 源码不标准,混乱,重复代码太多, python3 统一 标准,去除重复代码.3,python ...
- Java Knowledge series 5
Interface from user, not from implementor.(DIP) Interface-Oriented Programming. Interface or Abstrac ...
- SpringCloud的学习记录(6)
这一章节讲fegin的使用. 在我们生成的Demo项目上右键点击New->Module->spring Initializr, 然后next, 填写Group和Artifact等信息, 这 ...
- IDEA 打包jar
1.ctrl+shift+alt+s 弹出项目设置窗口,点击Artifacts页签,点+号,选择jar Empty.修改jar name,将右侧需要打包进去的资源拖到左侧,记住Output direc ...
- Spark job执行流程消息图
Spark job执行流程消息图 1.介绍
- 同步软件UltraCompare 64位 软件及注册机
软件及注册机下载: https://share.weiyun.com/f09e6243887e374ead1b3a3ab8f611a9 软件官方下载地址: https://www.ultraedit ...
- 814. Binary Tree Pruning(leetcode) (tree traverse)
https://leetcode.com/contest/weekly-contest-79/problems/binary-tree-pruning/ -- 814 from leetcode tr ...