random answer. Computer science. Stage an is lexicographically more modest than change b (they have a similar length n), if in the main file I wherein they vary, a[i]
Correct answer will be upvoted else Multiple Downvoted. Don't submit random answer. Computer science.
Stage an is lexicographically more modest than change b (they have a similar length n), if in the main file I wherein they vary, a[i]<b[i]. For instance, the change [1,3,2,4] is lexicographically more modest than the stage [1,3,4,2], on the grounds that the initial two components are equivalent, and the third component in the principal stage is more modest than in the second.
The following change for a stage an of length n — is the lexicographically littlest stage b of length n that lexicographically bigger than a. For instance:
for change [2,1,4,3] the following stage is [2,3,1,4];
for change [1,2,3] the following stage is [1,3,2];
for stage [2,1] next change doesn't exist.
You are given the number n — the length of the underlying stage. The underlying stage has the structure a=[1,2,… ,n]. At the end of the day, a[i]=i (1≤i≤n).
You really want to handle q inquiries of two sorts:
1 l r: inquiry for the amount of all components on the fragment [l,r]. All the more officially, you want to find a[l]+a[l+1]+… +a[r].
2 x: x occasions supplant the current stage with the following change. For instance, in the event that x=2 and the current change has the structure [1,3,4,2], we ought to perform such a chain of substitutions [1,3,4,2]→[1,4,2,3]→[1,4,3,2].
For each inquiry of the 1-st type output the necessary aggregate.
Input
The main line contains two integers n (2≤n≤2⋅105) and q (1≤q≤2⋅105), where n — the length of the underlying stage, and q — the number of inquiries.
The following q lines contain a solitary inquiry of the 1-st or 2-nd type. The 1-st type question comprises of three integers 1, l and r (1≤l≤r≤n), the 2-nd type inquiry comprises of two integers 2 and x (1≤x≤105).
It is ensured that all solicitations of the 2-nd type are feasible to process.
Output
For each inquiry of the 1-st type, output on a different line one integer — the necessary aggregate.
Step by step
Solved in 4 steps with 1 images