Codeforces Round 156 (Div. 1)
E
Lucky Arrays
Codeforces
2400
原题
← D→
翻译中…

Little Maxim loves interesting problems. He decided to share one such problem with you.

翻译中…

Initially there is an array $*a*$, consisting of $*n*$ zeroes. The elements of the array are indexed, starting from 1. Then follow queries to change array $*a*$. Each query is characterized by two integers $*v*_{*i*}, *t*_{*i*}$. In the answer to the query we should make the $*v*_{*i*}$-th array element equal $*t*_{*i*}$ $(*a*_{*v*_{*i*}} = *t*_{*i*}; 1 ≤ *v*_{*i*} ≤ *n*)$.

翻译中…

Maxim thinks that some pairs of integers $(*x*, *y*)$ are good and some are not. Maxim thinks that array $*a*$, consisting of $*n*$ integers, is lucky, if for all integer $*i*$, $(1 ≤ *i* ≤ *n* - 1)$ the pair of integers $(*a*_{*i*}, *a*_{*i* + 1})$ — is good. Note that the order of numbers in the pairs is important, that is, specifically, $(1, 2) ≠ (2, 1)$.

翻译中…

After each query to change array $*a*$ Maxim wants to know, how many ways there are to replace all zeroes in array $*a*$ with integers from one to three so as to make the resulting array (without zeroes) lucky. Of course, distinct zeroes can be replaced by distinct integers.

翻译中…

Maxim told you the sequence of queries and all pairs of integers he considers lucky. Help Maxim, solve this problem for him.

翻译中…

Input

翻译中…

The first line contains integers $*n*$ and $*m*$ $(1 ≤ *n*, *m* ≤ 77777)$ — the number of elements in the array and the number of commands.

翻译中…

The next three lines contain matrix $*w*$, consisting only of zeroes and ones; the $*j*$-th number in the $*i*$-th of these lines — $*w*_{*i*, *j*}$. If $*w*_{*i*, *j*} = 1$ $(1 ≤ *i*, *j* ≤ 3)$, then pair $(*i*, *j*)$ is good, otherwise it is not good. Matrix does not have to be symmetric relative to the main diagonal.

翻译中…

Next $*m*$ lines contain pairs of integers $*v*_{*i*}, *t*_{*i*}$ $(1 ≤ *v*_{*i*} ≤ *n*, 0 ≤ *t*_{*i*} ≤ 3)$ — the queries to change the array.

翻译中…

Output

翻译中…

Print $*m*$ integers — the $*i*$-th number should equal to the number of ways to replace all zeroes in array $*a*$ (changed after the $*i*$-th query) by integers from one to three so as to make the resulting array (without zeroes) lucky. Separate the numbers by whitespaces. As the answers can be rather large, print the remainder from dividing them by $777777777$.

翻译中…

样例

Input #1
3 10
1 1 0
1 0 0
1 1 1
1 1
1 3
2 2
3 0
2 1
3 0
3 1
2 0
3 1
1 0
Output #1
3
6
1
1
2
2
1
3
3
6
InputCopy OutputCopy
题目信息
题号
256E
时间限制
4 s
内存限制
256 MB
标签
数据结构

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。