Bad Doctor

Time limit3sMemory limit512 MB

Summary
Each doctor prescribes a set of medicines over a day interval; ignoring one doctor, compute the total cost of distinct medicines needed per day summed over all days.
Level

Hard8 of 10

Topics
Segment tree, Sorting, Prefix sum, Implementation
Solved
No attempts yet

Problem

Alex got sick. He went to a clinic and visited nn doctors. The ii-th doctor said that starting with day lil_i and ending with day rir_i, Alex must take kik_i medicines: a1,a2,…,akia_1, a_2, \ldots, a_{k_i}, one pill a day of each. Medicines are numbered from 1 to mm.

Of course, if several doctors tell Alex to take the same medicine on the same day, he takes only one pill of that medicine that day. At least, that is how people act in real life.

One pill of medicine jj costs cjc_j roubles. But Alex has a doubt: rumors say that one of the doctors in the clinic is really bad. He does not know which doctor is bad, but he decided to ignore this doctor's prescription.

Your task is to find nn numbers tit_i: how much money Alex will spend on pills if the ii-th doctor is bad.

Input

The first line contains two integers nn and mm: the number of doctors and the number of medicines (1≤n≤500 0001 \le n \le 500\,000, 1≤m≤500 0001 \le m \le 500\,000).

The second line contains mm integers cjc_j: the cost of one pill of the jj-th medicine (1≤cj≤1 000 0001 \le c_j \le 1\,000\,000).

Each of the next nn lines describes a doctor. The ii-th of them starts with three integers li,ri,kil_i, r_i, k_i: the start and end days of the ii-th doctor's prescription and the number of medicines he told Alex to take (1≤li≤ri≤1 000 0001 \le l_i \le r_i \le 1\,000\,000, 1≤ki≤m1 \le k_i \le m). Then follow kik_i distinct integers a1,a2,…,akia_1, a_2, \ldots, a_{k_i}, each from 1 to mm: the medicines in the prescription.

The sum of all kik_i in the input does not exceed 1 000 0001\,000\,000.

Output

Output nn integers t1,t2,…,tnt_1, t_2, \ldots, t_n: how much money Alex will spend on pills if he ignores the ii-th doctor's prescription.

Examples1

  1. Example 1

    Input
    5 4
    1000 100 10 1
    3 4 2 2 3
    4 8 3 1 2 4
    6 7 2 3 4
    8 9 2 1 4
    2 6 3 1 2 3
    
    Expected output
    8766 7564 8756 7765 6646