The Multiplayer Action Game - Toph

You are given two n-sphere, centered at C1, C2 and having a radius of R1, R2 respectively The velocity vector of the two n-sphere is V1, V2 respectively. Find the minimum time, when the smaller n-sphere will be fully inside of the bigger one. If it is impossible/minimum time is greater than 100000, then print -1. Constraints click to hide There will be atmost $10^{5}$ testcases.
Read more →

Unnamed Trick 1

Prerequisite Task 1: You are given two array $A$ and $B$ of length $n$. For each $j$ ($0\le j \le n-1$) print $\sum_{i=0}^{j-1}{[A_{i}=B_{j}]}$ In other words, for each $j$($0\le j \le n-1$) print number of index $i$(i<j) where $B_j=A_i$ Constraints click to hide $1\le n \le 10^{5}$ $-10^{9} \le A_{i},B_{i} \le 10^{9}$ cpp map<int, int> cnt; for (int j = 0; j < n; j++) { cout << cnt[B[j]] << '\n'; cnt[A[j]]++; } Prerequisite Task 2: Same as task 1, just find $\sum_{j=0}^{n-1}{\sum_{i=0}^{j-1}{[A_{i}=B_{j}]}}$
Read more →

AtCoder ABC-032 C

Given an array $S$ of length $n$ and an integer $k$. Find maximum value of $(r-l+1)$ such that $\prod_{i=l}^{r}{S_{i}} \le k$ Constraints click to hide $1\le n \le 10^{5}$ $0\le k \le 10^{9}$ $0\le S_{i} \le 10^{9}$ Bruteforce Solution $O(n^2)$: If any value of $S$ is $0$ then the answer is $n$ We call a segment $[l,r]$ valid if $\prod_{i=l}^{r}{S_{i}} \le k$
Read more →

Hashing 2 - Double Hash

If you don’t read this blog or solved Kattis - inversefactorial on your own, complete these two tasks at first. In our previous part, we take m=1000000009 in our solution. But if we take m=1000000011 or m=1000000125 what would happen? If you are using these/some random values and getting WA, you are on the right track. In our previous solution, we mapped every big value $p$ with some small value $H(p)$.
Read more →

Hashing 1 : Inverse Factorial - Kattis inversefactorial

$$f(n)=n!$$ Given a value $x$ , find $f^{-1}{(x)}$ [that is, such $n$ so that $f(n)=x$]. Constraints click to hide number of digit in $x$ is atmost $10^{6}$ Solution: At first, this problem seems too hard. Suppose, we have a bijective function $H(p)$ which return some small integer value for corresponding $p$. Hence, we can uniquely represent every $p$ by $H(p)$. How to make $H(p)$ click to hide $H(p) = p \text{ (mod $m$)}$ [for a choosen $m$]
Read more →