差分算法
一维:【2,5】 在2上面打 +1 标记, 6 上面打 -1 标记
0 +1 0 0 0 -1
二维:[(2,2),(5,5)]
0 0 0 0 0 0
0 +1 0 0 0 -1
0 +1 0 0 0 -1
0 +1 0 0 0 -1
0 +1 0 0 0 -1
0 0 0 0 0 0
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <queue>
#include <string>
#include <vector>
#include <set>
#define ll long long
using namespace std;
int n,m,a[1005][1005];
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n >> m;
int x1,y1,x2,y2;
while(m--)
{
cin >> x1 >> y1 >> x2 >> y2;
for(int i=x1;i<=x2;i++)
{
a[i][y1]++;
a[i][y2+1]--;
}
}
for(int i=1;i<=n;i++)
{
for(int j=1;j<=n;j++)
{
a[i][j]+=a[i][j-1];
printf("%d ",a[i][j]);
}
printf("\n");
}
return 0;
}