BLSUMSEQ - Sum of subsequences
Given an positive integer n and a sequence a1 ... an. There are q queries. Each query has one of two formats:
- Format 0 l r k: you need to output the k-th smallest positive integer that can’t be partition into a sum of any subsequence of al ... ar.
- Format 1 l r x: you need to output the numbers of ways to partition x into a sum of a subseqence of al ... ar (or the numbers of subsequence that sum of all its elements equal to x) (modulo 232).
Input
- First line: two positive n and q (1 ≤ n ≤ 100, 1 ≤ q ≤ 10000)
- Second line: n positive a1…an (0 ≤ ai ≤ 100)
- Next q lines: each line denotes a query with one of two format listed above (1 ≤ l ≤ r ≤ n, 1 ≤ k ≤ 109, 0 ≤ x ≤ 109)
Output
- q lines: the i-th line is the answer of i-th query.
Sample
Input: 5 3 1 0 2 4 1 0 2 3 2 1 1 4 0 1 2 5 3 Output: 3 1 2
hide comments
Jacob Plachta:
2014-04-11 23:54:22
I should note that the current data can be used without changes if, for Format 1 queries, the problem statement simply asks for the number of ways modulo 2^32.
|
|
Jacob Plachta:
2014-04-11 23:54:22
That's just fantastic... After wasting a very large amount of time, I discovered that the outputs *do* still overflow. If I use long longs, I find that the outputs exceed 2^32, and I get WA if I output them correctly - but if I use unsigned ints and pay no attention to overflow, I get AC. I expected that this wouldn't be the case after it was already pointed out that outputs were overflowing, and it was promised that they were fixed, but apparently not. |
|
Min_25:
2014-04-11 23:54:22
Does "k-th smallest positive integer" (in Format 0 l r k) mean "k-th smallest nonnegative integer" ?
|
|
Jacob Plachta:
2014-04-11 23:54:22
I assume that subsequences in this problem don't have to be contiguous, but they need to be non-empty? For example, is this input/output correct?
|
|
Min_25:
2014-04-11 23:54:22
I think my code(ID: 11284271) is correct.
|
Added by: | Kata |
Date: | 2014-03-12 |
Time limit: | 1s |
Source limit: | 50000B |
Memory limit: | 1536MB |
Cluster: | Cube (Intel G860) |
Languages: | All except: ASM64 |
Resource: | Own problem |