[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$大
- l r x p :输出$\sum\limits_{i=l}^rs_i^x\pm
$n,m\leqslant10^5$
题解:珂朵莉树模板题
卡点:$split$中写错,写成 it==s.end()
C++ Code:
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <set>
#include <vector>
#define mul(a, b) (static_cast<long long> (a) * (b) % mod)
#define _mul(a, b) (a = static_cast<long long> (a) * (b) % mod) inline int pw(int base, int p, int mod) {
static int res;
for (res = 1; p; p >>= 1, _mul(base, base)) if (p & 1) _mul(res, base);
return res;
} int n, m, seed, vmax;
int rnd() {
static const int mod = 1e9 + 7;
static int t; t = seed;
seed = (7ll * seed + 13) % mod;
return t;
} namespace ODT {
struct node {
int l, r; mutable long long v;
inline bool operator < (const node &rhs) const { return l < rhs.l; }
} ;
typedef std::set<node>::iterator SIT;
typedef std::pair<long long, int> PLI;
std::set<node> s;
SIT split(int pos) {
SIT it = s.lower_bound((node) { pos, 0, 0 });
if (it != s.end() && it -> l == pos) return it;
--it; const int l = it -> l, r = it -> r;
const long long v = it -> v;
s.erase(it), s.insert((node) { l, pos - 1, v });
return s.insert((node) { pos, r, v }).first;
}
void assign(int l, int r, int v) {
SIT R = split(r + 1), L = split(l);
s.erase(L, R), s.insert((node) { l, r, v });
}
void add(int l, int r, int v) {
SIT R = split(r + 1), L = split(l);
for (SIT it = L; it != R; ++it) it -> v += v;
}
long long rnk(int l, int r, int k) {
static std::vector<PLI> v; v.clear();
SIT R = split(r + 1), L = split(l);
for (SIT it = L; it != R; ++it)
v.push_back(std::make_pair(it -> v, it -> r - it -> l + 1));
std::sort(v.begin(), v.end());
for (PLI i : v) {
k -= i.second;
if (k <= 0) return i.first;
}
}
int query(int l, int r, int x, int mod) {
SIT R = split(r + 1), L = split(l);
int ans = 0;
for (SIT it = L; it != R; ++it)
ans = (ans + mul(pw(it -> v % mod, x, mod), it -> r - it -> l + 1)) % mod;
return ans;
}
} int main() {
std::ios::sync_with_stdio(false), std::cin.tie(0), std::cout.tie(0);
std::cin >> n >> m >> seed >> vmax;
for (int i = 1, x; i <= n; ++i) {
x = (rnd() % vmax) + 1;
ODT::s.insert((ODT::node) { i, i, x });
}
while (m --> 0) {
static int op, l, r, x, y;
op = (rnd() % 4) + 1;
l = (rnd() % n) + 1;
r = (rnd() % n) + 1;
if (l > r) std::swap(l, r);
if (op == 3) x = rnd() % (r - l + 1) + 1;
else x = rnd() % vmax + 1;
if (op == 4) y = rnd() % vmax + 1;
switch (op) {
case 1: ODT::add(l, r, x); break;
case 2: ODT::assign(l, r, x); break;
case 3: std::cout << ODT::rnk(l, r, x) << '\n'; break;
case 4: std::cout << ODT::query(l, r, x, y) << '\n';
}
}
return 0;
}
[CF896C]Willem, Chtholly and Seniorious的更多相关文章
- 【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 ...
- [CF896C]Willem, Chtholly and Seniorious(珂朵莉树)
https://www.cnblogs.com/WAMonster/p/10181214.html 主要用于支持含有较难维护的区间操作与查询的问题,要求其中区间赋值操作(assign())是纯随机的. ...
- cf896C. Willem, Chtholly and Seniorious(ODT)
题意 题目链接 Sol ODT板子题.就是用set维护连续段的大暴力.. 然鹅我抄的板子本题RE提交AC??.. 具体来说,用50 50 658073485 946088556这个数据测试下面的代码, ...
- 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 ...
- CF&&CC百套计划1 Codeforces Round #449 C. Willem, Chtholly and Seniorious (Old Driver Tree)
http://codeforces.com/problemset/problem/896/C 题意: 对于一个随机序列,执行以下操作: 区间赋值 区间加 区间求第k小 区间求k次幂的和 对于随机序列, ...
- 题解 CF896C 【Willem, Chtholly and Seniorious】
貌似珂朵莉树是目前为止(我学过的)唯一一个可以维护区间x次方和查询的高效数据结构. 但是这玩意有个很大的毛病,就是它的高效建立在数据随机的前提下. 在数据随机的时候assign操作比较多,所以它的复杂 ...
- 【CF896C】Willem, Chtholly and Seniorious
ODT模板题,ODT适合随机数据下具有维护区间推平操作的序列维护题目,时间复杂度较为玄学.. 代码如下 #include <bits/stdc++.h> #define pb push_b ...
- Codeforces Round #449 (Div. 1) Willem, Chtholly and Seniorious (ODT维护)
题意 给你一个长为 \(n\) 的序列 \(a_i\) 需要支持四个操作. \(1~l~r~x:\) 把 \(i \in [l, r]\) 的 \(a_i\) 加 \(x\) . \(2~l~r~x: ...
随机推荐
- 80: bzoj3705 线段树合并
$des$ 现在有一棵二叉树,所有非叶子节点都有两个孩子.在每个叶子节点上有一个权值(有n个叶子节点,满足这些权值为1..n的一个排列).可以任意交换每个非叶子节点的左右孩子.要求进行一系列交换,使得 ...
- BZOJ 3435: [Wc2014]紫荆花之恋
二次联通门 : BZOJ 3435: [Wc2014]紫荆花之恋 二次联通门 : luogu P3920 [WC2014]紫荆花之恋 /* luogu P3920 [WC2014]紫荆花之恋 怀疑人生 ...
- Shell的语法
Shell的语法: 变量:字符串.数字.环境和参数: 条件:shell中的布尔值: 程序控制:if.elif.for.while.until.case: 命令列表: 函数: Shell内置命令: 获取 ...
- JS filter的使用
定义和用法 filter() 方法创建一个新的数组,新数组中的元素是通过检查指定数组中符合条件的所有元素. 注意: filter() 不会对空数组进行检测. 注意: filter() 不会改变原始数组 ...
- MongoDB 关系型数据库表(集合)与表(集合)之间的几种关系
简述关系数据库中表与表的 3 种关系 一对一的关系:例如:一个人对应一个唯一的身份证号,即为一对一的关系. 一对多关系 :例如:一个班级对应多名学生,一个学生只能属于一个班级,即为一对多关系 多对多关 ...
- MyBatis中的配置错误creating bean with name 'sqlSessionFactory'
错误信息如下: 警告: Exception encountered during context initialization - cancelling refresh attempt: org.sp ...
- 范仁义html+css课程---6、表格
范仁义html+css课程---6.表格 一.总结 一句话总结: 表格中最常用的元素就是table.tr.td.th,还有语义化的thead.tbody.tfoot标签 1.表格构成三个基本要素? t ...
- mysql事务回滚机制概述
应用场景: 银行取钱,从ATM机取钱,分为以下几个步骤 1 登陆ATM机,输入密码: 2 连接数据库,验证密码: 3 验证成功,获得用户信息,比如存款余额等: 4 用 ...
- Dictionary导致IIS CPU 100%案例分析 学会使用WinDbg工具
.NET 开发注意 线程安全性问题.弄不好可能会导致CPU满载 特别主要 Dictionary作为静态变量使用的情况. 解决方法: Dictionary 换成 ConcurrentDictiona ...
- mysql-connector-java(6.0以上)的时差问题
一.背景 通过mybatis日志观察插入数据库的时间为当前时间,但是打开数据库表发现时间滞后了8个小时. 二.推论及解决 很容易猜到这是时区的问题. 三.最后找到的问题点如下: jdbc:mysql: ...