Блог пользователя algorithms400

Автор algorithms400, 5 лет назад, По-английски

Initially, I have given empty list. I have given Q queries, each queries can perform two types of operation on this list as :

1 x y : Insert value x, y times in list.

2 k : Print kth element of sorted list.

Constraints:

1<= Q <= 2*100000

1<= x,y <= 10^9

At any query, k is always less than or equal to list size.

List can have maximum 10^5 different values.

I have tried to solve this using set of pairs, but for each print it takes O(n) time in worst case.

Please, helps in figure out to solve these operation in O(n*log n ) where n stands for maximum size of list.

Полный текст и комментарии »

  • Проголосовать: нравится
  • +10
  • Проголосовать: не нравится

Автор algorithms400, история, 6 лет назад, По-английски

How to find the numbers of ways to fill a grid (3*n)array, with three colors A, B and C.

Under the following constraints:

1) All the n cells of the same row can't have the same color.

2) All the 3 cells of the same column can't have the same color.

Sample input : if n=2, then output or number of ways = 174.

Please explain the approach for this.

Полный текст и комментарии »

  • Проголосовать: нравится
  • 0
  • Проголосовать: не нравится