Sample Question
Sample Question
For the subarray of A ranging from index l to r, you need to for query 1:
assign a sequence of integers for each subsequent element. l = 0, r = 2, x = 1, y = 2
The sequence should start from x and increase by y. This means: A[0] = 1
A[1] = 3
• A[l] will be assigned the value of x. A[2] = 5
Find the sum of all integers in A after processing all queries. So, A = [6, 11, 5, 3, 0]
Since answer can be large, return it modulo 109+7.
for query 3:
Input Format l = 2, r = 3, x = 8, y = 0
A[2] = 8
1. The first line contains an integer, n, denoting the A[3] = 8
number of elements in A.
So, A = [6, 11, 8, 8, 0]
2. Each line i of the n subsequent lines (where 0 ≤ i < n)
contains an integer describing A[i]. for query 4:
l = 2, r = 4, x = 9, y = 6
3. The next line contains an integer, q, denoting the
A = [6, 11, 9, 15, 21]
number of rows in queries.
5. The 4 space separated integers denote the value of l, r, Hence, answer is 6+11+9+8+17 = 51
x and y for the i-th query.
for query 2:
l = 1, r = 2, x = 2, y = 8
So, A = [3, 2, 10, 5, 4]
for query 3:
l = 1, r = 2, x = 5, y = 5
So, A = [3, 5, 10, 5, 4]
for query 4:
l = 1, r = 3, x = 1, y = 8
So, A = [3, 1, 9, 17, 4]
for query 5:
l = 1, r = 2, x = 2, y = 9
A = [3, 2, 11, 17, 4]
Sample Input 3
5
0
1
0
0
1
5
1277
0136
1111
3491
2310
Sample output 3
16
Explanation 3
Here, n = 5
A = [0, 1, 0, 0, 1]
q = 5
queries = [[1, 2, 7, 7], [0, 1, 3, 6], [1,
1, 1, 1], [3, 4, 9, 1], [2, 3, 1, 0]]
for query 1:
l = 1, r = 2, x = 7, y = 7
A = [0, 7, 14, 0, 1]
for query 2:
l = 0, r = 1, x = 3, y = 6
A = [3, 9, 14, 0, 1]
for query 3:
l = 1, r = 1, x = 1, y = 1
A = [3, 1, 14, 0, 1]
for query 4:
l = 3, r = 4, x = 9, y = 1
A = [3, 1, 14, 9, 10]
for query 5:
l = 2, r = 3, x = 1, y = 0
A = [3, 1, 1, 1, 10]
operation 1:
Apply type 1 operation (i.e. Subtract B[1] from sum.) Apply type 2 operation (i.e. Decrease both of X and Y by 1,
then add A[2]*X*Y*Z to sum)
sum = sum - 10 = -10
X = 2, Y = 2, Z = 3
operation 2:
sum = sum + 2*2*2*3 = 23
Apply type 3 operation
(i.e. Decrease both of Y and Z by 1, then add
A[2]*X*Y*Z to sum) operation 3:
3
Hence, answer is the final value of sum i.e. sum = 35.
3
3
3
1
2
3
1
2
3
Sample output-3:
35
Explanation-3:
Here, N = 3, X = 3, Y = 3, Z = 3
A = [1, 2, 3]
B = [1, 2, 3]
operation 1:
Apply type 1 operation
(i.e. Subtract B[1] from sum.)
sum = sum - 1 = -1
operation 2:
q = 3 5
queries = [5, 4, 3] Sample Explanation - 3:
for query 2:
for query 1:
s = 4, means we need to select beautiful set of maximum
size in the subtree of node 4. s = 2, means we need to select beautiful set of maximum size
in the subtree of node 2.
we can select nodes {4} to form beautiful set of maximum
size. we can select nodes {2} to form beautiful set of maximum size.
so, answer for this query is 1. so, answer for this query is 1.
s = 3, means we need to select beautiful set of maximum s = 4, means we need to select beautiful set of maximum size in
size in the subtree of node 3. the subtree of 4.
we can select nodes {3} to form beautiful set of maximum we can select nodes {4} to form beautiful set of maximum size.
size.
so, answer for this query is 1.
so, answer for this query is 1.
for query 3:
Sample Input-3: we can select nodes {5} to form beautiful set of maximum size.
5
0 so, answer for this query is 1.
1
for query 4:
1
1 s = 1, means we need to select beautiful set of maximum size
3
5 in the subtree of 1.
5
we can select nodes {1, 4} to form beautiful set of maximum size.
5
1 so, answer for this query is 2.
5
4 Hence, answer is 1 + 1 + 1 + 2 = 5.
2
© 2024 Infosys Limited, Bengaluru, India. All Rights Reserved. Infosys believes the information in this document is accurate as of its publication date; such information is subject to change without notice. Infosys
acknowledges the proprietary rights of other companies to the trademarks, product names and such other intellectual property rights mentioned in this document. Except as expressly permitted, neither this
documentation nor any part of it may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, electronic, mechanical, printing, photocopying, recording or otherwise, without the
prior permission of Infosys Limited and/ or any named intellectual property rights holders under this document.