Chef & Chutneys

3.9

16 votes
Advanced Data Structures, Segment Trees, Gaussian Elimination, Data Structures, Linear Algebra, Math
Problem

A chef has recently opened a new restaurant to serve his special dishes. He has a list of ingredients from which he makes them. Each ingredient is denoted by a unique lowercase letter. Thus, a dish is represented as a string of ingredients possibly with repititions. There are people in his restaurant currently each of whom have ordered some dished.

You are given a collection of dishes with duplicates possibly. The chef can serve one of his favorite dishes from them if he is able to reorder all their ingredients (i.e. a permutation of the concatenation of all the strings) such that they form a palindrome. You have to facilitate the day-to-day working of the restaurant. There are two types of events happening in the restaurant:

  1. A person updates his order to get a new kind of dish.
  2. People in the range wants to know the number of non-empty subsets of from which the Chef can make one of his favorite dish.

You are given the initial orders of the people. Therefore, you have to process  events of the mentioned types. 

Input format

  • First Line: Two integers  denoting the number of people currently in the restaurant and the numbers events happening over time

  • Second Line: space seperated strings consisting only of lowercase letters,  where  denotes the chutney initially ordered by the  person
  • Next Lines: Event of any of the above two type in the following format:
    1. : The  person has updated his order to a new chutney :
    2. : Count the number of subsets satisfying the constraint described above.

Output format

Print the required answer for each event of the  type.

Constraints

There is at least one event of type.

 

Sample Input
11 8
tamarind red mint coconut ginger peanut pudina tomato periperisauce hummus redchilli
2 1 4
2 3 10
2 1 7
2 4 11
1 8 papaya
2 4 11
1 4 onion
2 1 7
Sample Output
1
0
2
2
2
3
Time Limit: 4
Memory Limit: 256
Source Limit:
Explanation

For the first 3 events, answers are as follows:

  1. We have only 1 subset from the first 4 chutneys from which Chef can prepare one of his favorite chutney: .
    Note: There might by many possible favorite chutneys Chef can prepare from a specific collection of chutneys but people are only interested to know if he can prepare one of them.
  2. There is no subset from from which Chef can prepare any of his favorite chutney.
  3. Indices from which favorite chutney can be prepared: .
Editor Image

?