Rides 1
Time limit2sMemory limit256 MB
Each day one child grows by 1 cm; after each growth, count how many of Q given pairs (i,j) can ride their specified ride, where the pair's combined height meets the ride's limit.
- Level
Hard8 of 10
- Topics
- Sorting, Binary search, Prefix sum, Implementation
- Solved
- No attempts yet
Problem
There are children numbered from 1 to . The children love going to the amusement park, but height limits often keep them off the rides. There are rides numbered from 1 to , and every ride holds exactly 2 people. Children and can ride ride together only if (height of child ) + (height of child ) (height limit of ride ).
You are given triples . Each triple means that children and try to ride ride every day. and may be equal, and the same formula applies in that case. If the same triple appears several times, each copy counts separately.
At the start every child is 0 cm tall, so nobody can ride anything. The children are growing fast, though.
On each day from day 1 to day , exactly one child grows by 1. Given which child grows on each day, write a program that finds, for each day from day 1 to day , the total number of rides the children take that day. Within a day, the growth happens first and the rides happen after it.
Input
The first line contains the number of children , the number of rides , the number of days , and the number of triples . ()
The second line contains the height limits of rides 1 to in order. ( height limit )
The third line contains numbers: the child who grows on each day, in order of days. ( child number )
Each of the next lines contains one triple . (, )
Output
Print lines. Line is the total number of rides the children take on day .
Note
In the first example, nobody can ride anything on days 1 and 2.
On day 3, children 3 and 5 can ride ride 3.
On day 4, children 3 and 5 can ride ride 3, and children 1 and 2 can ride ride 2.