| # | User | Rating |
|---|---|---|
| 1 | jiangly | 3810 |
| 2 | Benq | 3676 |
| 3 | Kevin114514 | 3655 |
| 4 | maroonrk | 3463 |
| 5 | strapple | 3447 |
| 6 | Um_nik | 3387 |
| 7 | heuristica | 3322 |
| 8 | turmax | 3317 |
| 9 | tourist | 3307 |
| 10 | jiangbowen | 3291 |
| # | User | Contrib. |
|---|---|---|
| 1 | Qingyu | 156 |
| 2 | nik_exists | 150 |
| 2 | maspy | 150 |
| 4 | Um_nik | 141 |
| 5 | Errichto | 139 |
| 6 | adamant | 137 |
| 7 | AmShZ | 135 |
| 8 | BledDest | 132 |
| 9 | maroonrk | 131 |
| 10 | qwexd | 129 |
| Name |
|---|



I can`t understend why answer is "1 2 3".
1 because {1}={2}, 2 because {3,1}={10,1}, and what is 3?
UPD. understood
3 because {1,2} = {4,5}
Maybe in KMP:
a[0]...a[i]...a[j]...a[k]a[0]...a[i]==a[j]...a[k]ifa[0]...a[i-1]==a[j]...a[k-1]anda[i]==a[k].a[i]==a[k]if and only if count of numbers which greather thena[i]ina[0]..a[i-1]is equal to count of numbers which greather thena[k]ina[j]..a[k-1].We can use the struct like segment tree, which help us get this count in
O(log(400000))(just +1 toa[i]when we add numbera[i]ans -1 else). If we getsuffix(a[j]..a[k-1])we don't forget to decrease all values which don't include to this suffix (it'sa[j]..a[h], ifa[j]..a[k-1]=a[j]..a[h]a[h+1]..a[k-1]). And first we should decrease all numbers as it possibly in any sequence because numbers are in the range1..2^32(then we can use a segment tree).I don't know is it correct solution, but maybe.
Yes, I did something like that for POJ 3167, using a BIT. But in that problem we only need to match one pattern. In SPOJ UNTITLED you need to match many patterns.
read the solution to ceoi 2011 Matching
Since the original problem is solved using KMP, and now we have multiple patterns, naturally we should solve this problem using the generalization of KMP to multiple strings, which is Aho–Corasick.
When constructing the automaton, you need to be able to answer the following query for each element in each pattern: what is its rank compared with all preceding elements in the same pattern? This is easy, you just use a BIT. These ranks label the child edges in the automaton. When computing the suffix arcs, and when matching the text, you need to be able to answer the following query: for a given node in the automaton, what child edge (if any) is labelled by the rank that that equals the rank of the current text element compared with the correspondingly long substring of the text preceding it? You can do this by computing the latter explicitly (I guess you'd use a persistent segment tree or something like that) but the faster way, I assume, is to use binary search with the trick from CEOI 2011 Matching where you have to precompute (for each pattern) tables that give, for each element, the index of the largest preceding element less than it and the smallest preceding element greater than it.