Under construction

Still being built. Things may change

Rides 1

Time limit2sMemory limit256 MB

Summary
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 NN children numbered from 1 to NN. The children love going to the amusement park, but height limits often keep them off the rides. There are MM rides numbered from 1 to MM, and every ride holds exactly 2 people. Children ii and jj can ride ride kk together only if (height of child ii) + (height of child jj) ≥\ge (height limit of ride kk).

You are given QQ triples (i,j,k)(i, j, k). Each triple means that children ii and jj try to ride ride kk every day. ii and jj 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 KK, 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 KK, 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 NN, the number of rides MM, the number of days KK, and the number of triples QQ. (1≤N,M,K,Q≤200 0001 \le N, M, K, Q \le 200\,000)

The second line contains the height limits of rides 1 to MM in order. (1≤1 \le height limit ≤200 000\le 200\,000)

The third line contains KK numbers: the child who grows on each day, in order of days. (1≤1 \le child number ≤N\le N)

Each of the next QQ lines contains one triple (i,j,k)(i, j, k). (1≤i,j≤N1 \le i, j \le N, 1≤k≤M1 \le k \le M)

Output

Print KK lines. Line dd is the total number of rides the children take on day dd.

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.

Examples1

  1. Example 1

    Input
    5 3 4 4
    4 3 1
    2 2 5 1
    1 2 2
    1 2 1
    1 5 2
    3 5 3
    
    Expected output
    0
    0
    1
    2