Under construction

Still being built. Things may change

Pigtail Virus

Time limit2sMemory limit1024 MB

Summary
Given a perfect binary tree of N cities and Q viruses that each add power p to cities within distance d of a source, print every city's total infection level.
Level

Medium6 of 10

Topics
Tree, Prefix sum, Implementation
Solved
No attempts yet

Problem

Nana, a stage girl who travels often, discovers the land of Galrae one day. Galrae has NN cities, and a two-way road connects the ii-th city (2≤i≤N2 \leq i \leq N) with the ⌊i2⌋\left \lfloor \frac{i}{2} \right \rfloor-th city. There is a positive integer kk that satisfies N=2k−1N = 2^k - 1. In other words, the roads of Galrae form a perfect binary tree.

No one in Galrae wears pigtails. Shocked by this, Nana sets aside her stage duties and builds QQ kinds of pigtail viruses.

Each virus has a power pp and an infectivity dd. A virus released in city vv infects every city within distance dd of vv, and each of those cities gains pp. The distance between cities aa and bb is the minimum number of roads on a path from aa to bb.

The infection level of a city is the sum of the powers of all viruses that infect it after Nana releases every virus. A city can be infected by two or more kinds of viruses.

Print the infection level of each city after all viruses are released.

Input

The first line contains NN (1≤N<262 144=2181 \leq N < 262\,144 = 2^{18}) and QQ (1≤Q≤200 0001 \leq Q \leq 200\,000), separated by a space.

Each of the next QQ lines contains vv, pp, and dd: a virus with power pp (1≤p≤1 0001 \leq p \leq 1\,000) and infectivity dd (0≤d≤(log⁡2(N+1)−1)×20 \leq d \leq (\log_2 (N + 1) - 1) \times 2) is released in city vv (1≤v≤N1 \leq v \leq N).

Output

Print NN integers, the infection level of each city in order, separated by spaces.

Examples1

  1. Example 1

    Input
    7 2
    2 3 2
    6 2 2
    
    Expected output
    5 3 5 3 3 2 2