洛谷 地毯(差分)

上一道“差分”小技巧

原题链接

#include<bits/stdc++.h>
using namespace std;
int n,m,a[1050][1050];
int xone,yone,xtwo,ytwo,i,j;
int main()
{
    cin>>n>>m;
    for(i=1;i<=m;i++)
    {
        cin>>xone>>yone>>xtwo>>ytwo;
        for(j=xone;j<=xtwo;j++)
        {
            a[j][yone]++;
            a[j][ytwo+1]--;
        }
    }
    for(i=1;i<=n;i++)
    {
        for(j=1;j<=n;j++)
        {
            a[i][j]+=a[i][j-1];
            cout<<a[i][j]<<" ";
        }
        cout<<endl;
    }
    return 0;
 } 
原文地址:https://www.cnblogs.com/zhouzhihao/p/10394778.html