Array and good pairs

1.8

8 votes
Advanced Data Structures, Data Structures, Segment Trees
Problem

You are given an array A of length N. A pair (a, b) is considered good if the following criterion is fulfilled:

Consider the decimal representation of a and b. a has digits a1,a2,...,ak1 and b has digits b1,b2,...,bk1. (a, b) is good only if there is no index y (1yk) such that ay and by are non-zero elements.

You are required to process Q queries where each having one of the following forms:

0ix: Change the ith index to x in the array
1lr: Consider all the pairs (i, j) such that lijr such that (ai, aj) is a good pair and add aiaj to the answer.
Note: As the answer can be large, print answer modulo 109+7.

Input format

  • First line: An integer N (1N105) representing the length of the array
  • Second line: N space-separated integers that representing the elements of the array (0Ai999999)
  • Next q lines: One of the queries of the following forms:
    • 0ix (1iN, 0x999999)
    • 1lr (1lrN)

Output format

For each query of type 1, print the required answer in a separate line.
 

Time Limit: 2
Memory Limit: 256
Source Limit:
Explanation

-

Editor Image

?