NOI '22 P6 - Quadratic Integer Program

View as PDF

Submit solution

Points: 40 (partial)
Time limit: 2.0s
Memory limit: 1G

Problem type
Task description

In this problem, you need to solve a well-known NP problem - the quadratic integer programming problem.

Quadratic integer programming problems have variables: you need to give a length n sequence of integers (x[1],x[2],,x[n]) that satisfies all the conditions below.

Quadratic integer programming problems have constraints: the sequence of integers you give needs to satisfy the following two types of constraints:

  1. Given a positive integer k (3k5) and n intervals [l[i],r[i]] (1in), where 1l[i]r[i]k , the sequence you give needs to satisfy l[i]x[i]r[i] for all 1in.
  2. Given m triples (p[j],q[j],b[j]), the sequence you give needs to satisfy |x[p[j]]x[q[j]]|b[j] for all 1jm.

The quadratic integer programming problem has an objective function: you are given given k2 weight parameters v[2],v[3],,v[k1] (note that the indices are from 2 to k1). Let c[i] be the number of elements in the sequence whose value is i, and G be the number of pairs 1i,jn such that |p[i]p[j]|1 (note that when ij, (i,j) and (j,i) are not the same). The weight of a sequence x[1],x[2],,x[n] is:

W(x[1],x[2],,x[n])=106G+i=2k1c[i]v[i]

Your sequence needs to maximize its weight while satisfying the above two constraints.

Quadratic integer programming problems do not necessarily require multiple queries, but we will give q queries, each query giving different weight parameters v[2],v[3],,v[k1]. For each query, you need find a sequence of maximum weight that satisfies the constraints. To reduce the output, you only need to output the weight of this sequence. The data guarantees that at least one sequence that satisfies the above conditions exists.

Input Specification

There are multiple sets of test data for this question. The first line contains a non-negative integer C and a positive integer T, which represent the test case number and the number of data sets, respectively. C=0 indicates that this set of data is a sample.

For each test case:

  • The first row contains four integers k,n,m,q, describing the sequence range, sequence length, the number of constraints between variables, and the number of queries.
  • The next n lines each contain two integers l[i], r[i], describing the value range corresponding to each element in the sequence.
  • The next m lines contain three integers p[j], q[j], b[j] each, describing the constraints between a pair of variable.
  • Each of the next q lines contains k2 non-negative integers v[2],v[3],,v[k1] describing a set of query weight parameters.

Output Specification

For each set of queries for each set of data, output a row of integers representing the maximum weight of the sequence.

Samples

Sample inputs and outputs can be found here.

Sample 1

See qip/qip1.in and qip/qip1.ans in the player directory. This example satisfies the properties of test point 1 in the data range.

Explanation of Sample 1

In the first test data, the optimal sequences corresponding to the two sets of queries are (1, 2, 2, 1, 3), with c2 = 2, G = 21.

Example 2

See qip/qip2.in and qip/qip2.ans in the player directory.

This example satisfies the properties of test point 3 in the data range.

Explanation of Sample 2

An optimal sequence corresponding to the two sets of queries in the first test data is (4, 4, 3, 3) and (4, 3, 2, 2), respectively.

Sample 3

See qip/qip3.in and qip/qip3.ans in the player directory. This example satisfies the properties of test point 5 in the data range.

Explanation of Sample 3

An optimal sequence corresponding to the three groups of queries in the first test data is (3, 3, 3, 3, 3), (2, 2, 3, 3, 2) and (3, 2, 4, 4, 2).

Sample 4

See qip/qip4.in and qip/qip4.ans in the player directory. This sample satisfies the properties of test point 2 in the data range.

Sample 5

See qip/qip5.in and qip/qip5.ans in the player directory. This sample satisfies the properties of test point 4 in the data range.

Sample 6

See qip/qip6.in and qip/qip6.ans in the player directory. This sample satisfies the properties of test point 8 in the data range.

Sample 7

See qip/qip7.in and qip/qip7.ans in the player directory. This sample satisfies the properties of test point 14 in the data range.

Sample 8

See qip/qip8.in and qip/qip8.ans in the player directory. This sample satisfies the properties of test point 17 in the data range.

Subtasks

Assume \sum q is the sum of q of all test data in a single test point. For all test points,

  • 1T600,
  • In the i(1iT) th test data, 1nmax(T/i,2log2T),
  • 3k5, 0m3n, 1q,q3×105,
  • 1l[i]r[i]k,
  • 1p[j],q[j]n, 0b[j]<k,
  • 0v[2],,v[k1]1012.
CaseTk=qSpecial PropertyPoints
1103200None4
26003×1056
31042004
46003×1056
51053005
6155004
7257504
85010006
98015006
1012020005
112008000A3
124003×1044
136002×1055
142008000B3
154003×1044
166002×1054
17120105C4
181502×1055
191803×1055
203005×104None5
214501054
226003×1054
  • Special property A: m=0.
  • Special property B: m10, the sum of m of all test data in a single test point does not exceed 200.
  • Special property C: The data is randomly generated. Specifically, when generating each set of test data in the test point, the parameters k, n, m, q and k non-negative integers p[0], p[1],p[2],,p[k1] are given to ensure that p[k1]0, then the following rules are used to generate this data:
  • For 1in, independent uniform random generation of x,y[1,k], then l[i]=min(x,y),r[i]=max(x,y);
  • Keep generating triples as follows until there are m triples:
    • Independently and uniformly randomly generate u,v[1,n];
    • Randomly generate w with p as weight (for 0ik1, w=i with probability p[i]p[0]+p[1]+...+p[k1] );
    • If there is no sequence (x[1],x[2],,x[n]) after adding (u,v,w) to the original triple set, the current triple is discarded, otherwise the current triple is added.
  • v[2],,v[k1] of each set of queries are independently and uniformly generated randomly within [0,1012].

Comments

There are no comments at the moment.