\(\text{Solution}\)
一眼 \(ODT\)
为避免每次都数颜色数量,提前记录下来,每次修改更新下
\(\text{Code}\)
#include <cstdio>
#include <iostream>
#include <set>
#define re register
using namespace std;
const int N = 1e5 + 5;
int L, c, m, cnt[N];
inline void read(int &x)
{
x = 0; char ch = getchar();
for(; !isdigit(ch); ch = getchar());
for(; isdigit(ch); x = (x<<3) + (x<<1) + (ch^48), ch = getchar());
}
struct node{
int l, r; mutable int v;
inline node(int l, int r, int v):l(l), r(r), v(v){};
inline bool operator < (const node &a) const {return l < a.l;}
};
typedef set<node>::iterator iter;
set<node> T;
inline iter split(int x)
{
if (x >= L) return T.end();
iter it = --T.upper_bound(node{x, 0, 0});
if (it->l == x) return it;
int l = it->l, r = it->r, v = it->v;
T.erase(it), T.insert(node{l, x - 1, v});
return T.insert(node{x, r, v}).first;
}
inline void assign(int l, int r, int v)
{
iter itr = split(r + 1), itl = split(l);
for(re iter it = itl; it != itr; ++it) cnt[it->v] -= (it->r - it-> l + 1);
T.erase(itl, itr), cnt[v] += r - l + 1, T.insert(node{l, r, v});
}
int main()
{
read(L), read(c), read(m), T.insert(node{0, L - 1, 1}), cnt[1] = L;
for(int p, x, a, b, s, l, r; m; --m)
{
read(p), read(x), read(a), read(b), s = cnt[p];
l = (a + (long long)s * s) % L, r = (a + (long long)(s + b) * (s + b)) % L;
if (l > r) swap(l, r); assign(l, r, x);
}
int mx = 0;
for(re int i = 1; i <= c; i++) mx = (cnt[i] > mx ? cnt[i] : mx);
printf("%d\n", mx);
}