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]

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question
100%

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.

 

 

Expert Solution
steps

Step by step

Solved in 4 steps with 1 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY