mirror of
https://git.sb/baoshuo/OI-codes.git
synced 2025-02-20 00:46:38 +00:00
Compare commits
No commits in common. "51efd8f0d0f4858f4e7a2731398492ddc6d48fd4" and "f51cbe62a992273eae2a0138225d64835d0b4d5d" have entirely different histories.
51efd8f0d0
...
f51cbe62a9
@ -1,151 +0,0 @@
|
|||||||
#include <iostream>
|
|
||||||
#include <cmath>
|
|
||||||
|
|
||||||
using std::cin;
|
|
||||||
using std::cout;
|
|
||||||
const char endl = '\n';
|
|
||||||
|
|
||||||
struct node {
|
|
||||||
int l, r;
|
|
||||||
int color, new_color;
|
|
||||||
long long sum, sum_delta;
|
|
||||||
node *lchild, *rchild;
|
|
||||||
|
|
||||||
node()
|
|
||||||
: l(0), r(0), color(-1), new_color(-1), sum(0), sum_delta(0), lchild(nullptr), rchild(nullptr) {}
|
|
||||||
|
|
||||||
node(int _l, int _r)
|
|
||||||
: l(_l), r(_r), color(-1), new_color(-1), sum(0), sum_delta(0), lchild(nullptr), rchild(nullptr) {}
|
|
||||||
|
|
||||||
~node() {
|
|
||||||
delete lchild;
|
|
||||||
delete rchild;
|
|
||||||
}
|
|
||||||
|
|
||||||
void pushup() {
|
|
||||||
sum = 0;
|
|
||||||
color = -1;
|
|
||||||
|
|
||||||
if (lchild != nullptr) {
|
|
||||||
sum += lchild->sum;
|
|
||||||
color = lchild->color;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (rchild != nullptr) {
|
|
||||||
sum += rchild->sum;
|
|
||||||
color = color == rchild->color ? color : -1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void pushdown() {
|
|
||||||
if (new_color == -1 || sum_delta == 0) return;
|
|
||||||
|
|
||||||
if (lchild != nullptr) {
|
|
||||||
if (sum_delta) {
|
|
||||||
lchild->sum_delta += sum_delta;
|
|
||||||
lchild->sum += sum_delta * (lchild->r - lchild->l + 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (new_color != -1) {
|
|
||||||
lchild->color = lchild->new_color = new_color;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (rchild != nullptr) {
|
|
||||||
if (sum_delta) {
|
|
||||||
rchild->sum_delta += sum_delta;
|
|
||||||
rchild->sum += sum_delta * (rchild->r - rchild->l + 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (new_color != -1) {
|
|
||||||
rchild->color = rchild->new_color = new_color;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
new_color = -1;
|
|
||||||
sum_delta = 0;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
void build(node *&u, int l, int r) {
|
|
||||||
u = new node(l, r);
|
|
||||||
|
|
||||||
if (l == r) {
|
|
||||||
u->color = l;
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
int mid = (l + r) >> 1;
|
|
||||||
|
|
||||||
if (l <= mid) build(u->lchild, l, mid);
|
|
||||||
if (r > mid) build(u->rchild, mid + 1, r);
|
|
||||||
|
|
||||||
u->pushup();
|
|
||||||
}
|
|
||||||
|
|
||||||
void modify(node *u, int l, int r, int new_color) {
|
|
||||||
if (l <= u->l && u->r <= r && ~u->color) {
|
|
||||||
u->sum += static_cast<long long>(std::abs(u->color - new_color)) * (u->r - u->l + 1);
|
|
||||||
u->sum_delta += std::abs(u->color - new_color);
|
|
||||||
u->color = u->new_color = new_color;
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
int mid = (u->l + u->r) >> 1;
|
|
||||||
u->pushdown();
|
|
||||||
|
|
||||||
if (l <= mid) modify(u->lchild, l, r, new_color);
|
|
||||||
if (r > mid) modify(u->rchild, l, r, new_color);
|
|
||||||
|
|
||||||
u->pushup();
|
|
||||||
}
|
|
||||||
|
|
||||||
long long query(node *u, int l, int r) {
|
|
||||||
if (l <= u->l && u->r <= r) {
|
|
||||||
return u->sum;
|
|
||||||
}
|
|
||||||
|
|
||||||
int mid = (u->l + u->r) >> 1;
|
|
||||||
long long res = 0;
|
|
||||||
|
|
||||||
u->pushdown();
|
|
||||||
|
|
||||||
if (l <= mid) res += query(u->lchild, l, r);
|
|
||||||
if (r > mid) res += query(u->rchild, l, r);
|
|
||||||
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
int main() {
|
|
||||||
std::ios::sync_with_stdio(false);
|
|
||||||
cin.tie(nullptr);
|
|
||||||
|
|
||||||
int n, m;
|
|
||||||
node *root;
|
|
||||||
|
|
||||||
cin >> n >> m;
|
|
||||||
|
|
||||||
build(root, 1, n);
|
|
||||||
|
|
||||||
while (m--) {
|
|
||||||
int op, l, r;
|
|
||||||
|
|
||||||
cin >> op >> l >> r;
|
|
||||||
|
|
||||||
if (op == 1) {
|
|
||||||
int x;
|
|
||||||
|
|
||||||
cin >> x;
|
|
||||||
|
|
||||||
modify(root, l, r, x);
|
|
||||||
} else {
|
|
||||||
cout << query(root, l, r) << endl;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
delete root;
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
@ -8,36 +8,7 @@ const char endl = '\n';
|
|||||||
const int N = 205;
|
const int N = 205;
|
||||||
|
|
||||||
int n, m;
|
int n, m;
|
||||||
long long g[N][N], s[N][N], c[N], ans;
|
long long g[N][N], ans;
|
||||||
|
|
||||||
bool check(int x) {
|
|
||||||
long long t = 0;
|
|
||||||
|
|
||||||
for (int i = x; i <= m; i++) {
|
|
||||||
t = std::min(t, c[i - x]);
|
|
||||||
|
|
||||||
if (c[i] > t) return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
int calc() {
|
|
||||||
int l = 1, r = n, res = 0;
|
|
||||||
|
|
||||||
while (l <= r) {
|
|
||||||
int mid = (l + r) >> 1;
|
|
||||||
|
|
||||||
if (check(mid)) {
|
|
||||||
res = mid;
|
|
||||||
l = mid + 1;
|
|
||||||
} else {
|
|
||||||
r = mid - 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
std::ios::sync_with_stdio(false);
|
std::ios::sync_with_stdio(false);
|
||||||
@ -49,17 +20,19 @@ int main() {
|
|||||||
for (int j = 1; j <= m; j++) {
|
for (int j = 1; j <= m; j++) {
|
||||||
cin >> g[i][j];
|
cin >> g[i][j];
|
||||||
|
|
||||||
s[i][j] = s[i - 1][j] + g[i][j];
|
g[i][j] += g[i - 1][j] + g[i][j - 1] - g[i - 1][j - 1];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 1; i <= n; i++) {
|
for (int i = 1; i <= n; i++) {
|
||||||
for (int j = i; j <= n; j++) {
|
for (int j = 1; j <= m; j++) {
|
||||||
for (int k = 1; k <= m; k++) {
|
for (int k = i; k <= n; k++) {
|
||||||
c[k] = c[k - 1] + s[j][k] - s[i - 1][k];
|
for (int l = j; l <= m; l++) {
|
||||||
|
if (g[k][l] - g[k][j - 1] - g[i - 1][l] + g[i - 1][j - 1] >= 0) {
|
||||||
|
ans = std::max(ans, static_cast<long long>(k - i + 1) * (l - j + 1));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ans = std::max(ans, static_cast<long long>(j - i + 1) * calc());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user