题意

题目链接

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. 设计模式《JAVA与模式》之访问者模式

    在阎宏博士的<JAVA与模式>一书中开头是这样描述访问者(Visitor)模式的: 访问者模式是对象的行为模式.访问者模式的目的是封装一些施加于某种数据结构元素之上的操作.一旦这些操作需要 ...

  2. iOS开发-实现相机app的方法[转载自官方]

    This brief code example to illustrates how you can capture video and convert the frames you get to U ...

  3. mongodb postgresql mysql jsonb对比

    mongodb pg mysql jsonb对比 http://erthalion.info/2017/12/21/advanced-json-benchmarks/ 使用禁用jsonb列的压缩 AL ...

  4. 最短路变形 poj3615& poj2263

    问题: 牛要跨过一些障碍,希望以最小的体力跨过障碍,并且对于一条路径,只在乎其中最高的障碍. 输入N代表站点数,标记为1—N,输入M代表路径数,从站点S到E之间需要跨过高度为H的障碍. 输入T代表牛要 ...

  5. vue教程2-01 vue生命周期、钩子函数

    vue教程2-01 vue生命周期.钩子函数 <!DOCTYPE html> <html lang="en"> <head> <meta ...

  6. Scala的Trait详解

    http://article.yeeyan.org/view/178378/358355

  7. 【JAVA】枚举

    枚举(enum)类型是Java 5新增的特性,它是一种新的类型,允许用常量来表示特定的数据片断,而且全部都以类型安全的形式来表示. 1.常量的使用 在JDK1.5之前,我们定义常量都是:public ...

  8. Linux 各种运算符

    目录 - 算术运算符 - 关系运算符 - 逻辑运算符 - 按位运算符 - 文件测试符 - 算术运算符 算术运算符,常用的有+.-.*./.%.++.--.** + - 加法运算符 [root@www ...

  9. Shell脚本 | 性能测试之启动流量

    安卓应用的流量统计有多种方式,点击「阅读原文」可以看到一篇别人写的文章,关于安卓流量数据的获取,写的挺全的,列举了几种不同方式的优劣.(见文末参考链接) 今天我要分享的是通过脚本一键获取应用的启动流量 ...

  10. 配置codis-dashboard

    codis-dashboard主要用来codis配置使用,也就是说所有的相关的配置项必须通过此进程完成,本演习在60服务上配置测试. 利用codis本身提供的命令自动生成配置文件:1.生成dashbo ...