PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#SRD0000049. Chtholly trở về nhà (Welcome home, Chtholly)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Chtholly trở về nhà (Welcome home, Chtholly)

Welcome home, Chtholly

Source: Codeforces

Version: Phuoc Hung OJ Extended

Problem Statement

There are nn cakes in a row, where cake ii needs aia_i seconds. Process mm operations:

  • 1 l r x: for each ii in the inclusive interval, replace aia_i with ai−xa_i-x only if ai>xa_i>x; leave smaller or equal values unchanged.
  • 2 l r x: count positions in the interval whose current value equals xx.

Indices start at 11, and all updates affect subsequent operations.

Input

The first line is n,mn,m; the second lists a1,…,ana_1,\ldots,a_n. Every following operation consists of exactly four integers t l r x, where t∈{1,2}t\in\{1,2\}.

Output

Print one count for each type-2 operation.

Subtasks

  • Subtask 1 (10 points): 1≤n≤601\le n\le60; 1≤m≤701\le m\le70. Every value and parameter xx lies in [1,105][1,10^5].
  • Subtask 2 (20 points): 1≤n≤20001\le n\le2000; 1≤m≤30001\le m\le3000. Every value and parameter xx lies in [1,105][1,10^5].
  • Subtask 3 (30 points): 1≤n≤250001\le n\le25000; 1≤m≤250001\le m\le25000. Every value and parameter xx lies in [1,105][1,10^5].
  • Subtask 4 (40 points): 1≤n≤1000001\le n\le100000; 1≤m≤1000001\le m\le100000. Every value and parameter xx lies in [1,105][1,10^5].

Examples

Input

5 6
1 5 5 5 8
2 2 5 5
1 2 4 3
2 2 5 2
2 2 5 5
1 3 5 1
2 1 5 1

Output

3
3
0
3

Explanation

Initially, interval [2,5][2,5] contains three fives. After 1 2 4 3, those fives become twos, so the next counts of 22 and 55 are 33 and 00. The subsequent update reduces the three twos to ones, making the final answer 33.