/
実行時間制限: 4 sec / メモリ制限: 1024 MiB
Score: 100 points
Problem Statement
The country of JOI is an equilateral triangle with side length L whose vertices are points A, B, and C. Here, L is a positive integer. Side AB connects vertices A and B in the east-west direction, and vertex A is the westernmost point of the country of JOI, while vertex B is the easternmost point. Vertex C is the northernmost point of the country of JOI.
The country of JOI is divided into L^2 regions, each of which is an equilateral triangle with side length 1. A point that is a vertex of some region is called a lattice point. For integers x, y satisfying 0\leq y\leq L and 0\leq x\leq L-y, the lattice point that is the (1+y)-st from the south and the (1+x)-st from the west is denoted by (x,y). In particular, A, B, and C are denoted by (0,0), (L,0), and (0,L), respectively. For example, the following figure shows the regions and the lattice points when L=5.

In the country of JOI, weather forecasts for the next N days have been announced. On day i, rain is forecast to fall in the triangular region T_i whose vertices are lattice points (X_i, Y_i), (X_i + Z_i, Y_i), and (X_i, Y_i + Z_i). An region is said to be forecast to receive rain on day i if the entire region is contained in T_i.
In order to prepare for disasters caused by rainfall, it is necessary to determine, for each k=1,2,\ldots,K, the number of regions that are forecast to receive rain on at least k days.
Given the size of the country of JOI, the weather forecasts, and K, write a program which, for each k=1,2,\ldots,K, computes the number of regions that are forecast to receive rain on at least k days.
Input
Input is given from Standard Input in the following format:
L N K X_1 Y_1 Z_1 X_2 Y_2 Z_2 \vdots X_N Y_N Z_N
Output
Print K lines to Standard Output. The k-th line (1\leq k\leq K) should contain the number of regions that are forecast to receive rain on at least k days.
Constraints
- 2\leq L\leq 10^9.
- 2 \leq N \leq 200\,000.
- 1 \leq K \leq 5.
- 0\leq X_i\leq L (1\leq i\leq N).
- 0\leq Y_i\leq L (1\leq i\leq N).
- 1 \leq Z_i\leq L (1\leq i\leq N).
- X_i+Y_i+Z_i\leq L (1\leq i\leq N).
- All input values are integers.
Subtasks
- (4 points) N = 2, K = 2.
- (5 points) L\leq 100, N\leq 100.
- (5 points) L\leq 1\,000.
- (7 points) N\leq 2\,000.
- (10 points) X_i = 0 (1\leq i\leq N), K = 1.
- (10 points) X_i = 0 (1\leq i\leq N).
- (23 points) K = 1.
- (18 points) K \leq 2.
- (18 points) There are no additional constraints.
Sample Input 1
5 2 2 1 0 3 0 1 4
Sample Output 1
21 4
If we illustrate, for each region, the number of days on which rain is forecast to fall, we obtain the following figure.

This sample input satisfies the constraints for Subtasks 1, 2, 3, 4, 8, and 9.
Sample Input 2
5 4 5 1 0 4 0 1 3 2 0 2 1 2 2
Sample Output 2
21 10 2 0 0
If we illustrate, for each region, the number of days on which rain is forecast to fall, we obtain the following figure.

This sample input satisfies the constraints for Subtasks 2, 3, 4, and 9.
配点: 100 点
問題文
JOI 国は,点 A, B, C を頂点とする一辺の長さが L の正三角形である.ここで L は正整数である.辺 AB は頂点 A, B を東西方向に結んでおり,頂点 A は JOI 国の最西端,頂点 B は JOI 国の最東端である.頂点 C は JOI 国の最北端である.
JOI 国は,一辺の長さが 1 の正三角形の区画 L^2 個に区切られている.ある区画の頂点であるような点は格子点と呼ばれている.0\leqq y\leqq L,0\leqq x\leqq L-y を満たす整数 x,y に対して,南側から 1+y 番目,西側から 1+x 番目の格子点は (x,y) と表される.特に A は (0,0),B は (L,0),C は (0,L) と表される.例えば次の図は L=5 の場合の区画,格子点を表している.

JOI 国ではこれから N 日の間の天気予報が発表された. i 日目には,格子点 (X_i, Y_i), (X_i + Z_i, Y_i), (X_i, Y_i + Z_i) を頂点とする正三角形状の地域 T_i に雨が降ると予報されている. i 日目に雨が降ると予報されている区画とは,区画全体が T_i に含まれるような区画のことである.
降雨による災害に備えるため,k=1,2,\ldots,K について,k 日以上雨が降ると予報されている区画の個数を調べる必要がある.
JOI 国の大きさ,天気予報の情報,K が与えられたときに,k=1,2,\ldots,K について,k 日以上雨が降ると予報されている区画の個数を求めるプログラムを作成せよ.
入力
入力は以下の形式で標準入力から与えられる.
L N K X_1 Y_1 Z_1 X_2 Y_2 Z_2 \vdots X_N Y_N Z_N
出力
標準出力に K 行出力せよ.k 行目 (1\leqq k\leqq K) には,k 日以上雨が降ると予報されている区画の個数を出力せよ.
制約
- 2\leqq L\leqq 10^9.
- 2 \leqq N \leqq 200\,000.
- 1 \leqq K \leqq 5.
- 0\leqq X_i\leqq L (1\leqq i\leqq N).
- 0\leqq Y_i\leqq L (1\leqq i\leqq N).
- 1 \leqq Z_i\leqq L (1\leqq i\leqq N).
- X_i+Y_i+Z_i\leqq L (1\leqq i\leqq N).
- 入力される値はすべて整数である.
小課題
- (4 点) N = 2,K = 2.
- (5 点) L\leqq 100,N\leqq 100.
- (5 点) L\leqq 1\,000.
- (7 点) N\leqq 2\,000.
- (10 点) X_i = 0 (1\leqq i\leqq N),K = 1.
- (10 点) X_i = 0 (1\leqq i\leqq N).
- (23 点) K = 1.
- (18 点) K \leqq 2.
- (18 点) 追加の制約はない.
入力例 1
5 2 2 1 0 3 0 1 4
出力例 1
21 4
それぞれの区画について,雨が降ると予報されている日数を図示すると,次の図のようになる.

この入力例は小課題 1, 2, 3, 4, 8, 9 の制約を満たす.
入力例 2
5 4 5 1 0 4 0 1 3 2 0 2 1 2 2
出力例 2
21 10 2 0 0
それぞれの区画について,雨が降ると予報されている日数を図示すると,次の図のようになる.

この入力例は小課題 2, 3, 4, 9 の制約を満たす.