题目大意:有$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. 【后缀数组】【LuoguP4248】 [AHOI2013]差异

    题目链接 题目描述 给定一个长度为 n 的字符串 S,令 Ti 表示它从第 i 个字符开始的后缀.求 \(\sum_{1\le i <j\le n}len(T_i)+len(T_j)-2*lcp ...

  2. 【洛谷P5049】旅行(数据加强版)

    题目链接 m=n-1是直接按字典序dfs就行, m=n时是一棵基环树,我们发现当一个点在环上时,可以把它和它的一个在环上的儿子之间的边删掉,然后回溯,到达它的第一个有其他儿子的祖先的另一个儿子上,我们 ...

  3. Good Morning

    题目链接:Good Morning 题目大意:按键盘上的数字,只能在此位置的基础上往右往下按,要求输出与所给值差的绝对值最小的数 AC代码如下: #include <iostream> # ...

  4. shell 杀死80端口的所有进程

    netstat -lnp|grep |grep -v grep |awk

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

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

  6. nRF51822 主从断开连接Reason,HCI ERROR CODE :0x003E

    最近在给一个客户调主从一体的模块,基于S130,距离稍微远一点就会出现连接上后立马又断开连接的现象, 追踪了一下原因,给出的 HCI Error code 是 0x003E,暂且不知道这是什么鬼,查了 ...

  7. Monkey框架(测试方法篇) - monkey日志分析

    Monkey日志分析是Monkey测试中非常重要的一个环节,通过日志分析,可以获取当前测试对象在测试过程中是否会发生异常,以及发生的概率,同时还可以获取对应的错误信息,帮助开发定位和解决问题.介绍日志 ...

  8. Git创建与合并分支,撤销修改

    git回滚到指定版本并推送到远程分支(撤销已提交的修改,并已push) git reset --hard <commit ID号> git push -f git回滚到上一个版本并推送到远 ...

  9. sip user Authentication and 401

    https://www.vocal.com/sip-2/sip-user-authentication/ https://tools.ietf.org/html/rfc3261 SIP User Au ...

  10. Windows系统因“CredSSP加密Oracle修正”无法远程连接

    解决办法如下: 在电脑本机运行(快捷键 Win+R)输入:gpedit.msc 回车: 计算机配置->管理模板->系统->凭据分配->右侧找到“加密Oracle凭据”双击-&g ...