kawatea's solution http://codeforces.me/contest/246/submission/2621642 i think it's brute force because this solution uesd a "for" loop to find distinct names of k sons
kawatea's solution http://codeforces.me/contest/246/submission/2621642 i think it's brute force because this solution uesd a "for" loop to find distinct names of k sons
| # | User | Rating |
|---|---|---|
| 1 | Benq | 3676 |
| 2 | jiangly | 3670 |
| 3 | Kevin114514 | 3657 |
| 4 | maroonrk | 3355 |
| 5 | Um_nik | 3353 |
| 6 | squareOf105 | 3346 |
| 7 | tourist | 3343 |
| 8 | strapple | 3324 |
| 9 | heuristica | 3322 |
| 10 | jiangbowen | 3291 |
| # | User | Contrib. |
|---|---|---|
| 1 | Qingyu | 158 |
| 2 | nik_exists | 150 |
| 2 | maspy | 150 |
| 4 | AmShZ | 144 |
| 5 | Um_nik | 141 |
| 6 | Errichto | 139 |
| 7 | adamant | 137 |
| 8 | BledDest | 134 |
| 9 | maroonrk | 133 |
| 10 | qwexd | 130 |
| Name |
|---|



It caches every query. It seems that there could not be many distinct large queries.
for (i = p; i < q; i++) { if (f[w[z][i].second] == 0) { sum++; f[w[z][i].second] = 1; } }In the worst case this part works (summary) in
.
Sample:
K+M -> K+M-1 -> K+M-2 -> .... KK -> 1,2,3, ..., K-1K+1 -> some chain of length 1K+2 -> some chain of length 2...K+M -> some chain of length MProve:
Each
times. To view it k times, we should ask about layer
.
w[z][i]will be viewed at mostzfrom k different ancestors ofw[z][i]. How to get k different pairs <p,q>? For each of these k ancestors we have to add a chain from it to layerz. Lengths of these chains will be at least 1,2, ... k. Sum is at most n. So k is at most