896C
ODT/珂朵莉树
原来这个东西很咸鱼,只能数据随机情况下nloglogn,不过作为卡常还是很好的
大概就是维护区间,值相同的并且连续当成一个区间存在set里,每次区间操作强行分裂就行了。
复杂度因为是随机保证
#include<bits/stdc++.h>
using namespace std;
int n, m, seed, mx;
int rnd()
{
int ret = seed;
seed = (1LL * seed * + ) % ;
return ret;
}
struct data {
int l, r;
long long x;
data() {}
data(int _, int __, long long ___) : l(_), r(__), x(___) {}
bool friend operator < (const data &a, const data &b) {
return a.l != b.l ? a.l < b.l : a.r < b.r;
}
};
bool cmp(const data &a, const data &b)
{
return a.x < b.x;
}
set<data> s;
vector<data> buf;
void cut(int p)
{
set<data> :: iterator it = prev(s.upper_bound(data(p, n + , -)));
if(it -> l == p) return;
data tmp = *it;
s.erase(it);
s.insert(data(tmp.l, p, tmp.x));
s.insert(data(p, tmp.r, tmp.x));
}
void merge(int l, int r)
{
cut(l);
cut(r);
buf.clear();
for(set<data> :: iterator it = s.lower_bound(data(l, -, -)); it != s.end() && it -> r <= r; ++it) buf.push_back(*it);
}
long long power(long long x, long long t, long long P)
{
long long ret = ;
x %= P;
for(; t; t >>= , x = x * x % P) if(t & ) ret = ret * x % P;
return ret;
}
int main()
{
scanf("%d%d%d%d", &n, &m, &seed, &mx);
for(int i = ; i <= n; ++i) s.insert(data(i, i + , rnd() % mx + ));
while(m--)
{
int opt = rnd() % + , l = rnd() % n + , r = rnd() % n + ;
long long x, y;
if(l > r) swap(l, r);
if(opt == ) x = (rnd() % (r - l + )) + ;
else x = rnd() % mx + ;
if(opt == ) y = rnd() % mx + ;
merge(l, r + );
if(opt == )
{
for(int i = ; i < buf.size(); ++i)
{
s.erase(buf[i]);
s.insert(data(buf[i].l, buf[i].r, buf[i].x + x));
}
}
if(opt == )
{
for(int i = ; i < buf.size(); ++i) s.erase(buf[i]);
s.insert(data(l, r + , x));
}
if(opt == )
{
sort(buf.begin(), buf.end(), cmp);
--x;
for(int i = ; i < buf.size(); ++i)
{
if(x < buf[i].r - buf[i].l)
{
printf("%lld\n", buf[i].x);
break;
}
else x -= buf[i].r - buf[i].l;
}
}
if(opt == )
{
long long ans = ;
for(int i = ; i < buf.size(); ++i) ans = (ans + power(buf[i].x, x, y) * (long long)(buf[i].r - buf[i].l) % y) % y;
printf("%lld\n", (ans % y + y) % y);
}
}
return ;
}
896C的更多相关文章
- 【题解】Willem, Chtholly and Seniorious Codeforces 896C ODT
Prelude ODT这个东西真是太好用了,以后写暴力骗分可以用,写在这里mark一下. 题目链接:ヽ(✿゚▽゚)ノ Solution 先把原题解贴在这里:(ノ*・ω・)ノ 简单地说,因为数据是全部随 ...
- 【模板】珂朵莉树(ODT)(Codeforces 896C Willem, Chtholly and Seniorious)
题意简述 维护一个数列,支持区间加,区间赋值,区间求第k小,区间求幂和 数据随机 题解思路 ODT是一种基于std::set的暴力数据结构. 每个节点对应一段区间,该区间内的数都相等. 核心操作spl ...
- Linux内核使用浮点运算问题
上一篇博文中 电池温度检测原理和示例代码 ,由于驱动要使用对数函数而从网上参看一个实现 double ln(double a) { ; int k,nk; double x,xx,y; x = (a- ...
- Chtholly Tree (珂朵莉树) ODT
ODT,OldDriverTree,又名ChthollyTree" role="presentation" style="position: relative; ...
- 「学习笔记」珂朵莉树 ODT
珂朵莉树,也叫ODT(Old Driver Tree 老司机树) 从前有一天,珂朵莉出现了... 然后有一天,珂朵莉树出现了... 看看图片的地址 Codeforces可还行) 没错,珂朵莉树来自Co ...
随机推荐
- react-redux的connect()方法
容器组件使用 connect() 方法连接 Redux 我们用 react-redux 提供的 connect() 方法将“笨拙”的 Counter 转化成容器组件.connect() 允许你从 Re ...
- Odoo10尝鲜: 采购协议
Odoo10 对 call for bid 进行了 改进, 作为 '采购协议' 进入 采购, 选择 'Purchase agreement' 在 agreement 列表 建立新的 协议 选择 协议类 ...
- Triangle 三角形——找出三角形中从上至下和最小的路
Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent n ...
- cas 单点登录(SSO)之中的一个: jasig cas-server 安装
cas 单点登录(SSO)实验之中的一个: jasig cas-server 安装 參考文章: http://my.oschina.net/indestiny/blog/200768#comments ...
- nyoj84 阶乘的0
阶乘的0 时间限制:3000 ms | 内存限制:65535 KB 难度:3 描写叙述 计算n!的十进制表示最后有多少个0 输入 第一行输入一个整数N表示測试数据的组数(1<=N<=1 ...
- 宜信开源|分布式任务调度平台SIA-TASK的架构设计与运行流程
一.分布式任务调度的背景 无论是互联网应用或者企业级应用,都充斥着大量的批处理任务.我们常常需要一些任务调度系统来帮助解决问题.随着微服务化架构的逐步演进,单体架构逐渐演变为分布式.微服务架构.在此背 ...
- node开发后将本地mysql数据导入到服务器mysql
近期写的一个钉钉企业微应用用到了mysql数据库(用koa写的后台,并用mysql库来连接),现在需要把本地数据库的数据导入到服务器的数据库中. 服务器安装mysql 可以google篇centos的 ...
- 从架构层面杜绝lua中使用未定义的变量
# 从架构层面杜绝lua中使用未定义的变量 标签(空格分隔): lua --- lua中有一个很坑的地方:1.就是如果一个变量拼写错误,会自动的认为你定义了一个值为nil的全局变量.2.如果在func ...
- MongoDB——mongo-connector同步到ES
1.搭建完毕MongoDb复制集环境 2.开始安装 mongo-connector pip install mongo-connector:基于pip命令,不管是linux .window 系统默认有 ...
- mount available
Mount (computing), the process of making a file system accessible mount (Unix), the utility in Unix- ...