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

#SRD0000019. Tần suất giá trị trong đoạn có cập nhật (Point Set Range Frequency)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Tần suất giá trị trong đoạn có cập nhật (Point Set Range Frequency)

Point Set Range Frequency

Source: Library Checker

Version: Phuoc Hung OJ Extended

Problem Statement

You are given a nonnegative integer array aa of length NN, indexed from 00. Process QQ operations in order:

  • 0 k v: assign ak=va_k=v.
  • 1 l r x: count occurrences of xx in the half-open interval [l,r)[l,r), i.e. at indices ll through r−1r-1.

An empty interval l=rl=r has answer 00. The array itself may be empty when N=0N=0; in that case updates are not permitted.

Input

The first line contains N,QN,Q. The next line holds the NN initial values (empty if N=0N=0). Each of the following QQ lines is either 0 k v or 1 l r x.

Output

For every operation of type 1, print the number of occurrences of xx in the queried interval.

Subtasks

  • Subtask 1 (10 points): 0≤N≤500\le N\le 50; 0≤Q≤800\le Q\le 80; 0≤ai,v,x≤1090\le a_i,v,x\le10^9; updates require 0≤k<N0\le k<N; queries require 0≤l≤r≤N0\le l\le r\le N. Both N=0N=0 and Q=0Q=0 are allowed.
  • Subtask 2 (20 points): 0≤N≤20000\le N\le 2000; 0≤Q≤25000\le Q\le 2500; 0≤ai,v,x≤1090\le a_i,v,x\le10^9; updates require 0≤k<N0\le k<N; queries require 0≤l≤r≤N0\le l\le r\le N. Both N=0N=0 and Q=0Q=0 are allowed.
  • Subtask 3 (30 points): 0≤N≤300000\le N\le 30000; 0≤Q≤300000\le Q\le 30000; 0≤ai,v,x≤1090\le a_i,v,x\le10^9; updates require 0≤k<N0\le k<N; queries require 0≤l≤r≤N0\le l\le r\le N. Both N=0N=0 and Q=0Q=0 are allowed.
  • Subtask 4 (40 points): 0≤N≤2000000\le N\le 200000; 0≤Q≤2000000\le Q\le 200000; 0≤ai,v,x≤1090\le a_i,v,x\le10^9; updates require 0≤k<N0\le k<N; queries require 0≤l≤r≤N0\le l\le r\le N. Both N=0N=0 and Q=0Q=0 are allowed.

Examples

Input

5 6
3 7 1 2 1
1 1 5 1
1 3 3 0
1 0 4 3
0 1 1
1 0 5 1
1 0 5 123456789

Output

2
0
1
3
0

Explanation

The first query examines [7,1,2,1][7,1,2,1] and finds two occurrences of 11. The interval [3,3)[3,3) is empty. After 0 1 1, the array becomes [3,1,1,2,1][3,1,1,2,1], which contains three ones.