Practice for KD Tree
时间限制:C/C++/Rust/Pascal 10秒,其他语言20秒
空间限制:C/C++/Rust/Pascal 256 M,其他语言512 M
64bit IO Format: %lld

题目描述

It's time to have a break and implement something.
You are given an matrix . All the elements are zero initially.
First, you need to perform m_1 range addition operations. For each operations, you are given .You need to add w to all the elements where and .
Then you need to perform m_2 range maximum queries. For each operations, you are given . You need to answer the maximum element among the elements that satisify and .

输入描述:

The first line contains three integers

Each of the following m_1 lines contains five integers
.Each of the following m_2 lines contains four integers
.

输出描述:

Output m_2 lines, each of which contains one integer.
示例1

输入

复制
5 5 5
1 1 4 5 4
4 1 4 1 10
1 3 3 3 3
1 1 5 5 8
2 4 4 5 8
2 1 2 1
4 1 5 4
1 2 3 5
2 1 5 3
1 3 5 5

输出

复制
12
22
20
22
20