Gardener

Maintain N gardens under plantings, range deletions of plants taller than h, and range count queries, all with time-dependent growth.

Hard9Segment treeBinary searchSortingImplementationNo attempts yetTime limit3sMemory limit128 MB

Problem

Onjo is a gardener who tends NN gardens. No garden holds any plant at the start, and there is no limit on how many plants one garden can hold. Every plant grows by kk per day. If a plant of height hh is planted on day xx, its height on day yy is h+k(yx)h + k(y - x). Onjo performs MM operations on the NN gardens.

There are three kinds of operations.

  • 1 t x h: on day tt, plant one plant of height hh in garden xx.
  • 2 t l r h: on day tt, pull out every plant in gardens ll through rr whose height is greater than hh. A plant whose height equals hh stays.
  • 3 t l r: on day tt, print the number of plants in gardens ll through rr.

Onjo handles the first and the second operation easily, but the third one is hard for him because he is weak at arithmetic. Answer the third operation for him.

Input

The first line contains the number of gardens NN (1N1051 \le N \le 10^5), the number of operations MM (1M1061 \le M \le 10^6), and the daily growth kk of every plant (1k1091 \le k \le 10^9).

Each of the next MM lines describes one operation, given in increasing order of day. ll, rr, and xx are between 11 and NN with lrl \le r, and every other number is an integer between 11 and 10910^9. Onjo refuses to do two operations on the same day, so at most one operation happens per day.

Output

Print the answer to each third operation on its own line, in the order the operations are given. At least one of the MM operations is a third operation.