二位差分0分求助

P3397 地毯

__Shine__ @ 2022-10-07 15:03:58

暴力已AC,但老师非让用二位差分

#include<bits/stdc++.h>
#define int   long long
#define rg    register int
#define float double
using namespace std;
int n,m,d[1010][1010];
signed main()
{
    cin>>n>>m;
    while(m--)
    {
        int X1,X2,Y1,Y2;
        cin>>X1>>X2>>Y1>>Y2;
        d[X1][Y1]++;
        d[X2+1][Y1]--;
        d[X1][Y2+1]--;
        d[X2+1][Y2+1]++; 
    }
    d[0][0]=0;
    for(int i=1;i<=n;i++)
        for(int j=1;j<=n;j++)
            d[i][j]+=(d[i-1][j]+d[i][j-1]-d[i-1][j-1]);
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=n;j++)
            cout<<d[i][j]<<" ";
        cout<<endl; 
    }

    return 0;
}

by __Shine__ @ 2022-10-07 15:05:06

二维


by bamboo12345 @ 2022-10-07 15:18:57

@wazzx 输入的问题……


by __Shine__ @ 2022-10-07 15:21:03

@bamboo123 那您能说下怎么改吗


by bamboo12345 @ 2022-10-07 15:22:51

@wazzx 看输入格式


by __Shine__ @ 2022-10-07 15:23:51

@bamboo123 thx,wssb


|