题意

题目链接

Sol

ODT板子题。就是用set维护连续段的大暴力。。

然鹅我抄的板子本题RE提交AC??。。

具体来说,用50 50 658073485 946088556这个数据测试下面的代码,然后在79行停住,看一下bg和i的值会发生神奇的事情。。

问题已解决,确实是那位博主写错了, 只要把split(l)和split(r + 1)反过来就行了

#include<bits/stdc++.h>
#define LL long long
#define int long long
#define sit set<Node>::iterator
#define fi first
#define se second
using namespace std;
const int MOD = 1e9 + 7, MAXN = 1e6 + 10;
inline int read() {
char c = getchar(); int x = 0, f = 1;
while(c < '0' || c > '9') {if(c == '-') f = -1; c = getchar();}
while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
return x * f;
}
int N, M, mod;
template<typename A, typename B> inline int mul(A x, B y) {
return 1ll * x * y % mod;
}
template<typename A, typename B> inline void add2(A &x, B y) {
x = (x + y % mod);
}
LL seed, vmax;
int a[MAXN];
int rnd() {
int ret = seed;
seed = (seed * 7 + 13) % MOD;
return ret;
}
struct Node {
int l, r;
mutable LL v;
bool operator < (const Node &rhs) const {
return l < rhs.l;
}
};
set<Node> s;
sit split(int p) {
auto pos = s.lower_bound({p});
if(pos != s.end() && pos->l == p) return pos;
pos--;
int L = pos->l, R = pos->r, V = pos->v;
s.erase(pos);
s.insert({L, p - 1, V});
return s.insert({p, R, V}).fi;
}
void Add(int l, int r, int val) {
auto bg = split(l), ed = split(r + 1);
for(auto i = bg; i != ed; i++) i->v += val;
}
void Mem(int l, int r, int val) {
for(int i = l; i <= r; i++) a[i] = val;
auto bg = split(l), ed = split(r + 1);
s.erase(bg, ed);
s.insert({l, r, val});
}
int rak(int l, int r, int x) {
vector<pair<LL, int>> v;
auto bg = split(l), ed = split(r + 1);
for(auto i = bg; i != ed; i++)
v.push_back({i->v, i->r - i->l + 1}); sort(v.begin(), v.end());
for(auto it = v.begin(); it != v.end(); it++) {
x -= it -> se;
if(x <= 0) return it -> fi;
}
assert(0);
}
int fp(int a, int p) {
int base = 1; a %= mod;
while(p) {
if(p & 1) base = 1ll * base * a % mod;
a = 1ll * a * a % mod; p >>= 1;
}
return base;
}
int po(int l, int r, int x) {
if(l == 6 && r == 7) {
puts("G");
}
auto bg = split(l);
printf("%d %d %d %d\n", bg->l, bg->r, bg->v);
auto ed = split(r + 1);
int ans = 0;
for(sit i = bg; i != ed; i++) {
printf("%d %d %d %d\n", i->l, i->r, i->v);
ans = (ans + (i->r - i->l + 1) * fp(i->v, x) % mod) % mod;
}
return ans;
}
signed main() {
N = read(); M = read(); seed = read(); vmax = read();
for(int i = 1; i <= N; i++) a[i] = (rnd() % vmax) + 1, s.insert({i, i, a[i]});
s.insert({N + 1, N + 1, 0});
for(int i = 1; i <= M; i++) {
int op = (rnd() % 4) + 1; int l = (rnd() % N) + 1; int r = (rnd() % N) + 1, x = -1;
if(l > r) swap(l, r); if(op == 3) x = (rnd() % (r - l + 1)) + 1;
else x = (rnd() % vmax) + 1;
if(op == 4) mod = (rnd() % vmax) + 1;
if(op == 1) Add(l, r, x);
else if(op == 2) Mem(l, r, x);
else if(op == 3) cout << rak(l, r, x) << '\n';
else cout << po(l, r, x) << '\n';
}
return 0;
}
/*
50 50 658073485 946088556
*/

cf896C. Willem, Chtholly and Seniorious(ODT)的更多相关文章

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

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

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

  4. [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$大 ...

  5. CF896C Willem, Chtholly and Seniorious(珂朵莉树)

    中文题面 珂朵莉树的板子……这篇文章很不错 据说还有奈芙莲树和瑟尼欧里斯树…… 等联赛考完去学一下(逃 //minamoto #include<bits/stdc++.h> #define ...

  6. Willem, Chtholly and Seniorious

    Willem, Chtholly and Seniorious https://codeforces.com/contest/897/problem/E time limit per test 2 s ...

  7. CF&&CC百套计划1 Codeforces Round #449 C. Willem, Chtholly and Seniorious (Old Driver Tree)

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

  8. 【题解】Willem, Chtholly and Seniorious Codeforces 896C ODT

    Prelude ODT这个东西真是太好用了,以后写暴力骗分可以用,写在这里mark一下. 题目链接:ヽ(✿゚▽゚)ノ Solution 先把原题解贴在这里:(ノ*・ω・)ノ 简单地说,因为数据是全部随 ...

  9. 【模板】珂朵莉树(ODT)(Codeforces 896C Willem, Chtholly and Seniorious)

    题意简述 维护一个数列,支持区间加,区间赋值,区间求第k小,区间求幂和 数据随机 题解思路 ODT是一种基于std::set的暴力数据结构. 每个节点对应一段区间,该区间内的数都相等. 核心操作spl ...

随机推荐

  1. 【ElasticSearch】:Windows下ElasticSearch+版本安装head

    概述 elasticsearch-head,之前插件plugin方式已废弃,现已改为nodejs的NPM安装,独立WEB服务方式. elasticsearch-head网址:https://githu ...

  2. Python 多进程 多线程 协程 I/O多路复用

    引言 在学习Python多进程.多线程之前,先脑补一下如下场景: 说有这么一道题:小红烧水需要10分钟,拖地需要5分钟,洗菜需要5分钟,如果一样一样去干,就是简单的加法,全部做完,需要20分钟:但是, ...

  3. 说说正则表达式的exec方法

    话说,关于正则表达式有一个梗,大意是: 假如你有一个问题,想用正则来解决,于是你就有了两个问题 这句话侧面反映了精通正则是一件不容易的事.比如我今天遇到的诡异事件. 情景回放 这两天练手写了一个爬用户 ...

  4. typedef在C和C++的区别?

    一.struct定义结构体1.先声明结构体类型再定义变量名struct name{ member ..};name A;... 如:struct student{ int a;};student st ...

  5. Linux内核升级导致无法启动,Kernel panic - not syncing Unable to mount root fs on unknown block(0,0)

    问题原因:内核的某次升级,导致系统无法启动. 首先进入recovery模式:引导界面选择-->Ubuntu高级-->出现的选项中选择能够启动的recovery模式(几个内核版本分别试一下) ...

  6. 老司机的应用级监控——spring actuator(转)

    转自:https://www.jianshu.com/p/c043d3c71f47 什么是spring actuator? 这是一个研发老司机与运维同学都会非常喜欢的东西,随着点融集团的扩张,点融网的 ...

  7. MYSQL用户权限管理(Grant,Revoke)

    MySQL可以为不同的用户分配严格的.复杂的权限.这些操作大多都可以用SQL指令Grant(分配权限)和Revoke(回收权限)来实现. Grant可以把指定的权限分配给特定的用户,如果这个用户不存在 ...

  8. 使用Gitlab一键安装包后的日常备份恢复与迁移

    Gitlab 创建备份 使用Gitlab一键安装包安装Gitlab非常简单, 同样的备份恢复与迁移也非常简单. 使用一条命令即可创建完整的Gitlab备份: gitlab-rake gitlab:ba ...

  9. Spring-IOC注解

    注解主要的目的就是实现零XML配置.一:自动扫描装配Bean. spring为我们引入了组件自动扫描机制,它可以在类路径底下寻找标注了@Component.@Service.@Controller.@ ...

  10. Docker基础教程(安装篇)

    Linux安装: 1.yum -y install docker-io 2.service docker start 3.chkconfig docker on Window安装: Docker 引擎 ...