Willem, Chtholly and Seniorious
Willem, Chtholly and Seniorious
https://codeforces.com/contest/897/problem/E
2 seconds
256 megabytes
standard input
standard output
— Willem...
— What's the matter?
— It seems that there's something wrong with Seniorious...
— I'll have a look...

Seniorious is made by linking special talismans in particular order.
After over 500 years, the carillon is now in bad condition, so Willem decides to examine it thoroughly.
Seniorious has n pieces of talisman. Willem puts them in a line, the i-th of which is an integer ai.
In order to maintain it, Willem needs to perform m operations.
There are four types of operations:
- 1 l r x: For each i such that l ≤ i ≤ r, assign ai + x to ai.
- 2 l r x: For each i such that l ≤ i ≤ r, assign x to ai.
- 3 l r x: Print the x-th smallest number in the index range [l, r], i.e. the element at the x-th position if all the elements ai such that l ≤ i ≤ r are taken and sorted into an array of non-decreasing integers. It's guaranteed that 1 ≤ x ≤ r - l + 1.
- 4 l r x y: Print the sum of the x-th power of ai such that l ≤ i ≤ r, modulo y, i.e.
.
The only line contains four integers n, m, seed, vmax (1 ≤ n, m ≤ 105, 0 ≤ seed < 109 + 7, 1 ≤ vmax ≤ 109).
The initial values and operations are generated using following pseudo code:
def rnd():
ret = seed
seed = (seed * 7 + 13) mod 1000000007
return ret
for i = 1 to n:
a[i] = (rnd() mod vmax) + 1
for i = 1 to m:
op = (rnd() mod 4) + 1
l = (rnd() mod n) + 1
r = (rnd() mod n) + 1
if (l > r):
swap(l, r)
if (op == 3):
x = (rnd() mod (r - l + 1)) + 1
else:
x = (rnd() mod vmax) + 1
if (op == 4):
y = (rnd() mod vmax) + 1
Here op is the type of the operation mentioned in the legend.
For each operation of types 3 or 4, output a line containing the answer.
10 10 7 9
2
1
0
3
10 10 9 9
1
1
3
3
In the first example, the initial array is {8, 9, 7, 2, 3, 1, 5, 6, 4, 8}.
The operations are:
- 2 6 7 9
- 1 3 10 8
- 4 4 6 2 4
- 1 4 5 8
- 2 1 7 1
- 4 7 9 4 4
- 1 2 7 9
- 4 5 8 1 1
- 2 5 7 5
- 4 3 10 8 5
ODT模板题
参考博客:https://blog.csdn.net/niiick/article/details/83062256
#include<bits/stdc++.h>
using namespace std;
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define IT set<node>::iterator
#define sqr(x) ((x)*(x))
#define pb push_back
#define eb emplace_back
#define maxn 100005
#define eps 1e-8
#define pi acos(-1.0)
#define rep(k,i,j) for(int k=i;k<j;k++)
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll>pll;
typedef pair<ll,int> pli;
typedef pair<pair<int,string>,pii> ppp;
typedef unsigned long long ull;
const long long MOD=1e9+;
const double oula=0.57721566490153286060651209;
using namespace std; struct node{
int l,r;
mutable ll val;
node(int L,int R=-,ll V=):l(L),r(R),val(V){}
bool operator<(const node& t)const {
return l<t.l;
}
};
set<node>se; ll ksm(ll a,ll b,ll mod){
ll ans=;
a%=mod;
while(b){
if(b&){
ans=(ans*a)%mod;
}
b>>=;
a=(a*a)%mod;
}
return ans;
} IT split(int pos){
IT it=se.lower_bound(node(pos));
if(it!=se.end()&&it->l==pos) return it;
it--;
int L=it->l,R=it->r;
ll V=it->val;
se.erase(it);
se.insert(node(L,pos-,V));
return se.insert(node(pos,R,V)).first;///返回L==pos的迭代器
} void assign(int l,int r,ll v){
IT itr=split(r+),itl=split(l);
se.erase(itl,itr);///左闭右开
se.insert(node(l,r,v));
} void add(int l,int r,ll v){
IT itr=split(r+);
for(IT itl=split(l);itl!=itr;itl++){
itl->val+=v;
}
} ll Rank(int l,int r,int v){
IT itr=split(r+);
vector<pli>tmp;
for(IT itl=split(l);itl!=itr;itl++){
tmp.pb({itl->val,itl->r-itl->l+});
}
sort(tmp.begin(),tmp.end());
for(int i=;i<tmp.size();i++){
v-=tmp[i].second;
if(v<=){
return tmp[i].first;
}
}
} ll query(int l,int r,ll x,ll y){
IT itr=split(r+);
ll ans=;
for(IT itl=split(l);itl!=itr;itl++){
ans=(ans+((ksm(itl->val,x,y)*(itl->r-itl->l+))%y))%y;
}
return ans;
} ll n,m,seed,vmax; ll rnd(){
ll ans=seed;
seed=(seed*+)%MOD;
return ans;
} int main(){
std::ios::sync_with_stdio(false); cin>>n>>m>>seed>>vmax;
ll x,y;
for(int i=;i<=n;i++){
x=(rnd()%vmax)+;
se.insert(node(i,i,x));
}
int opt,L,R;
for(int i=;i<=m;i++){
opt=(rnd()%)+;
L=(rnd()%n)+;
R=(rnd()%n)+;
if(L>R) swap(L,R);
if(opt==){
x=(rnd()%(R-L+))+;
}
else{
x=(rnd()%vmax)+;
}
if(opt==){
y=(rnd()%vmax)+;
}
if(opt==){
add(L,R,x);
}
else if(opt==){
assign(L,R,x);
}
else if(opt==){
cout<<Rank(L,R,x)<<endl;
}
else{
cout<<query(L,R,x,y)<<endl;
}
}
}
Willem, Chtholly and Seniorious的更多相关文章
- CF&&CC百套计划1 Codeforces Round #449 C. Willem, Chtholly and Seniorious (Old Driver Tree)
http://codeforces.com/problemset/problem/896/C 题意: 对于一个随机序列,执行以下操作: 区间赋值 区间加 区间求第k小 区间求k次幂的和 对于随机序列, ...
- 【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 ...
- 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: ...
- [Codeforces896C] Willem, Chtholly and Seniorious (ODT-珂朵莉树)
无聊学了一下珂朵莉树 珂朵莉树好哇,是可以维护区间x次方和查询的高效数据结构. 思想大致就是一个暴力(相对而言)的树形数据结构 lxl毒瘤太强了,发明了ODT算法(Old Driver Tree老司机 ...
- [CF896C]Willem, Chtholly and Seniorious(珂朵莉树)
https://www.cnblogs.com/WAMonster/p/10181214.html 主要用于支持含有较难维护的区间操作与查询的问题,要求其中区间赋值操作(assign())是纯随机的. ...
- 2019.01.19 codeforces896C.Willem, Chtholly and Seniorious(ODT)
传送门 ODTODTODT出处(万恶之源) 题目简述: 区间赋值 区间加 区间所有数k次方和 区间第k小 思路:直接上ODTODTODT. 不会的点这里 代码: #include<bits/st ...
- 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 ...
- 【Cf #449 C】Willem, Chtholly and Seniorious(set维护线段)
这里介绍以个小$trick$,民间流传为$Old Driver Tree$,实质上就是$set$维护线段. 我们将所有连续一段权值相同的序列合并成一条线段,扔到$set$里去,于是$set$里的所有线 ...
随机推荐
- 《Linux内核原理与分析》第三周作业
实验:基于kernel的简单的时间片轮转多道程序内核 1.实验要求 完成一个简单的时间片轮转多道程序内核代码 2.实验过程 进入实验楼的linux环境,打开shell,输入以下代码: cd Linux ...
- objdump和backtrace的配合使用
在程序调试过程中程序崩溃的情况时有发生,把出问题时的调用栈信息打印出来是一种不错的解决办法. 当然还有一些其他方法:https://www.cnblogs.com/jiangyibo/p/865372 ...
- web前端常用代码于面试等资源
https://www.cnblogs.com/moqiutao/p/4766146.html
- Hanlp中N最短路径分词详细介绍
N-最短路径 是中科院分词工具NLPIR进行分词用到的一个重要算法,张华平.刘群老师在论文<基于N-最短路径方法的中文词语粗分模型>中做了比较详细的介绍.该算法算法基本思想很简单,就是给定 ...
- FTP文件传输服务
FTP文件传输服务 一 .FTP 连接及传输的模式 l 控制连接:TCP21,用于发送FTP命令信息. l 数据连接:TCP 20, 用于上传下载数据. · 数据连接建立的类型: ·主动模式: 服 ...
- Flask--(项目准备)--框架搭建,参数配置
项目准备: 配置参数 项目配置: 新建工程: 配置虚拟环境: 通过配置类添加配置参数: Debug配置, 初始化数据库对象, Mysql配置及数据库创建 redis配置: 端口6379和域名: 创建存 ...
- java中int算法的有趣现象
今天无意中发现一个怪事,当时没理解,后来跟网友讨论了才知道原理,是关于int值的加法算法,两段代码如下: 代码1: @Test public void test1() { ; ; try { whil ...
- 从Tomcat的处理web请求分析Java的内存模型
Tomcat作为一个java应用,同样是有主线程和子线程的.主线使用while(true)的方式一直循环,等待客户端来连接.一个客户端来了之后,就从线程池中拿一个线程来处理请求,如果没有配置线程池,就 ...
- windows本地eclispe运行linux上hadoop的maperduce程序
继续上一篇博文:hadoop集群的搭建 1.将linux节点上的hadoop安装包从linux上下载下来(你也可以从网上直接下载压缩包,解压后放到自己电脑上) 我的地址是: 2.配置环境变量: HAD ...
- 利用Kettle 从Excel中抽取数据写入SQLite
SQLite作为一种数据库可以配置为Kettle的数据输入和输出,这个例子是从Excel中抽取数据然后写入到SQLite中 配置测试并成功后如下 下面是配置步骤: Excel输入配置 sqlite配置 ...