Does anybody know if there will be a tutorial for abbyy finals? If there is not going to be a tutorial soon, please give me some hints for tasks A,B,C. THANKS A LOT!!!
# | User | Rating |
---|---|---|
1 | tourist | 4009 |
2 | jiangly | 3831 |
3 | Radewoosh | 3646 |
4 | jqdai0815 | 3620 |
4 | Benq | 3620 |
6 | orzdevinwang | 3529 |
7 | ecnerwala | 3446 |
8 | Um_nik | 3396 |
9 | gamegame | 3386 |
10 | ksun48 | 3373 |
# | User | Contrib. |
---|---|---|
1 | cry | 164 |
1 | maomao90 | 164 |
3 | Um_nik | 163 |
4 | atcoder_official | 160 |
5 | -is-this-fft- | 158 |
6 | awoo | 157 |
7 | adamant | 156 |
8 | TheScrasse | 154 |
8 | nor | 154 |
10 | Dominater069 | 153 |
Name |
---|
A is more or less greedy: If you have a pair of equally appealing trees at positions i and j and you want to keep them as the outermost trees, you need to delete all trees at positions < i and > j. Also, you remove all the trees in between that have a negative appeal. The total remaining sum of appeals will be f(i, j) = psum[j - 1] - psum[i] + a[i] + a[j] where psum[k] is the sum of positive appeals in the range 0..k (it can be precomputed upfront). This is the maximum possible appeal if you decide to use i and j as the outermost trees.
Now how to find the pair (i, j) that maximizes f(i, j)? We can enumerate j and always use the leftmost i with a[i] = a[j]. Why? Because f(i, j) = 2·a[j] + psum[j - 1] - psum[i], so f is monotonically decreasing when i increases. We can use a
map<int,int> pos
so that pos[x] is the leftmost i such that a[i] = x. Then we can just iterate over the array a, checking pos[a[j]] for every position j and then updating pos with the value a[j]. The maximum over all iterations is the total maximum.Run time: or expected O(n) with a hash table. Code: 4099310
B: Let pos[i] be the position of the beaver i in the current permutation. For x > 1, let x[i] = 1 if pos[i] < pos[i - 1] and x[i] = 0 otherwise. Let a(l, r) be the result of a query of type 1. Intuitively, we get , where psum(k) is the prefix sum of x up to and including index k. We can use a binary indexed tree to store x, so that we can compute psum(k) fast.
Now for every swap, at most 4 different values of x can change, so we only need a constant number of updates of our data structure per swap. This results in a total complexity of .
Code: 4099288
C: I only solved C1, using DP with a straightforward recurrence: f(0) = 0 and f(x) = minD(x)f(x - d) (where D(x) is the set of digits of x)
Code: 4099317
B: When you change values of x, what do you do to the index tree?
You "set" the value. I just saved the array
x
explicitely and added 1 or -1 if a value changed (see theupdate
function in my code).The editorial is published now: here, but it's too short. I'd say the niklasb's explanations of A and B are much better than that.