#P2464. [SDOI2008] 郁闷的小 J

    ID: 1470 远端评测题 1000ms 125MiB 尝试: 0 已通过: 0 难度: 7 上传者: 标签>莫队各省省选块状链表,块状数组,分块

[SDOI2008] 郁闷的小 J

Description

Little J is a librarian at the National Library, and his job is to manage a huge bookshelf. Although he is diligent, the bookshelf is so large that his efficiency is always low, putting him at risk of being fired, which makes him depressed.

Specifically, the bookshelf consists of NN positions, numbered from 11 to NN. Each position holds one book, and each book has a specific code.

Little J’s job has two types:

  1. The library frequently purchases new books, and the shelf is always full at any time, so a book at some position has to be removed and replaced with the newly purchased one.

  2. Little J needs to answer customer queries. A customer will ask how many books with a given code appear in a certain contiguous segment of positions.

For example, there are 55 positions, and initially the codes of the books on the positions are 1,2,3,4,51, 2, 3, 4, 5.

A customer asks how many books with code "2" are in positions 11 to 33. The answer is 11.

A customer asks how many books with code "1" are in positions 11 to 33. The answer is 11.

At this point, the library purchases a book with code "1" and puts it at position 22.

A customer asks how many books with code "2" are in positions 11 to 33. The answer is 00.

A customer asks how many books with code "1" are in positions 11 to 33. The answer is 22.

...

Your task is to write a program to answer each customer’s query.

Input Format

The first line contains two integers N,MN, M, meaning there are NN positions and MM operations.

The next line contains NN integers A1,A2,,ANA_1, A_2, \ldots , A_N, where AiA_i is the code of the book initially at position ii.

The next MM lines each represent an operation, and each line begins with a character.

If the character is C, it means the library purchases a new book, followed by two integers A,PA, P (1AN1 \le A \le N), meaning the book is placed at position AA, and its code is PP.

If the character is Q, it represents a customer query, followed by three integers A,B,KA, B, K (1ABN1 \le A \le B \le N), meaning to query how many books with code KK appear from position AA to position BB (inclusive).

Output Format

For each customer query, output one integer representing the result of the query.

5 5
1 2 3 4 5
Q 1 3 2
Q 1 3 1
C 2 1
Q 1 3 2
Q 1 3 1

1
1
0
2

Hint

For 40%40\% of the testdata, 1N,M50001 \le N, M \le 5000.

For 100%100\% of the testdata, 1N,M1051 \le N, M \le {10}^5.

For 100%100\% of the testdata, all book codes that appear are positive integers not greater than 23112^{31} - 1.

Translated by ChatGPT 5