Operations on an array

2.4

27 votes
Advanced Data Structures, C++, Data Structures, Fenwick Tree
Problem

You are given an array of elements and an integer . You must perform the following types of operations on the array:

  1. Find the index of the  occurrence of  in the range to (both inclusive). If there are no indexes that satisfy the condition, then print .
  2. Update the value that is present at the given index.

For each query of type 1, print the index of the occurrence of .

Input format

  • The first line contains two integers and denoting the number of elements and an integer whose index is required respectively.
  • The second line contains integers  denoting the elements of the array
  • The third line contains an integer denoting the number of queries
  • Next q lines contain the following type of queries:
    • If type is equal to 1, then , , and (refer to the first point of the problem statement)
    • If type is equal to 2, then index and value (refer to the second point of the problem statement)

Output format

Print  integers as the answer to type 1 queries. If there are no indexes that satisfy the condition, then print .

Constraints

Sample Input
7 1
2 1 3 1 1 4 5
5
1 1 2 1
1 2 3 1
1 4 5 1
2 2 2
1 1 2 3
Sample Output
2
2
4
-1
Time Limit: 1
Memory Limit: 255
Source Limit:
Explanation

Values in the Array : 2 1 3 1 1 4 5

Index of Element    : 1 2 3 4 5 6 7

Editor Image

?