Plus
Pin


Problem description Progress
ID 23582. Minimum on segment of immutable array
Темы: Sparse tables   

You are given an array A [1…N]. It is required to perform M calculation of the minimum element on the segment from L to R.

Input
The first line contains the number N (\(1 <= N <= 100000\)) – array size. The second line contains N numbers – array elements. The third line contains the number M (\(1 <= M <= 100000\)) – minimum number of requests. The next M lines contain pairs of numbers L and R (\(L <= R < = N\)) describing segments.

Imprint
For each query print the value of the minimum on the segment separated by a space.

 

Examples
# Input Output
1 5
3 1 8 7 9
2
1 3
3 5
1 7

ID 23583. Oleg Evgenievich and the new Counter-Strike
Темы: Sparse tables   

Recently, a new Counter-Strike 2 game has been released. There is N in 5th grade and they all want to play this game. At the physical education lesson, all the students were lined up. Physical education instructor Oleg Evgenievich is in a mixed mood today: he decided to allow students to play CS2 instead of physical activities, but they will only play according to certain rules. 

Oleg Evgenievich will allow all students to play, whose line number lies in the segment \([L;R]\). Oleg Evgenievich found out that the parents of children are only allowed to play on the computer for ti minutes. But the students are very fond of computer games, so everyone will play exactly ti minutes, while no one refuses to play. 

The game is played as follows: a match time is chosen such that each student must play a strictly integer number of matches, while the number of matches played by each student may vary and the match time should be as long as possible. 

For example, 2 players are playing. If player has 1 time \(t_1 = 12\) and player 2 has \(t_2 = 8\) , then the maximum possible match time is 4 minutes. 1 player will be able to play 3 matches of 4 minutes, and 2 – 2 matches of 4 minutes. 

Oleg Evgenievich has been hard at work lately, so he decided M times to calculate the maximum time Q for players from L to R. You should check Oleg Evgenievich. To do this, print YES if it is correct, otherwise – NO.

Input
The first line contains the number N (\(1 <= N <= 10000\)) – the number of guys. The second line contains N numbers – ti (\(1 <= t_i <= 1000\)), time, given by the parents i-th child to play. The third line contains the number M (\(1 <= M <= 10^8\)), the number of queries. Further, in M lines there are 3 numbers L, R, Q (time calculated by Oleg Evgenievich).

Imprint
Output for each request YES if Oleg Evgenievich calculated correctly, otherwise – NO.

 

Examples
# Input Output
1 3
8 5 6
4
1 2 2
1 3 1
2 3 1
1 3 2
NO
YES
YES
NO