q1. There are N balls of integral sizes ranging from X to Y (both included) arranged in a line.
Two arrangements A1 and A2 of all the balls on the line are considered to be the same if at every position i (1<=i<=N), Size of ball Ali=Size of ball A2i, Else, the arrangements A1 and A2 are considered to be different.
Consider the following operation: You can choose any two indices a,b such that 1 <=a <=b<=N and reverse the order of all balls from positions a to b. You can perform this operation at most once
How many different arrangements can you obtain?
Input
The first line contains N, X and Y respectively The next line contains N integers denoting the ses of the balls arranged in the line.
Constraints
1<=N<=1e6, 1<=X<=Y<= 1e9
output: an integer denoting no. of diff arrangements that can be obtained.
example:
input:
4 1 10
3 7 9 2
output:7
explanation:
3792,9732,2973,7392,3972,3297,3729
q2.there are n integers in an array,lets call the array V.You are given 2 integers A and B.
You perform following operations B times:
i)select the min element from V array,call it x,and delete it.
ii) insert x * A in this array.
After all operations sort V.Since numbers can be too large ,output V[i]%(1e9+7)
constraints:
1<=n<=50
1<=A,B<=1e9
1<=ai<=1e9
input:
3 10 2
1 99 10
output:
10,99,100
q3.
in city1: you can exchange one gold coin with gi rupees,i.e.,you can spend gi rupees and get 1 gold coin or spend 1 gold coin and get gi rupees.Similarly,si is for silver and bi for bronze.
To buy/sell one coin of gold,silver and bronze in City 2,it costs gj,sj,bj.
You are in city 1 currently and looking to increase your money,so you plan to visit city2 and return to city1.
Given you have n rupees, what is the max money you can have after your return to city1.
Note:you are allowed to visit city2 only once.
constraints:
1<=n<=5000
1<=gi,si,bi,gj,sj,bj<=5000
input:
n
gi si bi
gj sj bj
example:
10
2 1 1
1 1 2
ans:40
buy 10 bronze coins in city 1 before going to city2. Sell them in city 2,now you have 20 rupees.Buy gold in city 2 and then come to city 1 and sell it.so total 40 rupees.
q4. we have a road of length m with m+1 bus stops at 0,1,....,m.
"d-bus" starts from 0th point and then stops at every dth bus stop.Eg: d=2, bus starts at 0 and stops at 2,4,6... 2 * floor(m/2)
we have n flower gardens along the road. The ith garden ranges from Ai to Bi and ith garden has plants that produces flower of type i only.
You travelling in a d bus collect ith type flower if your bus stop is at some point in the range [Ai,Bi].
For each d=1,2,...m find the max no. of different flowers you will be able to collect when you travel in a d bus
Note that there are unlimted flowers of each type.
Input:
n m
A1 B1
....
An Bn
constraints:
1<=n<=3 * 1e5
1<=m<=1e5
1<=Ai<=Bi<=m
Input:
3 4
1 2
2 3
4 4
output:
3 //d=1
3 //d=2
1 //d=3,can collect only flower 2
1 //d=4,can only collect flower 3