CF1753F.Minecraft Series

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Little Misha goes to the programming club and solves nothing there. It may seem strange, but when you find out that Misha is filming a Minecraft series, everything will fall into place...

Misha is inspired by Manhattan, so he built a city in Minecraft that can be imagined as a table of size n×mn \times m . kk students live in a city, the ii -th student lives in the house, located at the intersection of the xix_i -th row and the yiy_i -th column. Also, each student has a degree of his aggressiveness wiw_i . Since the city turned out to be very large, Misha decided to territorially limit the actions of his series to some square ss , which sides are parallel to the coordinate axes. The length of the side of the square should be an integer from 11 to min(n,m)\min(n, m) cells.

According to the plot, the main hero will come to the city and accidentally fall into the square ss . Possessing a unique degree of aggressiveness 00 , he will be able to show his leadership qualities and assemble a team of calm, moderate and aggressive students.

In order for the assembled team to be versatile and close-knit, degrees of aggressiveness of all students of the team must be pairwise distinct and must form a single segment of consecutive integers. Formally, if there exist students with degrees of aggressiveness l,l+1,,1,1,,r1,rl, l+1, \ldots, -1, 1, \ldots, r-1, r inside the square ss , where l0rl \le 0 \le r , the main hero will be able to form a team of rl+1r-l+1 people (of course, he is included in this team).

Notice, that it is not required to take all students from square ss to the team.

Misha thinks that the team should consist of at least tt people. That is why he is interested, how many squares are there in the table in which the main hero will be able to form a team of at least tt people. Help him to calculate this.

输入格式

The first line contains four integers nn , mm , kk and tt ( 1n,m400001 \le n, m \le 40\,000 , 1nm400001 \le n \cdot m \le 40\,000 , 1k1061 \le k \le 10^6 , 1tk+11 \le t \le k + 1 ) — the number of rows and columns in the table, and the number of students living in the city, respectively.

Each of the following kk lines contains three integers xix_i , yiy_i and wiw_i ( 1xin1 \le x_i \le n , 1yim1 \le y_i \le m , 1wi1091 \le \lvert w_i \rvert \le 10^9 ) — the number of row and column, where the ii -th student is living, and the degree of his aggressiveness.

输出格式

Print one integer — the number of ways to choose the square ss in such way that the main hero will be able to form a team of at least tt people.

输入输出样例

  • 输入#1

    2 2 1 2
    1 1 2

    输出#1

    0
  • 输入#2

    2 2 2 2
    1 1 1
    2 2 2

    输出#2

    2
  • 输入#3

    2 2 4 2
    1 1 1
    1 1 -1
    1 2 1
    2 2 1

    输出#3

    4

说明/提示

  1. In the first example the main hero will not be able to form a team of more than one person in any square ss . Illustration for the first example.
  2. In the second example there are two ways to select square ss . Both of them are illustrated below. In one of them the main hero will be able to form a team of students with degrees of aggressiveness [0,1][0, 1] , and in the another — with degrees of aggressiveness [0,1,2][0, 1, 2] . Notice, that the main hero with degree of aggressiveness 00 will be included to the team regardless of the chosen square. Illustration for the second example.
  3. In the third example there are four ways to select square ss . All of them are illustrated below. The main hero will be able to form a team with degrees of aggressiveness: [1,0,1][-1,0,1] , [0,1][0,1] , [0,1][0,1] , [1,0,1][-1, 0, 1] , respectively. Illustration for the third example.
首页