二维差分的简单应用。作为学二维差分时的练手题很不错。
主要代码:
#include<bits/stdc++.h> using namespace std; const int N=1002; int a[N][N]; int main(){ ios::sync_with_stdio(false); int n,m; cin>>n>>m; for (int i=1;i<=m;i++){ int left1,left2,right1,right2; cin>>left1>>right1>>left2>>right2; a[left1][right1]++; a[left1][right2+1]--; a[left2+1][right2+1]++; a[left2+1][right1]--; } for (int i=1;i<=n;i++) for (int j=1;j<=n;j++) a[i][j]+=a[i][j-1]+a[i-1][j]-a[i-1][j-1]; for (int i=1;i<=n;i++){ for (int j=1;j<=n;j++) if (j==1) cout<<a[i][j]; else cout<<" "<<a[i][j]; cout<<"\n"; } return 0; }
标签:right2,left1,left2,int,P3397,地毯,right1 From: https://www.cnblogs.com/purple123/p/18009972