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}]}}$
Long Sandwich - Codechef SANDWICH
It has two parts to this problem. You are given $n$ and $k$. You have to tell the minimum number of pieces, $a$, you can cut a sandwich of length $n$ such that the length of no piece is greater than $k$.
The answer is quite simple, isn’t it ?
Answer of the first part click to hide $a = \lceil \frac{n}{k} \rceil$ The second part is, how many ways we can cut the sandwich into $a$ pieces such that the length of no piece is greater than $k$.