题库练习 Minecraft Series
← 上一题 下一题 →

A15531 | Minecraft Series

时间限制1s
内存限制256MB
通过 / 提交0/0

题目描述

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 \times m$ . $k$ students live in a city, the $i$ -th student lives in the house, located at the intersection of the $x_i$ -th row and the $y_i$ -th column. Also, each student has a degree of his aggressiveness $w_i$ . Since the city turned out to be very large, Misha decided to territorially limit the actions of his series to some square $s$ , which sides are parallel to the coordinate axes. The length of the side of the square should be an integer from $1$ to $\min(n, m)$ cells.

According to the plot, the main hero will come to the city and accidentally fall into the square $s$ . Possessing a unique degree of aggressiveness $0$ , 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, \ldots, -1, 1, \ldots, r-1, r$ inside the square $s$ , where $l \le 0 \le r$ , the main hero will be able to form a team of $r-l+1$ people (of course, he is included in this team).

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

Misha thinks that the team should consist of at least $t$ 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 $t$ people. Help him to calculate this.

输入格式

The first line contains four integers $n$ , $m$ , $k$ and $t$ ( $1 \le n, m \le 40\,000$ , $1 \le n \cdot m \le 40\,000$ , $1 \le k \le 10^6$ , $1 \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 $k$ lines contains three integers $x_i$ , $y_i$ and $w_i$ ( $1 \le x_i \le n$ , $1 \le y_i \le m$ , $1 \le \lvert w_i \rvert \le 10^9$ ) — the number of row and column, where the $i$ -th student is living, and the degree of his aggressiveness.

输出格式

Print one integer — the number of ways to choose the square $s$ in such way that the main hero will be able to form a team of at least $t$ 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
C++ 编辑器
输入
输出