#P10633. BZOJ2989 数列/BZOJ4170 极光

BZOJ2989 数列/BZOJ4170 极光

Problem Description

Given a sequence of positive integers aia_i of length nn, the graze\text{graze} value between two positions is the sum of their position difference and value difference: graze(x,y)=xy+axay\text{graze}(x,y)=|x-y|+|a_x-a_y|.

You must support two types of operations (all kk are positive integers):

  • Modify x k, meaning modify the value of the xx-th number to kk;
  • Query x k, meaning ask how many ii satisfy graze(x,i)k\text{graze}(x,i) \leq k.

The query must consider not only the current sequence, but also any historical version. That is, count the number of pairs where any value that has ever appeared at any position and the current axa_x has graze\text{graze} value k\leq k. (If a position is modified to the same value multiple times, count it multiple times.)

Input Format

The first line contains two integers n,qn, q, representing the sequence length and the number of operations.

The second line contains nn positive integers, representing the initial sequence.

Lines 33 to q+2q+2 each contain one operation.

Output Format

For each query operation, output one non-negative integer as the answer.

3 5
2 4 3
Query 2 2
Modify 1 3
Query 2 2
Modify 1 2
Query 1 1
2
3
3

Hint

For all testdata, it is guaranteed that 1n6×1041\leq n\leq 6\times 10^4, 11\leq the number of modify operations 5×104\leq 5\times 10^4, 11\leq the number of queries 6×104\leq 6\times 10^4, and 11\leq the maximum value among all historical versions of ai105a_i \leq 10^5.

Translated by ChatGPT 5