#P6749. Sequence Operations and Inversion Count
Sequence Operations and Inversion Count
Sequence Operations and Inversion Count
Yoshino gives you a sequence of length $$n$$ with the $$i$$-th element being $$a_i$$. Yoshino will perform $$m$$ operations on the sequence.
Operations are of two types:
- 1 l r x: Yoshino updates the elements in the range $$[l, r]$$ to form an arithmetic sequence starting from $$x$$ with a common difference of 1. In other words, for every index $$i$$ in $$[l, r]$$, the value is set to $$a_i = x + (i - l)$$.
- 2: Yoshino queries the current number of inversion pairs in the entire sequence. An inversion pair is defined as a pair of indices $$(i, j)$$ such that $$i a_j$$.
inputFormat
The first line contains two integers $$n$$ and $$m$$: the length of the sequence and the number of operations.
The second line contains $$n$$ integers: $$a_1, a_2, \dots, a_n$$, representing the initial sequence.
Then follow $$m$$ lines, each describing an operation:
- If the operation is of type
1
, the line contains four integers:1 l r x
. - If the operation is of type
2
, the line contains a single integer:2
.
outputFormat
For every operation of type 2
, output one integer on a new line: the number of inversion pairs in the current sequence.
sample
5 3
1 3 2 5 4
2
1 2 4 0
2
3
4
</p>