Child Ehab has a piece of Cut and Stick with an exhibit an of length n composed on it. He intends to snatch some scissors and do the accompanying to it:    pick a reach (l,r) and cut out each component al, al+1, ..., ar in this reach;    stick a portion of the components together in a similar request they were in the exhibit;

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Correct answer will be upvoted else downvoted. Computer science.

 

 Child Ehab has a piece of Cut and Stick with an exhibit an of length n composed on it. He intends to snatch some scissors and do the accompanying to it: 

 

pick a reach (l,r) and cut out each component al, al+1, ..., ar in this reach; 

 

stick a portion of the components together in a similar request they were in the exhibit; 

 

end up with different pieces, where each piece contains a portion of the components and each component has a place with some piece. 

 

All the more officially, he segments the arrangement al, al+1, ..., ar into aftereffects. He thinks a dividing is lovely if for each piece (aftereffect) it holds that, assuming it has length x, no worth happens rigorously more than ⌈x2⌉ times in it. 

 

He didn't pick a reach yet, so he's pondering: for q ranges (l,r), what is the base number of pieces he really wants to parcel the components al, al+1, ..., ar into with the goal that the dividing is delightful. 

 

A succession b is an aftereffect of an exhibit an if b can be acquired from a by erasing a few (perhaps zero) components. Note that it doesn't need to be adjoining. 

 

Input 

 

The principal line contains two integers n and q (1≤n,q≤3⋅105) — the length of the exhibit an and the number of questions. 

 

The subsequent line contains n integers a1, a2, ..., an (1≤ai≤n) — the components of the exhibit a. 

 

Every one of the following q lines contains two integers l and r (1≤l≤r≤n) — the scope of this question. 

 

Output 

 

For each question, print the base number of aftereffects you wanted to segment this reach into so the dividing is delightful. We can demonstrate such dividing consistently exists.

Expert Solution
steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education