传送门

ODTODTODT出处(万恶之源)

题目简述:

  1. 区间赋值
  2. 区间加
  3. 区间所有数k次方和
  4. 区间第k小

思路:直接上ODTODTODT。

不会的点这里

代码:

#include<bits/stdc++.h>
#define ri register int
using namespace std;
inline int read(){
    int ans=0;
    char ch=getchar();
    while(!isdigit(ch))ch=getchar();
    while(isdigit(ch))ans=(ans<<3)+(ans<<1)+(ch^48),ch=getchar();
    return ans;
}
const int N=1e5+5;
typedef long long ll;
typedef pair<ll,int> pli;
vector<pli>q;
struct Node{
    int l,r;
    mutable ll v;
    Node(int l_,int r_=-1,ll v_=0):l(l_),r(r_),v(v_){}
    friend inline bool operator<(const Node&a,const Node&b){return a.l<b.l;}
};
set<Node>S;
typedef set<Node>::iterator It;
inline It split(int pos){
    It it=S.lower_bound(Node(pos));
    if(it!=S.end()&&it->l==pos)return it;
    --it;
    int l=it->l,r=it->r;
    ll v=it->v;
    return S.erase(it),S.insert(Node(l,pos-1,v)),S.insert(Node(pos,r,v)).first;
}
inline int ksm(ll a,int p,ll mod){int ret=1;a%=mod;for(;p;p>>=1,a=a*a%mod)if(p&1)ret=a*ret%mod;return ret;}
inline void assign(int l,int r,ll v){
    It R=split(r+1),L=split(l);
    return S.erase(L,R),(void)S.insert(Node(l,r,v));
}
inline void add(int l,int r,ll v){
    It L=split(l),R=split(r+1);
    for(It it=L;it!=R;++it)(it->v)+=v;
}
inline ll Rank(int l,int r,int kth){
    It R=split(r+1),L=split(l);
    q.clear();
    for(It it=L;it!=R;++it)q.push_back(pli(it->v,it->r-it->l+1));
    sort(q.begin(),q.end());
    for(ri i=0;i<q.size();++i){
        kth-=q[i].second;
        if(kth<=0)return q[i].first;
    }
    return -1;
}
inline ll query(int l,int r,int k,ll mod){
    ll ret=0;
    It L=split(l),R=split(r+1);
    for(It it=L;it!=R;++it)ret=(ret+(ll)(it->r-it->l+1)*ksm(it->v,k,mod)%mod)%mod;
    return ret;
}
int n,m,vmax,seed;
inline int rd(){
  int ret=seed;
  seed=(7ll*seed+13)%1000000007;
  return ret;
}
int main(){
    n=read(),m=read(),seed=read(),vmax=read();
    for(ri i=1;i<=n;++i)S.insert(Node(i,i,rd()%vmax+1));
    for(ri i=1,op,L,R,x,y;i<=m;++i){
        op=rd()%4+1,L=rd()%n+1,R=rd()%n+1;
        if(L>R)swap(L,R);
        if(op==3)x=rd()%(R-L+1)+1;
        else x=rd()%vmax+1;
        if(op==4)y=rd()%vmax+1;
        switch(op){
            case 1:add(L,R,x);break;
            case 2:assign(L,R,x);break;
            case 3:cout<<Rank(L,R,x)<<'\n';break;
            default:cout<<query(L,R,x,y)<<'\n';
        }
    }
    return 0;
}

2019.01.19 codeforces896C.Willem, Chtholly and Seniorious(ODT)的更多相关文章

  1. 2019.01.19 洛谷P2787 语文1(chin1)- 理理思维(ODT)

    传送门 ODTODTODT水题. 题意:有一个字母序列,支持区间赋值,查询区间某个字母的数量,区间按字母序排序. 思路: 可以开262626棵线段树搞过去,然而也可以用ODTODTODT秒掉. 如果用 ...

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

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

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

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

  4. CF896C Willem, Chtholly and Seniorious(珂朵莉树)

    中文题面 珂朵莉树的板子……这篇文章很不错 据说还有奈芙莲树和瑟尼欧里斯树…… 等联赛考完去学一下(逃 //minamoto #include<bits/stdc++.h> #define ...

  5. 2019.01.17 bzoj2753: [SCOI2012]滑雪与时间胶囊(最小生成树)

    传送门 最小生成树菜题. 题意:给出一些有向边,问有向的最小生成树. 思路:先dfsdfsdfs一把所有有用的边都存起来,然后按终点点权为第一关键字,边权为第二关键字给边排序保证最小生成树的合法性,排 ...

  6. 2019.01.02 NOIP训练 三七二十一(生成函数)

    传送门 生成函数基础题. 题意简述:求由1,3,5,7,9这5个数字组成的n位数个数,要求其中3和7出现的次数都要是偶数. 考虑对于每个数字构造生成函数. 对于1,5,9:∑nxnn!=ex\sum_ ...

  7. 【2019.5.19】接口测试及python基础(一)

      一.接口 1.什么是接口: 简单的说,接口就是从数据库获取数据. 2.前端和后端: 2.1前端client: 对于web来说,打开的网页,我们所看到的就是前端,前端语言包括html.JS.CSS: ...

  8. Willem, Chtholly and Seniorious

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

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

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

随机推荐

  1. Class语法糖

    TypeScript源码 class A { hello() { } } class B extends A{ welcome() { } } TypeScript编译 var __extends = ...

  2. TZOJ 3030 Courses(二分图匹配)

    描述 Consider a group of N students and P courses. Each student visits zero, one or more than one cour ...

  3. Java项目学习笔记(一)

    2017/2/27 一.target属性 <a>标签的target属性规定在什么地方打开该链接文档. 1.打开新窗口,将文档重定向到一个单独的窗口. <a href="a. ...

  4. 两个App之间的跳转 并传值

    两个App之间的传值最主要的是方法是 Intent intent = getPackageManager().getLaunchIntentForPackage("com.example.a ...

  5. python读写剪贴板

    #coding:utf-8 import os import time import win32api import win32con import win32clipboard as w impor ...

  6. ie6 PNG图片透明

    _background:none; _filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src=images/videoTips.pn ...

  7. hdu 1010(DFS) 骨头的诱惑

    http://acm.hdu.edu.cn/showproblem.php?pid=1010 题目大意从S出发,问能否在时间t的时候到达终点D,X为障碍 需要注意的是要恰好在t时刻到达,而不是在t时间 ...

  8. How to Solve Lonsdor K518ISE Abnormal Display by Factory Resetting

    Here’s the working solution to Lonsdor K518ISE Key Programmer abnormal display after upgrade. Proble ...

  9. [转载]linux awk命令详解

    简介 awk是一个强大的文本分析工具,相对于grep的查找,sed的编辑,awk在其对数据分析并生成报告时,显得尤为强大.简单来说awk就是把文件逐行的读入,以空格为默认分隔符将每行切片,切开的部分再 ...

  10. Xstream将XML转换为javabean的问题

    1.问题:Xstream is not security 解决方法:加上 2.问题:如果没有第二行代码,会出现xstream forbiddenclassexception 解决方法:加上第二行,其中 ...