ODT模板题,ODT适合随机数据下具有维护区间推平操作的序列维护题目,时间复杂度较为玄学。。

代码如下

#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()
using namespace std;
const int maxn=1e5+10;
const int mod=1e9+7;
typedef long long LL;
LL fpow(LL a,LL b,LL c){
LL ret=1%c;
for(;b;b>>=1,a=a*a%c)if(b&1)ret=ret*a%c;
return ret;
} int n,m;
LL seed,vmax;
LL rnd(){
LL ret=seed;
seed=(seed*7+13)%mod;
return ret;
}
struct node{
int l,r;
mutable LL val;
node(int x=0,int y=0,LL z=0):l(x),r(y),val(z){}
bool operator<(const node &rhs)const{
return this->l<rhs.l;
}
};
set<node> s;
auto split(int pos){
auto it=s.lower_bound(node(pos));
if(it!=s.end()&&it->l==pos)return it;
--it;
int l=it->l,r=it->r;
LL val=it->val;
s.erase(it);
s.insert(node(l,pos-1,val));
return s.insert(node(pos,r,val)).first;
}
void add(int l,int r,LL x){
auto itr=split(r+1),itl=split(l);
for(auto it=itl;it!=itr;it++)it->val+=x;
}
void assign(int l,int r,LL x){
auto itr=split(r+1),itl=split(l);
s.erase(itl,itr);
s.insert(node(l,r,x));
}
LL kth(int l,int r,int k){
auto itr=split(r+1),itl=split(l);
vector<pair<LL,int>> v;v.clear();
for(auto it=itl;it!=itr;it++){
v.pb(mp(it->val,it->r-it->l+1));
}
sort(all(v));
for(auto p:v){
k-=p.second;
if(k<=0)return p.first;
}
return -1;
}
LL sum(int l,int r,int x,int y){
auto itr=split(r+1),itl=split(l);
LL ret=0;
for(auto it=itl;it!=itr;it++){
ret=(ret+fpow(it->val%y,x,y)*(it->r-it->l+1)%y)%y;
}
return ret;
} int main(){
scanf("%d%d%lld%lld",&n,&m,&seed,&vmax);
for(int i=1;i<=n;i++){
s.insert(node(i,i,rnd()%vmax+1));
}
s.insert(node(n+1,n+1,0)); while(m--){
int opt=rnd()%4+1,l=rnd()%n+1,r=rnd()%n+1,x,y;
if(l>r)swap(l,r);
if(opt==3)x=rnd()%(r-l+1)+1;
else x=rnd()%vmax+1;
if(opt==4)y=rnd()%vmax+1;
if(opt==1)add(l,r,x);
else if(opt==2)assign(l,r,x);
else if(opt==3)printf("%lld\n",kth(l,r,x));
else if(opt==4)printf("%lld\n",sum(l,r,x,y));
} return 0;
}

【CF896C】Willem, Chtholly and Seniorious的更多相关文章

  1. 【题解】Willem, Chtholly and Seniorious Codeforces 896C ODT

    Prelude ODT这个东西真是太好用了,以后写暴力骗分可以用,写在这里mark一下. 题目链接:ヽ(✿゚▽゚)ノ Solution 先把原题解贴在这里:(ノ*・ω・)ノ 简单地说,因为数据是全部随 ...

  2. 【Luogu】P3933 Chtholly Nota Seniorious

    [题意]将n*m矩阵分成两个区域,要求满足一定条件,求两区域内部极差较大值最小.n,m<=2000 [算法]二分 [题解]极差的数值满足单调性,所以考虑二分极差. 对于给定的极差,将所有数值排序 ...

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

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

  4. Willem, Chtholly and Seniorious

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

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

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

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

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

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

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

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

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

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

随机推荐

  1. linux配置多个ip

    linux配置多个ip /sbin/ifconfig eth0:1 172.19.121.180 broadcast 172.19.121.255  netmask 255.255.255.0 up ...

  2. 精通CSS:高级Web标准解决方案(第二版) 不明白的地方

    P47 在图3-14中,当把框1向左浮动时,它脱离文档流并且向左移动,直到它的左边缘碰到包含框的左边缘.因为它不在处于文档流中,所以它不占据空间,实际上覆盖住了框2,使框2从视图中消失. 我的疑问是, ...

  3. 自己用canvas写的贪吃蛇代码

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  4. Hand on Machine Learning第三章课后作业(1):垃圾邮件分类

    import os import email import email.policy 1. 读取邮件数据 SPAM_PATH = os.path.join( "E:\\3.Study\\机器 ...

  5. Spring源码阅读环境搭建

    目录 安装gradle 导入Spring源码 创建测试模块my-test 其他问题 spring-aspects模块构建时报错 本文思维导图 本文将粗略的搭建一个Spring源码的阅读环境,为后面的源 ...

  6. 【VS开发】设置文档标题

    [注意]我们注意到我们的文档的创建的时候我们会发现系统会去调用Doc类中的OnNewDocument函数,这里我们知道他是一个虚函数,我们可以在这里设置我们的文档的标题. 代码如下: BOOL CGr ...

  7. win10 hhctrl.ocx 丢失

    1.我的是从同事电脑上复制过来的,他电脑也是win102.复制文件“hhctrl.ocx”到系统目录下  32位系统目录为:C:\WINNT\System32:64位系统为C:\Windows\Sys ...

  8. Python 正则匹配网页内的IP地址及端口号

    #!/usr/bin/env python # -*- coding: utf-8 -*- # @Date : 2017-08-30 20:38:23 # @Author : EnderZhou (z ...

  9. HDU 2094 产生冠军(STL map)

    产生冠军 Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submis ...

  10. FESCAR

    FESCAR:阿里重磅开源分布式事务解决方案 FESCAR名字的由来:Fast & EaSy Commit And Rollback FESCAR是啥? 被用在微服务架构中的高性能分布式事务解 ...