cf896C. Willem, Chtholly and Seniorious(ODT)

Posted zwfymqz

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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
", 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
", 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) << '
';
        else cout << po(l, r, x) << '
';
    }
    return 0;
}
/*
50 50 658073485 946088556
*/

以上是关于cf896C. Willem, Chtholly and Seniorious(ODT)的主要内容,如果未能解决你的问题,请参考以下文章

CF896C Willem, Chtholly and Seniorious

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

CF896C Willem, Chtholly and Seniorious

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

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

CF896EWelcome home, Chtholly 暴力+分块+链表