[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: ...
随机推荐
- springboot2.0整合redis作为缓存以json格式存储对象
步骤1 <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spr ...
- According to TLD or attribute directive in tag file, attribute items does not accept any expressions
<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %>报错 <%@ tagl ...
- linux下将终端的输入存入文件中
代码很简单: #include <stdlib.h> #include <fcntl.h> #include <stdio.h> #include <unis ...
- FormData实现文件上传
我用到FormData传输的使用场景:vant UI组件里面 的图片上传这块,需要调用后台的图片上传接口,使用的是FormData方式上传的 https://www.cnblogs.com/hutuz ...
- Spring Boot 面试,一个问题就干趴下了!(下)
前些天栈长在Java技术栈微信公众号分享一篇文章:Spring Boot 面试,一个问题就干趴下了!,看到大家的留言很精彩,特别是说"约定大于配置"的这两个玩家. 哈哈,上墙的朋友 ...
- layui如何自定义弹出层关闭事件
在某些业务场景下,我们需要自定义弹出层关闭事件,代码示例如下: layui.use('layer', function () { var layer = layui.layer; layer.open ...
- Netty 读写检测机制(心跳)
一.创建服务端 1.MyServer 类 public class MyServer { public static void main(String[] args) throws Exception ...
- 数据库sql优化总结之3--SQL优化总结
SQL是每个Java程序员必回的一项技能, 对于项目中的各种复杂业务, 你是否能写出高效率, 简洁的SQL对于项目的运行效率和稳定性是有非常大的作用的. 通过个人的理解和网上的资料总结了一下常见的S ...
- date命令时间戳和时间之间的转换
这里是在mac下的操作,主要就是用date这个命令,更多的用法用man命令查看 字符串格式时间 TO 时间戳我们知道date 命令可以直接把当前时间转化为时间戳 # date +%s143678152 ...
- ADB命令使用大法
前言 Android开发调试工具ADB的使用.ADB(Android Debug Bridge)是Android SDK中的一个工具, 使用ADB可以直接操作管理Android模拟器或者真实的And ...