#P10675. 【MX-S1-T4】先见之明

【MX-S1-T4】先见之明

Background

Original problem link: https://oier.team/problems/S1D

Problem Description

You are given nn non-negative integers a1,a2,,ana_1, a_2, \ldots, a_n。There are qq queries, and for each query:

  • Given a non-negative integer kk, you need to pick some elements (i.e., a subset, which may be empty) from 2a1,,2an2^{a_1}, \ldots, 2^{a_n} such that their sum is k\ge k
  • Under the condition that the sum is k\ge k, you need to minimize the sum. You only need to output this minimized sum.
  • kk is given in binary form. Specifically, it is given in the form k=i=1m2pik = \sum_{i = 1}^{m} 2^{p_i}, and it is guaranteed that all pip_i are non-negative integers and strictly decreasing, i.e., pi>pi+1p_i > p_{i + 1}

Since the answer may be very large, you only need to output the result modulo 998244353998244353

If it is impossible to pick some elements from 2a1,,2an2^{a_1}, \ldots, 2^{a_n} such that their sum is k\ge k, output 1-1 for that query.

Input Format

The first line contains two positive integers n,qn, q

The second line contains nn non-negative integers a1,a2,,ana_1, a_2, \dots, a_n

The next qq lines describe the queries. Each line starts with a non-negative integer mm, followed by mm non-negative integers p1,p2,,pmp_1, p_2, \dots, p_m, representing k=i=1m2pik = \sum_{i = 1}^{m} 2^{p_i}。It is guaranteed that pip_i are strictly decreasing, i.e., pi>pi+1p_i > p_{i+1}

Output Format

Output qq lines. Each line contains one integer, the answer modulo 998244353998244353, or 1-1 if there is no solution.

3 3
0 0 1
0
2 1 0
1 3

0
3
-1

见下发文件。
见下发文件。

Hint

Sample Explanation 1

Each 2ai2^{a_i} is 1,1,21, 1, 2 respectively. The values of kk in the three queries are: 0,3,80, 3, 8. Details:

  • k=0k = 0: choose the empty set.
  • k=3k = 3: choosing 1,21, 2 is enough.
  • k=8k = 8: no solution.

Sample Explanation 2

This sample satisfies the constraints of Subtask 11

Constraints

This problem uses bundled subtasks for judging.

For 100%100\% of the testdata, 1n,q1061 \le n, q \le 10^6, 0m1060 \le m \le 10^6, m5×106\sum m \le 5 \times 10^6, 0ai,pi1060 \le a_i, p_i \le 10^6, and pi>pi+1p_i > p_{i+1}

Blank entries in the table mean there are no additional constraints.

Subtask ID nn \le qq \le m\sum m \le ai,pia_i, p_i \le Special Property Score
11 2020 6060 1010
22 120120
33 5×1035\times 10^3 2.5×1042.5\times 10^4 5×1035\times 10^3 2020
44 10510^5 5×1055\times 10^5 10510^5
55 m2m \le 2 1010
66 All aia_i are distinct.
77 10610^6 5×1065\times 10^6 10610^6 2020

Since the input size is large, we provide fast_read.cpp in the attached files for optional use (note that it may fail to compile under the C++98 standard).

It is guaranteed that the time limit is set to twice that of using standard std input without special input optimizations.

Translated by ChatGPT 5