题目大意:有$n$个数,有$m$次$4$种操作:

  1. l r x :将$[l,r]$区间所有数加上$x$
  2. l r x :将$[l,r]$区间所有数变成$x$
  3. l r k :输出$[l,r]$区间第$k$大
  4. 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的更多相关文章

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

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

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

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

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

  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. CF&&CC百套计划1 Codeforces Round #449 C. Willem, Chtholly and Seniorious (Old Driver Tree)

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

  7. 题解 CF896C 【Willem, Chtholly and Seniorious】

    貌似珂朵莉树是目前为止(我学过的)唯一一个可以维护区间x次方和查询的高效数据结构. 但是这玩意有个很大的毛病,就是它的高效建立在数据随机的前提下. 在数据随机的时候assign操作比较多,所以它的复杂 ...

  8. 【CF896C】Willem, Chtholly and Seniorious

    ODT模板题,ODT适合随机数据下具有维护区间推平操作的序列维护题目,时间复杂度较为玄学.. 代码如下 #include <bits/stdc++.h> #define pb push_b ...

  9. 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: ...

随机推荐

  1. [USACO14MAR] Sabotage 二分答案 分数规划

    [USACO14MAR] Sabotage 二分答案 分数规划 最终答案的式子: \[ \frac{sum-sum[l,r]}{n-len[l,r]}\le ans \] 转换一下: \[ sum[1 ...

  2. kafka 创建消费者报错

    kafka-console-consumer.sh --zookeeper master:2181,slave1:2181,slave2:2181 --topic test --from-beginn ...

  3. PhpStorm 设置自动FTP同步文件

    1.添加一个FTP服务器 ① 首先在这里打开添加FTP的页面,步骤,工具栏 -> Tools -> Deployment -> Configuration .     ②添加服务器  ...

  4. 项目启动tomcat失败的几种可能原因和解决方法

    传送门:https://blog.csdn.net/u010565910/article/details/80411468 总结一下tomcat启动问题,也给自己做个笔记 , 逐渐补充完善. 1.ja ...

  5. centos 添加/删除用户和用户组

    centos系统添加/删除用户和用户组     在centos中增加用户使用adduser命令而创建用户组使用groupadd命令,这个是不是非常的方便呀,其实复杂点的就是用户的组与组权限的命令了,下 ...

  6. Mysql创建测试大量测试数据

    修改mysql配置 max_heap_table_size=4000M innodb_flush_log_at_trx_commit=0sync_binlog=500 创建测试数据库 create d ...

  7. Linux下打开超大文件的方法

    Linux下打开超大文件方法 在Linux下用VIM打开大小几个G.甚至几十个G的文件时,是非常慢的. 这时,我们可以利用下面的方法分割文件,然后再打开. 1 查看文件的前多少行 head -1000 ...

  8. SpringMVC @SessionAttribute 使用说明

    百度搜索 @SessionAttribute 这一句绝大多数文章中不存在: 如果Model中没有name参数,而session中存在一个name参数,那么SessionAttribute会讲这个参数塞 ...

  9. UBI mkfs.ubifs 参数记录

    NAND 硬件结构如下: 脚本如下 sudo mkfs.ubifs -q -r rootfs_iproute -m 4096 -e 248KiB -c 3840 -o ubifs.img -F ech ...

  10. Puppeteer最大化显示,分辨率自适应

    Puppeteer自适应分辨率,可以将defaultViewport设为null, 启动的时候还是半屏显示,点击最大化按钮,可以最大化显示. 这样分辨率能够自适应操作系统. 具体可看:https:// ...