Problem Description
n shops numbered with successive integers from
1 to
n in Byteland. Every shop sells only one kind of goods, and the price of the
i-th shop's goods is
vi. The distance between the
i-th shop and Byteasar's home is
di.
Every day, Byteasar will purchase some goods. On the
i-th day, he will choose an interval
[li,ri] and an upper limit
ci. Then, he will visit each shop with distance at most
ci away from home in
[li,ri], buy at most one piece of goods from each shop and go back home. Of course, he can also choose to buy nothing. Back home, Byteasar will calculate the total amount of money he has costed that day and write it down on his account book, denoted as
sumi.
However, due to Byteasar's poor math, he may calculate it wrong.
Please write a program to help Byteasar judge whether each number is sure to be calculated wrong.
Input
T
(1≤T≤10), denoting the number of test cases.
In each test case, the first line of the input contains two integers
n,m
(1≤n≤20000,1≤m≤100000), denoting the number of shops and the number of records on Byteasar's account book.
The second line of the input contains
n integers
v1,v2,...,vn
(1≤vi≤100), denoting the price of the
i-th shop's goods.
The third line of the input contains
n integers
d1,d2,...,dn
(1≤di≤109), denoting the distance between the
i-th shop and Byteasar's home.
Each of the next
m lines contains four integers
li,ri,ci,sumi
(1≤li≤ri≤n,1≤ci≤109,1≤sumi≤100), denoting a record on Byteasar's account book.
Output
m characters. If the i-th number is sure to be calculated wrong, then the i-th character should be '1'. Otherwise, it should be '0'.
Sample Input
2 3 3 3 3 3 2 4 3 3 3 5 3 3 3 3 1 2 3 1 3 5 4 5 1 2 4 2 1 8 9 2 1 1 5 1 3 4 4 1 5 1 5 3 5 1 3 5 1
Sample Output
1101
标算的做法,分治,复杂度100(nlogn+m)+mlogn
树状数组+多重背包二进制优化,按道理来说复杂度要炸,然而实际上跑的比分治还快。