0w1

Entries from 2016-07-01 to 1 month

HR Bear and Steady Gene ( Binary Search )

https://www.hackerrank.com/challenges/bear-and-steady-gene I knew it can be solved with crawling, but writing binary search was easier, and worked fine as well. Try removing ( int ) before s.size() in the function ok(), and call ok() with …

HR The Grid Search ( Hashing )

https://www.hackerrank.com/challenges/the-grid-search Somehow solved it with some dirty hashing... Maybe I should get rid of the modInv part, since it was not necessary, and adds a log( MOD ) factor for the hashing. The reason why MOD is 9…

HR Larry's Array ( Math Invariant )

https://www.hackerrank.com/challenges/larrys-array Rotating on any permutation, the number of inversions will have difference by exactly 2. Initially, the correct permutation has no inversion, which means only if the number of inversion is…

Yuki No.387 ハンコ ( Bitset )

No.387 ハンコ - yukicoder bitsetで塗る部分を処理するだけで32倍早くなるあれ。 動的宣言できないんだなbitset。 #include <bits/stdc++.h> using namespace std; typedef vector< int > vi; typedef vector< vi > vvi; const int MAXN = 1e5 + 5; const int MAXCOL = 1e5</bits/stdc++.h>…

CFR 342 E. Xenia and Tree ( LCA + Square Decompostion )

Problem - E - Codeforces 如果對於一個詢問,對所有塗色點取最小距離,複雜度為O( N ),如果對於一個添加所有點的答案,複雜度為O( N )。又只要開始的時候將所有始點押入 queue,囤積複數個始點再更新所有點的答案的複雜度依然為O( N ),可以考慮平方分割。…

CFR 519 E. A and B and Lecture Rooms ( LCA )

Problem - 519E - Codeforces 首先如果 a, b的路徑長為奇數,那麼解為 0。如果 a = b,那麼解為 N。 所以關注路徑長為偶數的情況,顯然要先找到路徑的中點,令它為 c。 為求方便,使 a的深度大於 b。 若 c為 a和 b的祖先,那麼答案是 N - ( c 連接有 a節點的…

CFR 232 C. On Changing Tree ( TimeStamp + Segment Tree )

Problem - C - Codeforces CFR 383 C. Propagating tree ( TimeStamp + Segment Tree ) - 0w1 和這題十分相似。 注意到當操作為 u, x, k的時候,對於任一個 u的子樹的節點 v,其改變的量為 x - k * ( depth[ v ] - depth[ u ] ),其中 depth[ root ] = 0。拆…

CFR 383 C. Propagating tree ( TimeStamp + Segment Tree )

Problem - 383C - Codeforces okuraofvegetableさんの記事を参考にしました ( 2015 木に対する一般的なテク達 ) www.npca.jp 行き戻りの配列がこう役に立つとは知りませんでした。勉強になりました。 #include <bits/stdc++.h> using namespace std; typedef vector< int > </bits/stdc++.h>…