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的更多相关文章

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

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

  2. Willem, Chtholly and Seniorious

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

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

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

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

  5. 【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 ...

  6. cf896C. Willem, Chtholly and Seniorious(ODT)

    题意 题目链接 Sol ODT板子题.就是用set维护连续段的大暴力.. 然鹅我抄的板子本题RE提交AC??.. 具体来说,用50 50 658073485 946088556这个数据测试下面的代码, ...

  7. Codeforces Round #449 (Div. 1)C - Willem, Chtholly and Seniorious

    ODT(主要特征就是推平一段区间) 其实就是用set来维护三元组,因为数据随机所以可以证明复杂度不超过O(NlogN),其他的都是暴力维护 主要操作是split,把区间分成两个,用lowerbound ...

  8. 2019.01.19 codeforces896C.Willem, Chtholly and Seniorious(ODT)

    传送门 ODTODTODT出处(万恶之源) 题目简述: 区间赋值 区间加 区间所有数k次方和 区间第k小 思路:直接上ODTODTODT. 不会的点这里 代码: #include<bits/st ...

  9. 题解 CF896C 【Willem, Chtholly and Seniorious】

    貌似珂朵莉树是目前为止(我学过的)唯一一个可以维护区间x次方和查询的高效数据结构. 但是这玩意有个很大的毛病,就是它的高效建立在数据随机的前提下. 在数据随机的时候assign操作比较多,所以它的复杂 ...

随机推荐

  1. JS页面出现Uncaught SyntaxError: Unexpected token < 错误

    action中的查询方法的返回值应该为NONE;

  2. Gogoing 场景调研(补)

    一.典型用户 蜗居在学校的大学生 二.场景描述 编号 用户故事 故事价值 (点数) 1 作为一名大学生,只知道学习 2 经常打游戏而无所事事的大学生 1.背景 (1)典型用户:张晨建 (2)用户的需求 ...

  3. 【转】python 三种遍历list的方法

    [转]python 三种遍历list的方法 #!/usr/bin/env python # -*- coding: utf-8 -*- if __name__ == '__main__': list ...

  4. 作业1.3——Android平台的开发环境的发展演变

    一开始的打算是在eclipse的基础上搭建Android平台,在ADT.SDK上兜兜转转,听过一些前车之鉴后,还是选择了Android studio.因为之前安装过eclipse,就省去了JDK下载和 ...

  5. 结对项目作业报告——四则运算web项目

    成员:顾思宇2016011993 程羚2016012050   1.仓库地址:https://git.coding.net/DandelionClaw/WEB_Calculator.git 注: 本项 ...

  6. 读《构建之法》一、二、十六章随笔a

    第一章    概论 “软件团队要从需求分析开始,把合适的需求梳理出来,然后逐步开展后续工作”:——p3 问题:好的用户体验要从软件分析开始,那么软件分析仅仅是从用户的需求出发吗? 我的看法:需求分析是 ...

  7. ReentrantLock 和 Condition的使用

    ReentrantLock  ReentrantLock可以等同于synchronized使用. ReentrantLock 类实现了Lock ,它拥有与 synchronized 相同的并发性和内存 ...

  8. javascript获取当前日期和时间

    ){ ){ _time = year+"-"+month+"-"+date+" "+hour+":"+minu+&quo ...

  9. Memcache服务器端+Redis服务器端+PHP Memcache扩展+PHP Memcached扩展+PHP Redis扩展+MemAdmin Memcache管理工具+一些概念(更新中)

    Memcache和Redis因为操作简单,是我们常用的服务器数据缓存系统,以下文字仅作备忘记录,部份转载至网络. 一.定义 1.Memcache Memcache是一个高性能的分布式的内存对象缓存系统 ...

  10. C 数据类型——Day02

    C 数据类型 在 C 语言中,数据类型指的是用于声明不同类型的变量或函数的一个广泛的系统.变量的类型决定了变量存储占用的空间,以及如何解释存储的位模式. C 中的类型可分为以下几种: 序号 类型与描述 ...