LA 4329: Ping Pong
ACM-ICPC Live Archive 4329: Ping Pong My Problem Version Given N (3 ≤ N ≤ 20000) distinct numbers, a 1 , a 2 , a 3 ... a N , each not more than 100000, how many ways can we select a pair of three numbers, a x , a y , and a z , such that a x < a y < a z and x < y < z? Note: x=1, y=2, z=3 is different from x=2, y=1, z=3. The Algorithm We can take a hint from "... how many ways can we select ..." that this would involve prefix sums. Since we are asked to select the way to make 3 things, we would need to make 3 prefix sum arrays... unless we try to consider the problem from a y 's point of view: the amount of ways to select a number to "its" left and smaller times the number of ways to select a number to "its" right and bigger is the amount of ways to create a pair where "it" is a y . We do this for every possible value of y. Wait a minute... smaller and to its left ... larger and to its right ... isn't