【题解】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操作比较多,所以它的复杂 ...
随机推荐
- 使用SSD目标检测c++接口编译问题解决记录
本来SSD做测试的Python接口用起来也是比较方便的,但是如果部署集成的话,肯定要用c++环境,于是动手鼓捣了一下. 编译用的cmake,写的CMakeList.txt,期间碰到一些小问题,简单记录 ...
- JAVA第一次实验 ——凯撒密码
课程:Java程序设计 班级:1352 姓名:黄伟业 学号:20135215 成绩: 指导教师:娄嘉鹏 实验日期:2015.4.15 实验密级: 预习程度: 实验时间:19: ...
- mysql 修改语句及耗时
1.含有某串字母的字段替换: update imagetable set imageID = replace(imageID, 'ZH0211001', 'ZH4111001') 只要imageID含 ...
- 软工1816 · Beta冲刺(3/7)
团队信息 队名:爸爸饿了 组长博客:here 作业博客:here 组员情况 组员1(组长):王彬 过去两天完成了哪些任务 协助后端完成历史记录接口.美食排行榜接口 完成食堂平面图的绘制 确定web端业 ...
- Leetcode题库——15.三数之和
@author: ZZQ @software: PyCharm @file: threeSum.py @time: 2018/10/6 19:47 说明:给定一个包含 n 个整数的数组 nums,判断 ...
- 校园跳蚤市场-Sprint计划(第二阶段)
- python learning Regular Expression.py
# 正则表达式,又称规则表达式.(英语:Regular Expression,在代码中常简写为regex.regexp或RE),计算机科学的一个概念.正则表达式通常被用来检索.替换那些符合某个模式(规 ...
- 怎样利用好单片机上的存储器资源来实现OD的存储与访问
转自:http://www.cnblogs.com/winshton/p/4897789.html 我们知道OD(对象字典)是CANopen的核心,所有功能都是围绕它开展的,是协议栈的数据中心,良好的 ...
- 3ds Max学习日记(十)——显示场景资源管理器
之前把max的对象窗口(场景资源管理器)给弄没了,搞了半天都不知道怎么调回来,百度搜索到的结果也不知道都是些啥玩意.不过好在最后还是弄出来了! 一开始是下面这样的,没有场景资源管理器用起来很不 ...
- IDEA 开发工具的快捷键
IDEA 开发工具的快捷键 原文链接:http://blog.csdn.net/wfp458113181wfp/article/details/24579781 1.文本编辑 删除 ctr + ...