题目大意:有$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. 洛谷 P4071 [SDOI2016]排列计数 题解

    P4071 [SDOI2016]排列计数 题目描述 求有多少种长度为 n 的序列 A,满足以下条件: 1 ~ n 这 n 个数在序列中各出现了一次 若第 i 个数 A[i] 的值为 i,则称 i 是稳 ...

  2. 结构体&文件

    1.本章学习内容总结 1.1学习内容总结 什么是结构类型? 结构Structure类型是一种允许程序员把一些数据分量聚合成一个整体的数据类型. 结构和数组的区别? 结构和数组的最大区别是数组中所有元素 ...

  3. lintcode-1174.下一个更大的元素 III

    题目描述: 1174. 下一个更大的元素 III 给定一个32位整数n,用同样的数字组成新的32位整数,使得它要比n大,返回最小的这样的数.如果不存在这样的整数,返回-1. 算法思路: 首先将这个数转 ...

  4. 简书 markdown 代码高亮标记

    SyntaxHighlight language language_key 1C 1c ActionScript actionscript Apache apache AppleScript a pp ...

  5. GO语言GIN框架入门

    Gin框架介绍 Gin是一个用Go语言编写的web框架.它是一个类似于martini但拥有更好性能的API框架, 由于使用了httprouter,速度提高了近40倍. 中文文档 Gin框架安装与使用 ...

  6. semantic ui要装什么才能使用

    作者:呆呆笨笨链接:https://www.zhihu.com/question/32233356/answer/196799506来源:知乎著作权归作者所有.商业转载请联系作者获得授权,非商业转载请 ...

  7. git之fatal: Could not read from remote repository

    问题背景:在git bash中使用hexo g -d命令进行文章发布 详细错误信息: fatal: Could not read from remote repository. Please make ...

  8. @DateTimeFormat 和 @JsonFormat 注解

    1. 准备 定义一个pojo,它有一个 java.util.Date 类型的属性 date. import java.util.Date; public class DateVo { private ...

  9. #C++初学记录(奶酪#并查集)

    原题目:牛客网 题目描述 : 现有一块大奶酪,它的高度为 h,它的长度和宽度我们可以认为是无限大的,奶酪中间有许多半径相同的球形空洞.我们可以在这块奶酪中建立空间坐标系, 在坐标系中,奶酪的下表面为 ...

  10. 3ds Max学习日记(十二)——用Maxscript将每一帧动画导出成obj

    参考链接: is there a way to through maxscript to make the time slider go to a spacific frame? 最近老师布置了要用m ...