本来想像 APJ 一样刷 *3000+ 的……结果发现完全做不动
没在集训,所以会酌 quan 情 bu 口胡(
斜体表示看了题解。
CF1928F *2900
题意:给 ,答案是 二元组个数,满足
-
,
-
内没有相邻相同元素, 内没有相邻相同元素,
每次对 或 区间加,每次操作后求答案。
卡了一年常数。
#include <set>
#include <cstdio>
using namespace std;
set<int> C, D;
int N, n, m, q, _c[300050], _d[300050];
long long _a[300050], _b[300050];
struct T
{
long long sa, sb, va, vb, q, za1, za2, zb1, zb2;
} R[300050 << 2];
inline void u(int s, int t, int p)
{
int m = s + t >> 1;
R[p].q = R[p << 1].q + R[p << 1 | 1].q;
R[p].sa = R[p << 1].sa + R[p << 1 | 1].sa;
R[p].sb = R[p << 1].sb + R[p << 1 | 1].sb;
R[p].va = R[p << 1].va + R[p << 1].sa * (t - m) + R[p << 1 | 1].va;
R[p].vb = R[p << 1].vb + R[p << 1].sb * (t - m) + R[p << 1 | 1].vb;
}
inline void fa(int x, int y, int s, int t, int p)
{
R[p].q += x * R[p].vb + y * R[p].sb;
R[p].sa += (t - s + 1ll) * (t - s + 2ll) / 2 * x + (t - s + 1ll) * y;
R[p].va += (t - s + 1ll) * (t - s + 2ll) * (2 * t - 2 * s + 3ll) / 6 * x + (t - s + 1ll) * (t - s + 2ll) / 2 * y;
R[p].za1 += x, R[p].za2 += y;
}
inline void fb(int x, int y, int s, int t, int p)
{
R[p].q += x * R[p].va + y * R[p].sa;
R[p].sb += (t - s + 1ll) * (t - s + 2ll) / 2 * x + (t - s + 1ll) * y;
R[p].vb += (t - s + 1ll) * (t - s + 2ll) * (2 * t - 2 * s + 3ll) / 6 * x + (t - s + 1ll) * (t - s + 2ll) / 2 * y;
R[p].zb1 += x, R[p].zb2 += y;
}
inline void d(int s, int t, int p)
{
int m = s + t >> 1;
if (R[p].za1)
{
fa(R[p].za1, R[p].za1 * (t - m), s, m, p << 1);
fa(R[p].za1, 0, m + 1, t, p << 1 | 1);
R[p].za1 = 0;
}
if (R[p].za2)
{
fa(0, R[p].za2, s, m, p << 1);
fa(0, R[p].za2, m + 1, t, p << 1 | 1);
R[p].za2 = 0;
}
if (R[p].zb1)
{
fb(R[p].zb1, R[p].zb1 * (t - m), s, m, p << 1);
fb(R[p].zb1, 0, m + 1, t, p << 1 | 1);
R[p].zb1 = 0;
}
if (R[p].zb2)
{
fb(0, R[p].zb2, s, m, p << 1);
fb(0, R[p].zb2, m + 1, t, p << 1 | 1);
R[p].zb2 = 0;
}
}
void M(int r, int x, int y, int o, int s, int t, int p)
{
if (t <= r)
{
if (o)
fa(x, y, s, t, p);
else
fb(x, y, s, t, p);
return;
}
d(s, t, p);
int m = s + t >> 1;
if (r > m)
{
M(r, x, x * (r - m) + y, o, s, m, p << 1);
M(r, x, y, o, m + 1, t, p << 1 | 1);
}
else
M(r, x, y, o, s, m, p << 1);
u(s, t, p);
}
inline void Ia(int x)
{
auto i = C.insert(x).first;
++_c[x];
int l = *prev(i), r = *next(i);
M(r - l, -1, 0, 1, 1, N, 1);
M(x - l, 1, 0, 1, 1, N, 1);
M(r - x, 1, 0, 1, 1, N, 1);
}
inline void Da(int x)
{
auto i = C.find(x);
int l = *prev(i), r = *next(i);
M(x - l, -1, 0, 1, 1, N, 1);
M(r - x, -1, 0, 1, 1, N, 1);
M(r - l, 1, 0, 1, 1, N, 1);
C.erase(x), --_c[x];
}
inline void Ib(int x)
{
auto i = D.insert(x).first;
++_d[x];
int l = *prev(i), r = *next(i);
M(r - l, -1, 0, 0, 1, N, 1);
M(x - l, 1, 0, 0, 1, N, 1);
M(r - x, 1, 0, 0, 1, N, 1);
}
inline void Db(int x)
{
auto i = D.find(x);
int l = *prev(i), r = *next(i);
M(x - l, -1, 0, 0, 1, N, 1);
M(r - x, -1, 0, 0, 1, N, 1);
M(r - l, 1, 0, 0, 1, N, 1);
D.erase(x), --_d[x];
}
signed main()
{
scanf("%d%d%d", &n, &m, &q);
C.insert(0), C.insert(n), D.insert(0), D.insert(m);
for (int i = 1; i <= n; ++i)
scanf("%lld", _a + i);
for (int i = 1; i < n; ++i)
if (_a[i] == _a[i + 1])
C.insert(i), ++_c[i];
for (int i = n; i >= 1; --i)
_a[i] -= _a[i - 1];
for (int i = 1; i <= m; ++i)
scanf("%lld", _b + i);
for (int i = 1; i < m; ++i)
if (_b[i] == _b[i + 1])
D.insert(i), ++_d[i];
for (int i = m; i >= 1; --i)
_b[i] -= _b[i - 1];
N = max(n, m);
for (auto i = C.begin(); i != --C.end(); ++i)
M(*next(i) - *i, 1, 0, 1, 1, N, 1);
for (auto i = D.begin(); i != --D.end(); ++i)
M(*next(i) - *i, 1, 0, 0, 1, N, 1);
printf("%lld\n", R[1].q);
for (int i = 0, o, x, y, k; i < q; ++i)
{
scanf("%d%d%d%d", &o, &x, &y, &k);
if (o & 1)
{
_a[x] += k, _a[y + 1] -= k;
if (x > 1)
{
if (!_c[x - 1] && !_a[x])
Ia(x - 1);
if (_c[x - 1] && _a[x])
Da(x - 1);
}
if (y < n)
{
if (!_c[y] && !_a[y + 1])
Ia(y);
if (_c[y] && _a[y + 1])
Da(y);
}
}
else
{
_b[x] += k, _b[y + 1] -= k;
if (x > 1)
{
if (!_d[x - 1] && !_b[x])
Ib(x - 1);
if (_d[x - 1] && _b[x])
Db(x - 1);
}
if (y < m)
{
if (!_d[y] && !_b[y + 1])
Ib(y);
if (_d[y] && _b[y + 1])
Db(y);
}
}
printf("%lld\n", R[1].q);
}
return 0;
}CF1920F2 *3000
题意:给一张 的地图,有 .,v,# 三种格子,
保证所有 # 形成一个连通块,其余格子也形成一个连通块,
定义一条路径的权值为其上任意一个格子到任意一个 v 格子的距离最小值,
每次询问 ,求经过 的,包围所有 # 的闭合路径的权值最大值。