【题解】Willem, Chtholly and Seniorious Codeforces 896C ODT
Prelude
ODT这个东西真是太好用了,以后写暴力骗分可以用,写在这里mark一下。
题目链接:ヽ(✿゚▽゚)ノ
Solution
先把原题解贴在这里:(ノ*・ω・)ノ
简单地说,因为数据是全部随机的,所以一定会有特别多的区间set,就会有很多数字相同,那么我们暴力把相同的数字合并成一个点,合并完之后数组就变得很短,然后对于询问暴力做就可以了。
具体复杂度是什么我也不会证明qwq,所以就把由乃的题解贴上来了qwq,感觉很靠谱的样子。
题解中给的是用STL的set维护缩点后的数组,我感觉不是很好写,就直接用数组维护了。
ddd还写过链表维护的,不过感觉都差不多,反正复杂度都是对的,肯定能过qwq。
Code
#include <bits/stdc++.h>
#define dprint printf
using namespace std;
typedef long long ll;
typedef pair<ll,int> pli;
const int MAXN = 100010;
int _w;
void noprint(...) {}
int fpow( int a, int b, int mod ) {
int c = 1;
while(b) {
if( b & 1 ) c = int(1LL * c * a % mod);
a = int(1LL * a * a % mod);
b >>= 1;
}
return c;
}
int inter( int l1, int r1, int l2, int r2 ) {
int l = max(l1, l2);
int r = min(r1, r2);
return max(r-l+1, 0);
}
int n, m, seed, vmax;
ll a[MAXN];
int rnd() {
const int MOD = 1e9+7;
int ret = seed;
seed = int((1LL * seed * 7 + 13) % MOD);
return ret;
}
pli b[MAXN];
int sz;
void prelude() {
sz = 1;
b[sz-1].first = a[1], b[sz-1].second = 0;
for( int i = 1; i <= n; ++i ) {
if( b[sz-1].first == a[i] ) {
++b[sz-1].second;
} else {
b[sz].first = a[i], b[sz].second = 1, ++sz;
}
}
}
pli c[MAXN];
int csz;
void append( ll x, int cnt ) {
if( csz && c[csz-1].first == x )
c[csz-1].second += cnt;
else
c[csz].first = x, c[csz].second = cnt, ++csz;
}
void solve1( int l, int r, int x ) {
int L = 0, R = 0;
csz = 0;
for( int i = 0; i < sz; ++i ) {
L = R+1;
R = L + b[i].second - 1;
ll num = b[i].first;
int cntl = inter(L, l-1, L, R);
int cnt = inter(L, R, l, r);
int cntr = inter(r+1, R, L, R);
if( cntl ) append(num, cntl);
if( cnt ) append(num+x, cnt);
if( cntr ) append(num, cntr);
}
sz = csz;
for( int i = 0; i < sz; ++i )
b[i] = c[i];
}
void solve2( int l, int r, int x ) {
int L = 0, R = 0;
csz = 0;
for( int i = 0; i < sz; ++i ) {
L = R+1;
R = L + b[i].second - 1;
ll num = b[i].first;
int cntl = inter(L, l-1, L, R);
int cnt = inter(L, R, l, r);
int cntr = inter(r+1, R, L, R);
if( cntl ) append(num, cntl);
if( cnt ) append(x, cnt);
if( cntr ) append(num, cntr);
}
sz = csz;
for( int i = 0; i < sz; ++i )
b[i] = c[i];
}
void solve3( int l, int r, int x ) {
int L = 0, R = 0;
csz = 0;
for( int i = 0; i < sz; ++i ) {
L = R+1;
R = L + b[i].second - 1;
int cnt = inter(L, R, l, r);
if( cnt ) c[csz++] = pli( b[i].first, cnt );
}
sort(c, c+csz);
L = R = 0;
for( int i = 0; i < csz; ++i ) {
L = R+1;
R = L + c[i].second - 1;
if( x >= L && x <= R )
return (void)printf( "%lld\n", c[i].first );
}
return assert(0);
}
void solve4( int l, int r, int x, int y ) {
int L = 0, R = 0, ans = 0;
for( int i = 0; i < sz; ++i ) {
L = R+1;
R = L + b[i].second - 1;
int cnt = inter(L, R, l, r);
if( cnt ) ans = int((ans + 1LL * cnt * fpow( int(b[i].first % y), x, y )) % y);
}
printf( "%d\n", ans );
}
void output_array() {
for( int i = 0; i < sz; ++i ) {
int t = b[i].second;
while( t-- )
dprint( "%lld ", b[i].first );
}
dprint("\n");
}
int main() {
_w = scanf( "%d%d%d%d", &n, &m, &seed, &vmax );
// dprint("Init:\n");
for( int i = 1; i <= n; ++i ) {
a[i] = rnd() % vmax + 1;
// dprint("%lld ", a[i]);
}
// dprint("\n");
prelude();
for( int i = 1; i <= m; ++i ) {
int op, l, r, x, y;
op = rnd() % 4 + 1;
l = rnd() % n + 1;
r = rnd() % n + 1;
if( l > r ) swap(l, r);
if( op == 3 )
x = rnd() % (r-l+1) + 1;
else
x = rnd() % vmax + 1;
if( op == 4 )
y = rnd() % vmax + 1;
if( op == 1 ) solve1(l, r, x);
else if( op == 2 ) solve2(l, r, x);
else if( op == 3 ) solve3(l, r, x);
else if( op == 4 ) solve4(l, r, x, y);
// dprint("op = %d, l = %d, r = %d, x = %d, y = %d\n", op, l, r, x, y);
// output_array();
}
return 0;
}
【题解】Willem, Chtholly and Seniorious Codeforces 896C ODT的更多相关文章
- CF&&CC百套计划1 Codeforces Round #449 C. Willem, Chtholly and Seniorious (Old Driver Tree)
http://codeforces.com/problemset/problem/896/C 题意: 对于一个随机序列,执行以下操作: 区间赋值 区间加 区间求第k小 区间求k次幂的和 对于随机序列, ...
- Willem, Chtholly and Seniorious
Willem, Chtholly and Seniorious https://codeforces.com/contest/897/problem/E time limit per test 2 s ...
- 【模板】珂朵莉树(ODT)(Codeforces 896C Willem, Chtholly and Seniorious)
题意简述 维护一个数列,支持区间加,区间赋值,区间求第k小,区间求幂和 数据随机 题解思路 ODT是一种基于std::set的暴力数据结构. 每个节点对应一段区间,该区间内的数都相等. 核心操作spl ...
- 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: ...
- 【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(ODT)
题意 题目链接 Sol ODT板子题.就是用set维护连续段的大暴力.. 然鹅我抄的板子本题RE提交AC??.. 具体来说,用50 50 658073485 946088556这个数据测试下面的代码, ...
- Codeforces Round #449 (Div. 1)C - Willem, Chtholly and Seniorious
ODT(主要特征就是推平一段区间) 其实就是用set来维护三元组,因为数据随机所以可以证明复杂度不超过O(NlogN),其他的都是暴力维护 主要操作是split,把区间分成两个,用lowerbound ...
- 2019.01.19 codeforces896C.Willem, Chtholly and Seniorious(ODT)
传送门 ODTODTODT出处(万恶之源) 题目简述: 区间赋值 区间加 区间所有数k次方和 区间第k小 思路:直接上ODTODTODT. 不会的点这里 代码: #include<bits/st ...
- 题解 CF896C 【Willem, Chtholly and Seniorious】
貌似珂朵莉树是目前为止(我学过的)唯一一个可以维护区间x次方和查询的高效数据结构. 但是这玩意有个很大的毛病,就是它的高效建立在数据随机的前提下. 在数据随机的时候assign操作比较多,所以它的复杂 ...
随机推荐
- python如何与以太坊交互并将区块链信息写入SQLite
关于区块链介绍性的研讨会通常以易于理解的点对点网络和银行分类账这类故事开头,然后直接跳到编写智能合约,这显得非常突兀.因此,想象自己走进丛林,想象以太坊区块链是一个你即将研究的奇怪生物.今天我们将观察 ...
- Django之Models与ORM操作
一.models例子 from django.db import models class User(models.Model): """ 用户表 "" ...
- 我眼中的PD(产品狗)
以下内容可能引起您的不适(前方高能),请先移步科普: 产品经理为什么会存在? 本猿 -> web程序属 -> 前端开发种,从大森林迁徙到了小草原: 小草原物种稀缺,除了 程序猿,很难见到诸 ...
- Shell重新学习(忘光了)
成功和失败都放同一个文件 调试shell
- 欢迎来怼--第三十七次Scrum会议
一.小组信息 队名:欢迎来怼 小组成员 队长:田继平 成员:李圆圆,葛美义,王伟东,姜珊,邵朔,阚博文 小组照片 二.开会信息 时间:2017/12/3 17:50~18:23,总计33min. 地点 ...
- Task 6.2站立会议三
今天我完成了软件的主要聊天界面的视频通话和语音通话的部分功能,过程中遇到很多不会的知识.因为使用的是C#,虽然很容易上手但是还会存在很多不懂得内容.
- Ubuntu登录界面添加root用户登录选项
1.普通用户登录系统并打开终端 配置root密码 $sudo passwd 切换至root用户 $su root 输入密码 修改以下配置文件 $nano /usr/share/lightdm/ligh ...
- Beta后续感想/吐槽
感想 磨人的软工实践终于结束了 艰难的度过了一学期,还是写点什么纪念一下吧. 大一大二的时候就听说软工实践是魔鬼般的锻炼,于是当年不知天高地厚的我是很期待的,终于,我大三了. 后来,我长大了. alp ...
- 23_IO_第23天(字节流、字符流)_讲义
今日内容介绍 1.字节流 2.字符流 01输入和输出 * A:输入和输出 * a: 参照物 * 到底是输入还是输出,都是以Java程序为参照 * b: Output * 把内存中的数据存储到持久化设备 ...
- Java分布式应用
分布式计算就是通过计算机网络将计算工作分布到多台主机上,多个主机一起协同完成工作. 我试着列一下相关知识吧. 网络通讯,网络是分布式的基础,对分布式的理解建立在对网络的理解上,包括: OSI模型的7层 ...