Incredible Crazily Progressing Company (ICPC) suffered a lot with the low speed of procedure. After investigation, they found that the bottleneck was at Absolutely Crowded Manufactory (ACM). In oder to accelerate the procedure, they bought a new machine for ACM. But a new problem comes, how to place the new machine into ACM?
ACM is a rectangular factor and can be divided into W * H cells. There are N retangular old machines in ACM and the new machine can not occupy any cell where there is old machines. The new machine needs M consecutive cells. Consecutive cells means some adjacent cells in a line. You are asked to calculate the number of ways to choose the place for the new machine.
There are multiple test cases (no more than 50). The first line of each test case contains 4 integers W, H, N, M (1 ≤ W, H ≤ 10
7, 0 ≤ N ≤ 50000, 1 ≤ M ≤ 1000), indicating the width and the length of the room, the number of old machines and the size of the new machine. Then N lines follow, each of which contains 4 integers X
i1, Y
i1, X
i2 and Y
i2 (1 ≤ X
i1 ≤ X
i2 ≤ W, 1 ≤ Y
i1 ≤ Y
i2 ≤ H), indicating the coordinates of the i-th old machine. It is guarantees that no cell is occupied by two old machines.
/*hdu 4052 线段树扫描线、奇特处理给你W*H大小的矩形,其中有N个地区不能使用(给出了这个地区的两个顶点的坐标即(x1,y1)和(x2,y2)),问能下多少个1*M的矩形。但是看见题目有想到了扫描线,但是一直不知道应该怎么处理后来偶然看见别人提示可以转换成求面积,大致就有了思路假设1*n的矩阵中放入1*m的矩阵,能有多少种? n-m+1我们扫描每一列,两个相邻为n的旧机器中就能放下n-m+1个新机器,于是原先的旧机器矩形就变成了(x1,y1,x2+ma-1,y2)(从下往上扫描) (x1,y1,x2,y2+ma-1)(从左往右扫描)而剩下的为被占据的位置就是方案数了因为我是在每个旧机器往右边添加的,所以还要解决这一列没有从1开始的情况,所以在最左边加上(1,1,ma,h+1)的矩阵而且ma=1时,横着放和竖着放是一样的,所以除以2但是第一个版本写出来一直 RuntimeError后来实在没法又换了个,把离散化用vec处理终于出现了WR(TAT)主要是 ma == 1 情况,因为我会在1添加一个矩阵,但是当ma==1时这个矩阵也被建立了就导致(1,1,1,h+1) 由于是按边建树l=x1,r=x2-1 -> r #include #include #include #include #include