Limits 2.5s, 512 MB

You will be given a list LL. Each element LiL_{i} will contain a list of integers. You have to perform two types of queries in list LL.

  • 11 ii ll rr xx yy

    This is the query of type 1 which asks you to replace the elements Lik(lkr)L_{i_{k}} (l \leq k \leq r) with yy if Lik=xL_{i_{k}} = x.

  • 22 ii

    Query type 2 asks you to determine the number of anagrams of LiL_{i} in list LL.


  • Anagram: Two arrays are anagrams if one can be formed by rearranging the elements of the other. Note that, in this problem, we consider an array to be an anagram of itself.


The first line of the input file will contain a positive integer N(1N105)N(1\leq N \leq 10^{5}) which denotes the number of elements in list LL.

Each of the next NN lines will start with a positive integer MM denoting the number of elements of LiL_{i}. Following by a space there will be MM space separated positive integers. Note that, (1Lij104)(1\leq L_{i_{j}} \leq 10^{4}).

Then, you will be given a positive integer Q(1Q6×105)Q(1\leq Q \leq 6 \times 10^{5}) in a new line.

After that you will be given the queries in the next QQ lines as described in the statement.

  • 11 ii ll rr xx yy

    Here, (1iN)(1 \leq i \leq N), (1lrLi)(1\leq l \leq r \leq |L_{i}|), (1x,y104)(1\leq x,y \leq 10^{4})

  • 22 ii

    Here, (1iN)(1\leq i \leq N)

Note that, (1i=1NLi105)(1 \leq \sum_{i=1}^{N}{|L_{i}|} \leq 10^{5}) and there will be at least one query of type 2.


For each query of type 22, print the answer in a new line.


2 10 20
2 20 10
2 10 10
2 2
2 3
1 1 2 2 20 10
2 2
2 3


Login to submit.


50% Solution Ratio
YouKnowWhoEarliest, 2w ago
YouKnowWhoFastest, 0.6s
YouKnowWhoLightest, 29 MB
YouKnowWhoShortest, 2692B
Toph uses cookies. By continuing you agree to our Cookie Policy.