Problem

国王奇遇记加强版之再加强版

Time  Limit:  15  Sec\mathrm{Time\;Limit:\;15\;Sec}
Memory  Limit:  128  MB\mathrm{Memory\;Limit:\;128\;MB}

Description

Input

共一行,包括两个正整数NNMM

Output

共一行,为所求表达式的值对109+710^9+7取模的值。

Read more »

Problem

Solitaire

Time  limit:  2  Sec\mathrm{Time\;limit:\;2\;Sec}
Memory  limit:  256  MB\mathrm{Memory\;limit:\;256\;MB}

Statement

Snuke has decided to play with NN cards and a deque (that is, a double-ended queue). Each card shows an integer from 11 through NN, and the deque is initially empty.
Snuke will insert the cards at the beginning or the end of the deque one at a time, in order from 11 to NN. Then, he will perform the following action NN times: take out the card from the beginning or the end of the deque and eat it.
Afterwards, we will construct an integer sequence by arranging the integers written on the eaten cards, in the order they are eaten. Among the sequences that can be obtained in this way, find the number of the sequences such that the KthK^{th} element is 11. Print the answer modulo 109+710^9+7.

Constraints

1KN20001\le K\le N\le2000

Input

The input is given from Standard Input in the following format:
N  KN\;K

Output

Print the answer modulo 109+710^9+7.

Read more »

Problem

【JLOI2015】有意义的字符串

Time  Limit:  10  Sec\mathrm{Time\;Limit:\;10\;Sec}
Memory  Limit:  128  MB\mathrm{Memory\;Limit:\;128\;MB}

Description

B\mathrm{B君}有两个好朋友,他们叫宁宁和冉冉。
有一天,冉冉遇到了一个有趣的题目:输入b,d,nb,d,n,求

(b+d2)nmod7528443412579576937\lfloor(\frac{b+\sqrt{d}}{2})^n\rfloor\mod{7528443412579576937}

Input

一行三个整数b,d,nb,d,n

Output

一行一个数表示模75284434125795769377528443412579576937之后的结果。

Read more »

Problem

【HNOI2010】城市建设

Time  Limit:  20  Sec\mathrm{Time\;Limit:\;20\;Sec}
Memory  Limit:  162  MB\mathrm{Memory\;Limit:\;162\;MB}

Description

PS\mathrm{PS国}是一个拥有诸多城市的大国,国王Louis\mathrm{Louis}为城市的交通建设可谓绞尽脑汁。Louis\mathrm{Louis}可以在某些城市之间修建道路,在不同的城市之间修建道路需要不同的花费。Louis\mathrm{Louis}希望建造最少的道路使得国内所有的城市连通。但是由于某些因素,城市之间修建道路需要的花费会随着时间而改变,Louis\mathrm{Louis}会不断得到某道路的修建代价改变的消息,他希望每得到一条消息后能立即知道使城市连通的最小花费总和,Louis\mathrm{Louis}决定求助于你来完成这个任务。

Input

第一行三个整数N,M,QN,M,Q,分别表示城市的数目,可以修建的道路个数,收到的消息个数。
接下来MM行,第i+1i+1行有三个用空格隔开的整数Xi,Yi,ZiX_i,Y_i,Z_i1Xi,Yin,0Zi5×1071\le X_i,Y_i\le n, 0\le Z_i\le5\times10^7),表示在城市XiX_i与城市YiY_i之间修建道路的代价为ZiZ_i
接下来QQ行,每行包含两个数k,dk,d,表示输入的第kk个道路的修建代价修改为dd(即将ZkZ_k修改为dd)。

Output

QQ行,第ii行输出得知前ii条消息后使城市连通的最小花费总和。

Read more »

Problem

国王奇遇记

Time  Limit:  10  Sec\mathrm{Time\;Limit:\;10\;Sec}
Memory  Limit:  512  MB\mathrm{Memory\;Limit:\;512\;MB}

Description

Input

共一行,包括两个正整数NNMM

Output

共一行,为所求表达式的值对109+710^9+7取模的值。

Read more »

Problem

国王奇遇记加强版

Time  Limit:  1  Sec\mathrm{Time\;Limit:\;1\;Sec}
Memory  Limit:  512  MB\mathrm{Memory\;Limit:\;512\;MB}

Description

Input

共一行,包括两个正整数NNMM

Output

共一行,为所求表达式的值对109+710^9+7取模的值。

Read more »

Problem

Magic Cards

by Birjik

Description

Birzhan has nn cards, numbered from 11 to nn. Every card has each number from 11 to mm written on it. Some numbers exist on the front side of the card and some on the back side. No number exists on both the sides of a card at the same time. These cards are placed on the table in a row such that only one side is visible. Birzhan is allowed to flip them any number of times.
Now, Birzhan has to answer qq queries each of them consisting of two integers ll and rr (1lrn1\le l\le r\le n). We define f(l,r)f(l,r) as the sum of the squares of every integer from 11 to mm if it exists on the visible side of any card numbered from ll to rr. Given that Birzhan can flip any number of cards any number of times, find and print the maximum value of f(l,r)f(l,r).
For example, given 33 cards and m=5m=5 we have the as follows:-

Now, for l=1l=1 and r=2r=2. We have 1,2,4,51,2,4,5 on the two cards, the sum of their squares is 4646.
If we flip the first card, we get 3,4,53,4,5, the sum of their squares is 5050.
And, if we flip both cards, we get 1,2,3,4,51,2,3,4,5, the sum of their squares is 5555
Hence, the maximum value of f(1,2)f(1,2) in the above case is 5555.

Input Format

The first line contains three space-separated integers, nn, mm, and qq, denoting the number of cards, what numbers written on each card, and the number of queries, respectively.
Each of the next nn lines describes the cards. On each line, the first number is xix_i, denoting the count of numbers written on the visible side of the ithi^{th} card. Next xix_i space-separated unique integers represent the numbers written on the visible side of that card, each between 11 and mm.
Next qq lines contain two space-separated integers, ll and rr, describing the query mentioned above.

Constraints

  • 1n×m,q1061\le n\times m,q\le 10^6
  • 0xim0\le x_i\le m
  • 1lrn1\le l\le r\le n

Output Format

Print the maximum value of f(l,r)f(l,r) for each query.

Read more »

Problem

【TJOI2015】概率论

Time  Limit:  10  Sec\mathrm{Time\;Limit:\;10\;Sec}
Memory  Limit:  128  MB\mathrm{Memory\;Limit:\;128\;MB}

Description

Input

输入一个正整数NN,代表有根树的节点数。

Output

输出这棵树期望的叶子节点数。要求误差小于10910^{-9}

Read more »

Problem

Number Table

Time  Limit:  2  seconds\mathrm{Time\;Limit:\;2\;seconds}
Memory  Limit:  216  megabytes\mathrm{Memory\;Limit:\;216\;megabytes}

Description

As it has been found out recently, all the Berland’s current economical state can be described using a simple table n×mn\times m in size. nn ― the number of days in each Berland month, mm ― the number of months. Thus, a table cell corresponds to a day and a month of the Berland’s year. Each cell will contain either 11, or 1-1, which means the state’s gains in a particular month, on a particular day. 11 corresponds to profits, 1-1 corresponds to losses. It turned out important for successful development to analyze the data on the state of the economy of the previous year, however when the treasurers referred to the archives to retrieve the data, it turned out that the table had been substantially damaged. In some table cells the number values had faded and were impossible to be deciphered. It is known that the number of cells in which the data had been preserved is strictly less than max(n,m)\max(n,m). However, there is additional information ― the product of the numbers in each line and column equaled 1-1. Your task is to find out how many different tables may conform to the preserved data. As the answer to the task can be quite large, you have to find it modulo pp.

Input

The first line contains integers nn and mm (1n,m1000)(1\le n,m\le1000). The second line contains the integer kk (0k<max(n,m))(0\le k<\max(n,m)) ― the number of cells in which the data had been preserved. The next kk lines contain the data on the state of the table in the preserved cells. Each line is of the form a b c, where aa (1an)(1\le a\le n) ― the number of the table row, bb (1bm)(1\le b\le m) ― the number of the column, cc ― the value containing in the cell (11 or 1-1). They are numbered starting from 11. It is guaranteed that no two lines with same aa and bb values exist. The last line contains an integer pp (2p109+7)(2\le p\le10^9+7).

Output

Print the number of different tables that could conform to the preserved data modulo pp.

Read more »