Willem, Chtholly and Seniorious

https://codeforces.com/contest/897/problem/E

time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

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:

  • l r x: For each i such that l ≤ i ≤ r, assign ai + x to ai.
  • l r x: For each i such that l ≤ i ≤ r, assign x to ai.
  • 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.
  • l r x y: Print the sum of the x-th power of ai such that l ≤ i ≤ r, modulo y, i.e. .
Input

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.

Output

For each operation of types 3 or 4, output a line containing the answer.

Examples
input

Copy
10 10 7 9
output

Copy
2
1
0
3
input

Copy
10 10 9 9
output

Copy
1
1
3
3
Note

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

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

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

  4. [Codeforces896C] Willem, Chtholly and Seniorious (ODT-珂朵莉树)

    无聊学了一下珂朵莉树 珂朵莉树好哇,是可以维护区间x次方和查询的高效数据结构. 思想大致就是一个暴力(相对而言)的树形数据结构 lxl毒瘤太强了,发明了ODT算法(Old Driver Tree老司机 ...

  5. [CF896C]Willem, Chtholly and Seniorious(珂朵莉树)

    https://www.cnblogs.com/WAMonster/p/10181214.html 主要用于支持含有较难维护的区间操作与查询的问题,要求其中区间赋值操作(assign())是纯随机的. ...

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

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

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

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

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

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

  9. 【Cf #449 C】Willem, Chtholly and Seniorious(set维护线段)

    这里介绍以个小$trick$,民间流传为$Old Driver Tree$,实质上就是$set$维护线段. 我们将所有连续一段权值相同的序列合并成一条线段,扔到$set$里去,于是$set$里的所有线 ...

随机推荐

  1. java.io.EOFException ValueOperations.increment()操作后,获取值时有的bug

    ---恢复内容开始--- 今天使用spring-data-redis包操作redis,就是简单的使用redis的计数功能,在redis中的操作命令如:incr key;get key; 这两步操作使用 ...

  2. 使用Log4net 日志系统

    官方文档 http://logging.apache.org/log4net/release/config-examples.html C# 项目中直接使用nuget,下载Apache的log4net ...

  3. linux下insmod模块出现“Invalid parameters"

    在编译一个模块时,会出现WARNING:"函数名" undefined!,这 说明该模块所依赖的模块还没有加载进内核,需要先加载所依赖的模块. 当加载依赖模块后,使用insmod会 ...

  4. Flume调优

    这是一个关于池子的故事.有一个池子,它一头进水,另一头出水,进水口可以配置各种管子,出水口也可以配置各种管子,可以有多个进水口.多个出水口.水术语称为Event,进水口术语称为Source.出水口术语 ...

  5. requests库(爬虫)

    北京理工大学嵩天老师的课程:http://www.icourse163.org/course/BIT-1001870001 官方文档:http://docs.python-requests.org/e ...

  6. oracle表被锁(delete或update一直处于执行状态)的处理办法。

    --首先查看有哪些锁 select /*+ rule */ s.username, decode(l.type,'TM','TABLE LOCK','TX','ROW LOCK',null) lock ...

  7. SpringSecurity-FilterSecurityInterceptor的作用

    FilterSecurityInterceptor也是很重要的一个interceptor,它的作用是对request进行权限判断,允许访问或者抛出accessDenied异常. 这个类继承Abstra ...

  8. java File处理

    /**************************************************************************************工具类********** ...

  9. [转]Java事件处理机制- 事件监听器的四种实现方式

    原文来自http://stefan321.iteye.com/blog/345221 自身类作为事件监听器 外部类作为事件监听器 匿名内部类作为事件监听器 内部类作为事件监听器 自身类作为事件监听器: ...

  10. Zookeeper集群节点数量为什么要是奇数个?

    无论是公司的生产环境,还是自己搭建的测试环境,Zookeeper集群的节点个数都是奇数个.至于为什么要是奇数个,以前只是模糊的知道是为了满足选举需要,并不知道详细的原因.最近重点学习zookeeper ...