Get queries

4.3

3 votes
Advanced Data Structures, Segment Trees, Basics of Implementation, Data Structures, Implementation, Segment tree, Math
Problem

You are given an array A that contains N numbers and M queries. The queries are of the following two types:

  • update position value: Update the number at position aposition with value.
  • get l r k : Write all the numbers from al to position ar inclusive without spaces. You are required to print the kth digit in this sequence. If there are fewer digits in the sequence, print -1.

Input format

  • The first line contains two numbers N and M.
  • The second line contains N numbers denoting the array A.
  • From the third line to M + 2 line, the queries are explained.

Output format

Print a response for each get queries. Refer to the explanation for a better understanding of the problem statement.

Constraints

1N,M2105

0a[i],value2109

1lrN

1positionN

1k2109

Sample Input
5 5
1 100 2 3 5
get 1 4 4
update 2 3
get 1 4 4
get 1 4 100
get 1 5 3
Sample Output
0
3
-1
2
Time Limit: 1.5
Memory Limit: 256
Source Limit:
Explanation

Our first queries is of type get. If you write out all the numbers from 1 to 4 positions inclusive, you get the following sequence - 110023. Position 4 in this sequence is 0.

The second update queries. Change 100 to 3.

The third queries is of type get. Sequence - 1323. 4th position - 3.

The fourth query - we have 4 digits in the sequence, 4 < 100 - output -1.

The fifth queries is 13235. We have 2 for 3 positions.

Contributers:
Editor Image

?