珂朵莉树模板(珂朵莉树)

orz yzhang

学会了一个叫做mutable的关键字

关键操作:Split,将指定位置的区间拆开

洛谷CF896C Willem, Chtholly and Seniorious

#include<bits/stdc++.h>
#define LL long long
#define I inline
#define R register int
using namespace std;
struct Node{
    mutable int l,r;mutable LL v;
    I Node(R a,R b=0,LL c=0):l(a),r(b),v(c){}
    I bool operator<(const Node&a)const{
        return l<a.l;
    }
};
typedef set<Node>::iterator IT;
set<Node>s;
IT d[100009];
I bool operator<(const IT&a,const IT&b){
    return a->v<b->v;
}
I IT Split(R p){
    IT it=s.lower_bound(Node(p));
    if(it!=s.end()&&it->l==p)return it;
    R r=(--it)->r;it->r=p;
    return s.insert(Node(p,r,it->v)).first;
}
int n,m,seed,vmax;
I int Rand(){
    R ret=seed;
    seed=((LL)seed*7+13)%1000000007;
    return ret;
}
I LL Pow(LL b,R k,LL YL,LL a=1){
    for(b%=YL;k;k>>=1,b=b*b%YL)
        if(k&1)a=a*b%YL;
    return a;
}
int main(){
    ios::sync_with_stdio(0);
    cin>>n>>m>>seed>>vmax;
    for(R i=1;i<=n;++i)
        s.insert(Node(i,i+1,Rand()%vmax+1));
    for(R i=1;i<=m;++i){
        R op=Rand()%4+1,l=Rand()%n+1,r=Rand()%n+1,p=0;
        if(l>r)swap(l,r);++r;
        R x=Rand()%(op==3?r-l:vmax)+1;
        IT it=Split(l),en=r>n?s.end():Split(r);
        switch(op){
        case 1:
            for(;it!=en;++it)it->v+=x;
            break;
        case 2:
            s.erase(it,en);
            s.insert(Node(l,r,x));
            break;
        case 3:
            for(;it!=en;++it)d[++p]=it;
            sort(d+1,d+p+1);
            for(p=1;x>0;++p)x-=d[p]->r-d[p]->l;
            cout<<d[p-1]->v<<'\n';
            break;
        case 4:
            LL YL=Rand()%vmax+1,ans=0;
            for(;it!=en;++it)ans=(ans+Pow(it->v,x,YL)*(it->r-it->l))%YL;
            cout<<ans<<endl;
        }
    }
    return 0;
}
posted @   Flash_Hu  阅读(1246)  评论(7编辑  收藏  举报
编辑推荐:
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
· 一个奇形怪状的面试题:Bean中的CHM要不要加volatile?
· [.NET]调用本地 Deepseek 模型
· 一个费力不讨好的项目,让我损失了近一半的绩效!
阅读排行:
· 在鹅厂做java开发是什么体验
· 百万级群聊的设计实践
· WPF到Web的无缝过渡:英雄联盟客户端的OpenSilver迁移实战
· 永远不要相信用户的输入:从 SQL 注入攻防看输入验证的重要性
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
点击右上角即可分享
微信分享提示
哥伦布
-1°
10:09发布
哥伦布
10:09发布
-1°
西南风
2级
空气质量
相对湿度
87%
今天
小雨
-1°/13°
周六
多云
-3°/10°
周日
-4°/2°