10分求助,思路二维差分,参考了题解第二篇

P3397 地毯

dami826 @ 2023-02-04 11:34:30

#include<bits/stdc++.h>
using namespace std;
int a[1001][1001];
int main(){
    int m,n;
    scanf("%d %d",&m,&n);
    for(int i=1;i<=m;i++){
        int x1,y1,x2,y2;
        scanf("%d %d %d %d",&x1,&y1,&x2,&y2);
        a[x1][y1]++;
        a[x1][y2+1]--;
        a[x2+1][y1]--;
        a[x2+1][y2+1]++;
    }
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++){
            a[i][j]+=a[i-1][j]+a[i][j-1]-a[i-1][j-1];
            printf("%d%c",a[i][j],j==n?'\n':' ');
        }
    }
    return 0;
}

by dami826 @ 2023-02-04 11:37:01

1 3 6 7 9 WA,4 5 8 10 RE,2 AC


by Loser_Syx @ 2023-02-04 11:37:44

@大米爱干饭 数组小了


by Loser_Syx @ 2023-02-04 11:38:29

@大米爱干饭 不能开刚刚好大小的,这样差分时候会越界


by dami826 @ 2023-02-04 11:44:11

@Saint_ying_xtf 阿这


by dami826 @ 2023-02-04 11:45:39

@Saint_ying_xtf 开了1011的还是WA了两个点


by Loser_Syx @ 2023-02-04 11:48:20

@大米爱干饭 你n和m貌似反了,你不测样例的吗


by dami826 @ 2023-02-04 15:28:53

6


by dami826 @ 2023-02-04 15:30:10

@Saint_ying_xtf 谢谢


|