题意:
题意还是如图所示,非常清晰明了的,确实学到了东西,相比而且为前缀和,这个二位差分更加深得我心,其实也就是把二维转换为一维,只不过它的转换实在是过于巧妙了
代码
#include <bits/stdc++.h>
#include<unordered_map>
#define endl '\n'
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
const int maxn=1005;
int mp[maxn][maxn];
int sum[maxn][maxn];
int main()
{
int n,m,i,q1,q2;
cin>>n>>m;
for(i=0;i<m;i++)
{
int x1,x2,y1,y2;
cin>>x1>>y1>>x2>>y2;
for(int j=x1;j<=x2;j++) mp[j][y1]++;
for(int j=x1;j<=x2;j++) mp[j][y2+1]--;
}
// for(i=1;i<=n;i++)
// {
// for(int j=1;j<=n;j++)
// {
// cout<<mp[i][j]<<" ";
// }
// cout<<endl;
// }
int res=0;
int j;
for(i=1;i<=n+1;i++)
{
for(j=1;j<=n+1;j++)
{
res+=mp[i][j];
sum[i][j]=res;
}
}
for(i=1;i<=n;i++)
{
for(j=1;j<=n;j++)
{
cout<<sum[i][j]<<" ";
}
cout<<endl;
}
return 0;
}