#P4620. [SDOI2018] 荣誉称号

    ID: 3558 远端评测题 10000ms 500MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>2018各省省选山东O2优化概率论,统计

[SDOI2018] 荣誉称号

Description

Casual game player QQ has not only achieved excellent results in algorithm contests, but also ranks very high in a diamond-collecting game.

This game has nn different types of diamonds, numbered from 11 to nn. Player QQ has played this game for a long time. For type ii, he has already collected aia_i diamonds. The biggest feature of this game is that there is only one way to obtain diamonds: buying them from the shop. Specifically, the unit price of type ii is bib_i coupons. To encourage players to spend money, there is no quantity limit for any type of diamond: as long as you are willing to pay, you can have as many diamonds as you want. However, the game does not have a “discard item” feature, so QQ cannot discard diamonds to complete the task.

Recently, the game launched a limited-time achievement task. Players who complete it can get an honorary title. The completion condition is:

Given positive integers kk and mm, for any integer x (x2k)x \ (x\ge 2^k), the value
$a_{x}+a_{\lfloor\frac{x}{2}\rfloor}+a_{\lfloor\frac{x}{4}\rfloor}+a_{\lfloor\frac{x}{8}\rfloor}+...+a_{\lfloor\frac{x}{2^k}\rfloor}$
must be a multiple of mm.

Of course, skilled player QQ wants to complete this limited-time achievement task, but before spending money he wants to know how many coupons he needs to complete it. Please write a program to help QQ compute the minimum number of coupons required.

Input Format

The first line contains a positive integer TT, the number of test cases.

For each test case, the first line contains 99 positive integers n,k,m,p,SA,SB,SC,A,Bn, k, m, p, SA, SB, SC, A, B, where nn is the number of diamond types, and k,mk, m are the task conditions.

To reduce the input size to some extent, arrays a[]a[] and b[]b[] are generated by the following code:

unsigned int SA, SB, SC;int p, A, B;
unsigned int rng61(){
	SA ^= SA << 16;
	SA ^= SA >> 5;
	SA ^= SA << 1;
	unsigned int t = SA;
	SA = SB;
	SB = SC;
	SC ^= t ^ SA;
	return SC;
}
void gen(){
	scanf("%d%d%d%d%u%u%u%d%d", &n, &k, &m, &p, &SA, &SB, &SC, &A, &B);
	for(int i = 1; i <= p; i++)scanf("%d%d", &a[i], &b[i]);
	for(int i = p + 1; i <= n; i++){
		a[i] = rng61() % A + 1;
		b[i] = rng61() % B + 1;
	}
}

Output Format

For each test case, output one integer per line, the minimum number of coupons required.

2
3 1 2 3 11111 22222 33333 1 1
1 5
2 3
3 6
7 2 3 7 11111 22222 33333 1 1
6 9
4 5
3 7
5 2
2 4
1 7
9 6
3
14

Hint

  • 1T101 ≤ T ≤ 10.
  • 1k101 ≤ k ≤ 10 and 2kn2^k ≤ n.
  • 1pmin(n,100000)1 ≤ p ≤ min(n, 100000), 10000SA,SB,SC100000010000 ≤ SA, SB, SC ≤ 1000000.
  • 1A,B,ai,bi1071 ≤ A, B, ai, bi ≤ 10^7.

Constraints:

Subtask 1 (3030 points): 1n10001 ≤ n ≤ 1000 and m=2m = 2.

Subtask 2 (4040 points): 1n1051 ≤ n ≤ 10^5 and m200m ≤ 200.

Subtask 3 (3030 points): 1n1071 ≤ n ≤ 10^7 and m200m ≤ 200.

Translated by ChatGPT 5