given a cluster a comprising of n integers. At first all components of an are either 0 or 1. You wanted to deal with q inquiries of two sorts:    1 x : Assign to cut out the worth 1−ax.    2 k : Print the k-th biggest worth of the cluster.

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.

 

 You are given a cluster a comprising of n integers. At first all components of an are either 0 or 1. You wanted to deal with q inquiries of two sorts: 

 

1 x : Assign to cut out the worth 1−ax. 

 

2 k : Print the k-th biggest worth of the cluster. 

 

As an update, k-th biggest worth of the cluster b is characterized as following: 

 

Sort the cluster in the non-expanding request, return k-th component from it. 

 

For instance, the second biggest component in exhibit [0,1,0,1] is 1, as in the wake of arranging in non-expanding request it becomes [1,1,0,0], and the second component in this cluster is equivalent to 1. 

 

Input 

 

The principal line contains two integers n and q (1≤n,q≤105) — the length of the given cluster and the number of questions. 

 

The subsequent line contains n integers a1,a2,a3,… ,an (0≤ai≤1) — components of the underlying cluster. 

 

Every one of the accompanying q lines contains two integers. The main integer is t (1≤t≤2) — the sort of question. 

 

In the event that t=1 the subsequent integer is x (1≤x≤n) — the situation of the altered number. You need to appoint to hack out the worth 1−ax. 

 

In the event that t=2 the subsequent integer is k (1≤k≤n) — you wanted to print the k-th biggest worth of the exhibit. 

 

It's surefire that there will be something like one inquiry of the subsequent kind (fulfilling t=2). 

 

Output 

 

For each inquiry of the subsequent sort, print a solitary integer — the response to the question

 

 

Expert Solution
steps

Step by step

Solved in 4 steps with 1 images

Blurred answer
Knowledge Booster
Hash Table
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar 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