二维差分裸题,放假之前做的,想着之前没做过二维的所以记录一下。
好文:差分——(2)二维差分_努力中的老周的专栏-CSDN博客
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <cmath>
#include <string>
#include <vector>
#include <stack>
#include <map>
#include <sstream>
#include <cstring>
#include <set>
#include <cctype>
#include <list>
#include <bitset>
#define IO \
ios::sync_with_stdio(false); \
// cin.tie(0); \
// cout.tie(0);
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
const int maxn = 1e3 + 100;
const int maxm = 1e6 + 10;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const int inf = 0x3f3f3f3f;
const LL mod = 998244353;
// int dis[8][2] = {0, 1, 1, 0, 0, -1, -1, 0, 1, -1, 1, 1, -1, 1, -1, -1};
int a[maxn];
int sum[maxn];
int c[maxn][maxn];
int main()
{
#ifdef ONLINE_JUDGE
#else
freopen("in.txt", "r", stdin);
// freopen("out.txt", "w", stdout);
#endif
IO;
int n, m;
int t;
int x1, x2, y1, y2;
cin >> n >> m >> t;
for (int i = 0; i < t; i++)
{
cin >> x1 >> y1 >> x2 >> y2;
c[x1][y1] += 1;
c[x1][y2 + 1] -= 1;
c[x2 + 1][y1] -= 1;
c[x2 + 1][y2 + 1] += 1;
}
int ans = 0;
int temp = 0;
for (int i = 1; i <= n; i++)
{
for (int j = 1; j <= m; j++)
{
c[i][j] += c[i - 1][j] + c[i][j - 1] - c[i - 1][j - 1];
ans = max(ans, c[i][j]);
}
}
cout << ans;
return 0;
}