Rabbit的数列

17 篇文章 0 订阅

在这里插入图片描述
在这里插入图片描述
因为 A,B 是随机的,所以分块维护一下颜色即可,当然用其他方法也可以,验题人表示还可以用一个 set/map 存下所有的相同的段,每次把[l,r]这一段分离出来,然后把这一段里面的相同段修改之后合并成

#include<cassert>
#include<cctype>
#include<cerrno>
#include<cfloat>
#include<ciso646>
#include<climits>
#include<clocale>
#include<cmath>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<bitset>
#include<complex>
#include<deque>
#include<exception>
#include<fstream>
#include<functional>
#include<iomanip>
#include<ios>
#include<iosfwd>
#include<iostream>
#include<istream>
#include<iterator>
#include<limits>
#include<list>
#include<locale>
#include<map>
#include<memory>
#include<new>
#include<numeric>
#include<ostream>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<stdexcept>
#include<streambuf>
#include<string>
#include<typeinfo>
#include<utility>
#include<valarray>
#include<vector>
using namespace std;
#define LL long long
const int maxn = 100000 + 100;
int n, c, q;
LL x, y, a, b, p;
int num[maxn << 2], cnt[maxn];
void push_up(int rt) {
    if(num[rt << 1] == num[rt << 1 | 1]) {
        num[rt] = num[rt << 1];
        return ;
    }
    num[rt] = 0;
}
void push_down(int rt) {
    if(num[rt] != 0) {
        num[rt << 1] = num[rt << 1 | 1] = num[rt];
    }
}
void build(int l, int r, int rt) {
    if(l == r) {
        cnt[l] = 0;
        num[rt] = 1;
        return ;
    }
    int m = (l + r) >> 1;
    build(l, m, rt << 1);
    build(m + 1, r, rt << 1 | 1);
    push_up(rt);
}
void dfs(int tmp, int l, int r, int rt) {
    if(num[rt] != 0) {
        cnt[num[rt]] -= (r - l + 1);
        num[rt] = tmp;
        cnt[tmp] += (r - l + 1);
        return ;
    }
    int m = (l + r) >> 1;
    dfs(tmp, l, m, rt << 1);
    dfs(tmp, m + 1, r, rt << 1 | 1);
    push_up(rt);
}
void update(int L, int R, int tmp, int l, int r, int rt) {
    if(L <= l && r <= R) {
        if(num[rt] == 0) {
            dfs(tmp, l, r, rt);
        } else {
            cnt[num[rt]] -= (r - l + 1);
            num[rt] = tmp;
            cnt[tmp] += (r - l + 1);
        }
        return ;
    }
    push_down(rt);
    int m = (l + r) >> 1;
    if(L <= m) {
        update(L, R, tmp, l, m, rt << 1);
    }
    if(R > m) {
        update(L, R, tmp, m + 1, r, rt << 1 | 1);
    }
    push_up(rt);
}
int main() {
    ios::sync_with_stdio(false);
    while(scanf("%d%d%d", &n, &c, &q) != EOF) {
        build(1, n, 1);
        cnt[1] = n;
        for(int i = 0; i < q; ++i) {
            scanf("%lld%lld%lld%lld", &x, &y, &a, &b);
            p = cnt[x];
            LL l = (a + (p + b) * (p + b)) % n;
            LL r = (a + (p * b % n) * (p * b % n) % n) % n;
            LL ll = min(l, r) + 1;
            LL rr = max(l, r) + 1;
            update(ll, rr, y, 1, n, 1);
        }
        int ans = 0;
        for(int i = 1; i <= c; ++i) {
            ans = max(ans, cnt[i]);
        }
        printf("%d\n", ans);
    }
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值