cf896C. Willem, Chtholly and Seniorious(ODT)

题意

题目链接

Sol

ODT板子题。就是用set维护连续段的大暴力。。

然鹅我抄的板子本题RE提交AC??。。

具体来说,用50 50 658073485 946088556这个数据测试下面的代码,然后在79行停住,看一下bg和i的值会发生神奇的事情。。

问题已解决,确实是那位博主写错了, 只要把split(l)和split(r + 1)反过来就行了

#include<bits/stdc++.h>
#define LL long long
#define int long long
#define sit set<Node>::iterator
#define fi first
#define se second
using namespace std;
const int MOD = 1e9 + 7, MAXN = 1e6 + 10;
inline int read() {
    char c = getchar(); int x = 0, f = 1;
    while(c < '0' || c > '9') {if(c == '-') f = -1; c = getchar();}
    while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
    return x * f;
}
int N, M, mod;
template<typename A, typename B> inline int mul(A x, B y) {
    return 1ll * x * y % mod;
}
template<typename A, typename B> inline void add2(A &x, B y) {
    x = (x + y % mod);
}
LL seed, vmax;
int a[MAXN];
int rnd() {
    int ret = seed;
    seed = (seed * 7 + 13) % MOD;
    return ret;
}
struct Node {
    int l, r;
    mutable LL v;
    bool operator < (const Node &rhs) const {
        return l < rhs.l;
    }
};
set<Node> s;
sit split(int p) {
    auto pos = s.lower_bound({p});
    if(pos != s.end() && pos->l == p) return pos;
    pos--;
    int L = pos->l, R = pos->r, V = pos->v;
    s.erase(pos);
    s.insert({L, p - 1, V});
    return s.insert({p, R, V}).fi;
}
void Add(int l, int r, int val) {
    auto bg = split(l), ed = split(r + 1);
    for(auto i = bg; i != ed; i++) i->v += val;
}
void Mem(int l, int r, int val) {
    for(int i = l; i <= r; i++) a[i] = val;
    auto bg = split(l), ed = split(r + 1);
    s.erase(bg, ed);
    s.insert({l, r, val});
}
int rak(int l, int r, int x) {
    vector<pair<LL, int>> v;
    auto bg = split(l), ed = split(r + 1);
    for(auto i = bg; i != ed; i++)
        v.push_back({i->v, i->r - i->l + 1});   

    sort(v.begin(), v.end());
    for(auto it = v.begin(); it != v.end(); it++) {
        x -= it -> se;
        if(x <= 0) return it -> fi;
    }
    assert(0);
}
int fp(int a, int p) {
    int base = 1; a %= mod;
    while(p) {
        if(p & 1) base = 1ll * base * a % mod;
        a = 1ll * a * a % mod; p >>= 1;
    }
    return base;
}
int po(int l, int r, int x) {
    if(l == 6 && r == 7) {
        puts("G");
    }
    auto bg = split(l);
    printf("%d %d %d %d\n", bg->l, bg->r, bg->v);
    auto ed = split(r + 1);
    int ans = 0;
    for(sit i = bg; i != ed; i++) {
        printf("%d %d %d %d\n", i->l, i->r, i->v);
        ans = (ans + (i->r - i->l + 1) * fp(i->v, x) % mod) % mod;
    }
    return ans;
}
signed main() {
    N = read(); M = read(); seed = read(); vmax = read();
    for(int i = 1; i <= N; i++) a[i] = (rnd() % vmax) + 1, s.insert({i, i, a[i]});
    s.insert({N + 1, N + 1, 0});
    for(int i = 1; i <= M; i++) {
        int op = (rnd() % 4) + 1; int l = (rnd() % N) + 1; int r = (rnd() % N) + 1, x = -1;
        if(l > r) swap(l, r);

        if(op == 3) x = (rnd() % (r - l + 1)) + 1;
        else x = (rnd() % vmax) + 1;
        if(op == 4) mod = (rnd() % vmax) + 1;
        if(op == 1) Add(l, r, x);
        else if(op == 2) Mem(l, r, x);
        else if(op == 3) cout << rak(l, r, x) << '\n';
        else cout << po(l, r, x) << '\n';
    }
    return 0;
}
/*
50 50 658073485 946088556
*/

原文地址:https://www.cnblogs.com/zwfymqz/p/10357168.html

时间: 2024-08-30 14:38:33

cf896C. Willem, Chtholly and Seniorious(ODT)的相关文章

CF896C Willem, Chtholly and Seniorious 珂朵莉树

问题描述 CF896C LG-CF896C 题解 我expect就是T飞,从这里跳下去,也不碰和珂朵莉相关的任何东西. 珂朵莉树真好使. 珂朵莉树模板. \(\mathrm{Code}\) #include<bits/stdc++.h> using namespace std; #define int long long #define IT set<node>::iterator template <typename Tp> void read(Tp &x){

CF896C Willem, Chtholly and Seniorious

话说,研究珂学的最好方式是-- 其实珂朵莉树很久之前就看过UESTC的那个介绍了,但是由于太菜,听都听不懂. 现在过来学一学,才发现太暴力太优美了!我爱珂朵莉... 这道题要你弄的4个操作是区间加.区间推平.区间排序后的第\(k\)大值和区间任意幂次和. 比较有难度的就是区间任意幂次和.暴力显然行不通的啊!!! 讲道理,珂朵莉树是我看过的唯一支持维护区间任意幂次和的数据结构. 所以用珂朵莉树来搞一搞? 珂朵莉树的单个节点是这样的: struct Nodes { ll l, r; mutable

Solution: 题解 CF896C Willem, Chtholly and Seniorious(线段树解珂朵莉树)

Intro: 珂朵莉树模板题 怎么所有题解都是珂朵莉树啊啊啊啊 于是本蒟蒻决定来一发中(feng)规(kuang)中(luan)矩(gao)的线段树 首先这棵线段树只维护懒标记 来一发定义 线段树节点\(u\)维护区间\([l_u,r_u]\)的内容 懒标记\(t_u\):当\(t_u\not=0\)时表示区间\([l_u,r_u]\)全是\(t_u\),\(t_u=0\)就是没有懒标记 建立线段树 在建立时顺便处理\(l_u,r_u\),只要当\(l_u=r_u\)时就打上标记 P.s \(L

[ODT]CF 896 C. Willem, Chtholly and Seniorious

题目描述 给出\(n\)个数,支持区间加,区间覆盖,区间第\(k\)小,区间的\(x\)次幂和.数据随机 解题思路 学ODT之前,第四个操作我是维护不来的. 第一次写ODT,ODT在数据随机有区间覆盖操作的情况下有优秀的复杂度. 关键就是用一棵平衡树维护覆盖的区间,其他就是暴力...... #include<cstdio> #include<set> #include<algorithm> #define IT set<jz>::iterator #defi

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

无聊学了一下珂朵莉树 珂朵莉树好哇,是可以维护区间x次方和查询的高效数据结构. 思想大致就是一个暴力(相对而言)的树形数据结构 lxl毒瘤太强了,发明了ODT算法(Old Driver Tree老司机算法) 这里有一个大佬ACDreamer的题解 附上链接https://www.luogu.org/blog/ACdreamer/solution-cf896c 还有一个B站的讲解视频 附上链接https://www.bilibili.com/video/av21651173 我不会用珂朵莉树,但是

Linux下markdown编辑软件 — retext 支持实时预览,存为pdf、html、ODT等

本文由Suzzz原创,发布于 http://www.cnblogs.com/Suzzz/p/4129368.html,转载请保留此声明 ReText是一个linux下的markdown和reStructedText的编辑器,支持实时预览.输出为pdf.html.ODT等功能. 直接上效果图 查看生成的 html 代码

git diff odt文件

odt文件其实由若干文本文件组成,git 经过一些配置是可以支持diff的. step 1: 在git项目中i添加.gitattributes文件, 内容如下: *.odt diff=odt step 2: 在.git/config文件中添加下面一段: [diff "odt"] binary = true textconv = /usr/local/bin/odt-to-txt step 3: 创建/usr/local/bin/odt-to-txt文件,并添加内容如下: #! /usr

How to Install office 365 Plus without ODT

The URL for download ODT: Office 2016 Deployment Tool This is for Install skype for business, Than I will reywrite this  for office365 Puls This guide will walk you through downloading and installing Office or Office Products using the Office Deploym

windows下怎么打开odt 文件

http://blog.csdn.net/pipisorry/article/details/39891197 odt文件 ODT是Openoffice存档的文件格式,Openoffice是一套跨平台的办公室软件套件,Openoffice能在 Windows.Linux.MacOS X (X11).和 Solaris 等操作系统上执行. 它与各个主要的办公室软件套件兼容.OpenOffice.org 是自由软件,任何人都可以免费下载.使用! odt文件怎么打开 1.在没有安装Openoffice