2017 ACM-ICPC 亚洲区(西安赛区)网络赛

A

There is a tree with nn nodes, at which attach a binary 64*6464∗64 matrix M_i (1 \le i \le n)M
​i
​​ (1≤i≤n). There are qq queries for matrix multiplication on the path from node aa to node bb modulo 22. To avoid massive input dataset, M_i(1\le i \le n)M
​i
​​ (1≤i≤n) is attained by the following algorithm:

Input a random seedseed (unsigned long long)

1
for(int i = 1; i <= n; ++i) {
2
for(int p = 1; p <= 64; ++p) {
3
seed ^= seed * seed + 15;
4
for(int q = 1; q <= 64; ++q) {
5
M[i][p][q] = (seed >> (q - 1)) & 1;
6
}
7
}
8
}
To avoid massive output, you should output

\displaystyle (\displaystyle \sum_{i=1}^{64} \sum_{j=1}^{64} M_{ij}*19i*26j) \mod 19260817(
​i=1
​∑
​64
​​
​j=1
​∑
​64
​​ M
​ij
​​ ∗19
​i
​​ ∗26
​j
​​ )mod19260817

Input Format

There are multi datasets. (\sum n \le 3000, \sum q \le 30000)(∑n≤3000,∑q≤30000).

For each dataset:

In the first n-1n−1 lines, there are to integers u,vu,v, indicates there is an edge connects node uu and node vv.(1\le u,v \le n)(1≤u,v≤n).

In the next line there is an integer seed(0 \le seed < 2^{64})seed(0≤seed<2
​64
​​ ).

In the next qq lines, there is to integers a,ba,b, indicates a query on path from node aa to node bb.(1 \le a,b \le n)(1≤a,b≤n).

Output Format

For each query, output an integer in one line without any additional space.

样例输入

6 5
4 1
3 4
6 4
5 3
2 3
19260817
4 5
5 6
4 4
2 1
2 2
样例输出

4855239
2667906
277543
14478924
1173682

B

Bob has a not even coin, every time he tosses the coin, the probability that the coin's front face up is \frac{q}{p}(\frac{q}{p} \le \frac{1}{2})
​p

​q
​​ (
​p

​q
​​ ≤
​2

​1
​​ ).

The question is, when Bob tosses the coin kk times, what's the probability that the frequency of the coin facing up is even number.

If the answer is \frac{X}{Y}
​Y

​X
​​ , because the answer could be extremely large, you only need to print (X * Y^{-1}) \mod (10^9+7)(X∗Y
​−1
​​ )mod(10
​9
​​ +7).

Input Format

First line an integer TT, indicates the number of test cases (T \le 100T≤100).

Then Each line has 33 integer p,q,k(1\le p,q,k \le 10^7)p,q,k(1≤p,q,k≤10
​7
​​ ) indicates the i-th test case.

Output Format

For each test case, print an integer in a single line indicates the answer.

样例输入

2
2 1 1
3 1 2
样例输出

500000004
555555560

C

Define the function S(x)S(x) for xx is a positive integer. S(x)S(x) equals to the sum of all digit of the decimal expression of xx. Please find a positive integer kk that S(k*x)%233=0S(k∗x)%233=0.

Input Format

First line an integer TT, indicates the number of test cases (T \le 100T≤100). Then Each line has a single integer x(1 \le x \le 1000000)x(1≤x≤1000000) indicates i-th test case.

Output Format

For each test case, print an integer in a single line indicates the answer. The length of the answer should not exceed 20002000. If there are more than one answer, output anyone is ok.

样例输入

1
1
样例输出

89999999999999999999999999

D

Player #0 and Player #1 are playing a game, and they move by turns. Given nn strings, all of which only consist of the characters 00 and 11. When in Player #i's move (i = 0, 1), he has to select a character i in any of the nn strings, and remove it and all the characters on its right side. Anyone who can't move loses and the other one wins.

They find the game fairly easy after playing a while, so they make a tiny change to the original game. Besides the characters 00 and 11, now each string may contain at most one pair of parentheses, denoting that the substring between the parentheses is compressed, which occurs actually infinite times. You need to figure out who will be the winner at last, assuming that both players are rational enough.

Input Format

Multiple test cases(about 100 test cases).

For each test case, a integer in the first line denotes n(n \le 10)n(n≤10).

Then nn strings, S_1,S_2,\cdots,S_nS
​1
​​ ,S
​2
​​ ,⋯,S
​n
​​ , follow in the next n lines. |S_i| \le 50∣S
​i
​​ ∣≤50.

It is guaranteed that the sum of length of strings in all test cases is no more than 1000010000.

Output Format

For each test case, if Player #i (i = 0,1)(i=0,1) wins regardless of moving first or not, print "i wins", otherwise print "tie".

Hint

Once a player selects a character between the parentheses and removes it and all the characters on its right side, the actual length of the string will decrease from infinity to a finite number, hence all the games will end in finite turns.

Taking the third sample for instance, without loss of generality, let Player #0 moves first. Let’s assume that he selects the (k+1)-th character between the parentheses, and then the string will become 0000...00000...0, whose length is kk. Afterwards Player #1 have to remove infinite 1s and make sure the number of the remaining 1s is greater than or equal to kk. Then we will see Player #1 must be the winner. According to symmetry of the initial strings, Player #0 will win if Player #1 moves first. Therefore, the game is a tie.

样例输入

2
10
0
2
0(1)
100000000000000
2
(0)
(1)
3
0(1)0
1(0)
1(0)
3
0(1)1
0(1)1
1(0)
样例输出

0 wins
1 wins
tie
tie
tie

E

Given a directed graph with nn nodes, labeled 0,1, \cdots, n-10,1,⋯,n−1.

For each <i, j><i,j> satisfies 0 \le i < j < n0≤i<j<n, there exists an edge from the i-th node to the j-th node, the capacity of which is ii xor jj.

Find the maximum flow network from the 0-th node to the (n-1)-th node, modulo 10000000071000000007.

Input Format

Multiple test cases (no more than 1000010000).

In each test case, one integer in a line denotes n(2 \le n \le 10^{18})n(2≤n≤10
​18
​​ ).

Output Format

Output the maximum flow modulo 10000000071000000007 for each test case.

样例输入

2
样例输出

1

F

f(cos(x))=cos(n∗x) holds for all xx.

Given two integers nn and mm, you need to calculate the coefficient of x^mx
​m
​​ in f(x)f(x), modulo 998244353998244353.

Input Format

Multiple test cases (no more than 100100).

Each test case contains one line consisting of two integers nn and mm.

1 \le n \le 10^9,0 \le m \le 10 ^ 41≤n≤10
​9
​​ ,0≤m≤10
​4
​​ .

Output Format

Output the answer in a single line for each test case.

样例输入

2 0
2 1
2 2
样例输出

998244352
0
2

G

There is a tree with nn nodes. For each node, there is an integer value a_ia
​i
​​ , (1 \le a_i \le 1,000,000,0001≤a
​i
​​ ≤1,000,000,000 for 1 \le i \le n1≤i≤n). There is qq queries which are described as follow: Assume the value on the path from node aa to node bb is t_0, t_1, \cdots t_mt
​0
​​ ,t
​1
​​ ,⋯t
​m
​​ . You are supposed to calculate t_0t
​0
​​ xor t_kt
​k
​​ xor t_{2k}t
​2k
​​ xor ... xor t_{pk}t
​pk
​​ (pk \le m)(pk≤m).

Input Format

There are multi datasets. (\sum n \le 50,000, \sum q \le 500,000)(∑n≤50,000,∑q≤500,000).

For each dataset: In the first n-1n−1 lines, there are two integers u,vu,v, indicates there is an edge connect node uu and node vv.

In the next nn lines, There is an integer a_ia
​i
​​ (1 \le a_i \le 1,000,000,0001≤a
​i
​​ ≤1,000,000,000).

In the next qq lines, There is three integers a,ba,b and kk. (1 \le a,b,k \le n1≤a,b,k≤n).

Output Format

For each query, output an integer in one line, without any additional space.

样例输入

5 6
1 5
4 1
2 1
3 2
19
26
0
8
17
5 5 1
1 3 2
3 2 1
5 4 2
3 4 4
1 4 5
样例输出

17
19
26
25
0
19

H

AI likes playing a game named "Rhythm Master".

He plays this game day after day, it is super noisy. His roommate can not tolerate him anymore, so he decide to write a plug-in to defeat AI.

We can regard this game as in an 1\times n1×n keyboard. Every millisecond, there are some note drop to some position of your keyboard. Notes have two different types.

'*': The note is a single note, you can press the corresponding button to get 55 points.

'#': The note is a continuous note, this position will be '#' for several milliseconds, only if you press the corresponding button and never get miss between the continuous note, you can get 10*P10∗P points, PP is the number of '#'.

For more, '.' means at this time there are no note drop to the position.

The word miss means, if you lose any note at millisecond TT, you will get miss at TT.

For example:

Time 11: #..*

Time 22: #...

If you press (1001) at the first millisecond(11 means pressing, 00 means no pressing), you will get 55 points, if you press (1000) at the second millisecond, you will get 10*2=2010∗2=20 points.

If you press (1000) at the first millisecond, you will get 00 points, if you press (1000) at the second millisecond, you will get 00 points, because you get miss at millisecond 11.

To make this game more interesting, the developer add a new data named combo.

If you don’t get miss at millisecond TT, you will get a combocombo, means combo=combo+1combo=combo+1;

If you get miss at millisecond TT, or the game ends, you will get \frac{combo^2}{2}+\frac{combo}{2}-1
​2

​combo
​2
​​
​​ +
​2

​combo
​​ −1 points and then your combo will become to 00.

For example:

Time 11: #..#

Time 22: #..#

Time 33: #...

If you press (1001),(1001),(1001) in first 33 times, you will get 30+20+3*3/2+3/2-1 = 5530+20+3∗3/2+3/2−1=55 points.

If you press (1001),(1001),(0000) in first 33 times, you will get 20+2*2/2+2/2-1 = 2220+2∗2/2+2/2−1=22 points.

If you press (1001),(0001),(1000) in first 33 times, you will get 00 point.

Now the plug-in is ready for use, but we notice it has some bugs.

If the plug-in press XX at millisecond TT, It can not press YY at millisecond T+1T+1.

For example:

X=1010, Y=0101X=1010,Y=0101.

If the plug-in press 1010(or 1110,1011,1111) at time TT, it can not press 0101 at time T+1T+1, so can’t 1101,0111, and 1111.

Help the plug-in to find the maximum points it can get.

Input Format

Several test cases.

Each case begins with 33 integers N,M,K(1\le N\le 7,1 \le M \le 5000,1 \le K \le 1000)N,M,K(1≤N≤7,1≤M≤5000,1≤K≤1000). NN is the size of keyboard. MM is the millisecond of the game. KK is the number of bug.

The next KK lines, each line contains two 01 string, means X,YX,Y.

Then MM lines follow, each line contains a string with length NN, the i-th(1 \le i \le M1≤i≤M) line means the situation of millisecond ii.

Output Format

For each test case, print an integer in a single line.

样例输入

4 4 2
1111 1111
0011 1100


*##

*##

..#

样例输出

30

I

Barty have a computer, it can do these two things.

Add a new string to its memory, the length of this string is even.

For given 44 strings a,b,c,da,b,c,d, find out how many strings that can be product by a+s1+b+c+s2+da+s1+b+c+s2+d, and |a| + |s1| + |b| = |c| + |s2| + |d|∣a∣+∣s1∣+∣b∣=∣c∣+∣s2∣+∣d∣. |s|∣s∣ means the length of string ss, s1s1 and s2s2 can be any string, including "".

Please help your computer to do these things.

Input Format

Test cases begins with T(T \le 5)T(T≤5).

Then TT test cases follows.

Each test case begins with an integer Q(Q \le 30000)Q(Q≤30000).

Then QQ lines,

1 s: add a new string ss to its memory.

2 a b c d: find how many strings satisfying the requirement above.

\sum |s| + |a| + |b| + |c| + |d| \le 2000000∑∣s∣+∣a∣+∣b∣+∣c∣+∣d∣≤2000000.

Output Format

For type 22 query. Output the answer in one line.

样例输入

1
10
1 abcqaq
1 abcabcqaqqaq
2 ab bc qa aq
2 a c q q
1 abcabcqaqqwq
2 ab bc qa aq
2 a c q q
1 abcq
2 a c q q
2 a b c q
样例输出

1
2
1
3
3
1

G

This problem is very easy. You need to do these QQ queries.

Queries have 33 types.

1 n x1 x2 x3 , ... , xn: Add a new sequence to the next line.

2 x l1 r1 y l2 r2: Copy two sub-sequence and expend them to the next line.

3 x k: Output the first kk sum of sub-sequence of sequence in the x-th line, in increasing order of the sum of each sub-sequence.

Input Format

First line an integer T(T=6)T(T=6), indicates the number of test cases.

In each case, begin with an integer Q(Q \le 100000)Q(Q≤100000).

Then comes QQ lines.

1 n x1 x2 x3, ..., xn: means the first type.

2 x l1 r1 y l2 r2: means the second type. xx and yy is the line of the two sequences. [l1,r1][l1,r1], [l2,r2][l2,r2] are the two sub-sequences.

3 x k: means we need the first kk sum of sub-sequence of the x-th sequence in increasing order.

Sum of nn or sum of k \le 1000000k≤1000000.

Each sequence is no longer than 10000001000000.

We granted that every number you read are non-negative.

Output Format

For every query of type 33, print kk number, each number in a single line .

样例输入

1
3
1 5
1 2 3 4 5
3 1 2
3 1 4
样例输出

1
2
1
2
3
3

posted @ 2017-09-16 16:07  besti5332  阅读(509)  评论(0编辑  收藏  举报