Kadomatsu Subsequence

AtCoder
IDabc439_d
Time2000ms
Memory256MB
Difficulty
You are given an integer sequence $A=(A_1,A_2,\dots,A_N)$ of length $N$. Find the number of triples of integers $(i,j,k)$ that satisfy all of the following: * $1 \le i,j,k \le N$ * $A_i : A_j : A_k = 7:5:3$ * $\min(i,j,k) = j$ or $\max(i,j,k) = j$. ## Constraints * All input values are integers. * $1 \le N \le 3 \times 10^5$ * $1 \le A_i \le 10^9$ ## Input The input is given from Standard Input in the following format: $N$ $A_1$ $A_2$ $\dots$ $A_N$ [samples]
Samples
Input #1
10
3 10 7 10 7 6 7 6 5 14
Output #1
7

The seven triples of integers $(i,j,k)$ that satisfy the conditions are:

*   $(3,9,1)$
    *   $A_i : A_j : A_k = 7:5:3$, and $\max(i,j,k) = j$.
*   $(5,9,1)$
    *   $A_i : A_j : A_k = 7:5:3$, and $\max(i,j,k) = j$.
*   $(7,9,1)$
    *   $A_i : A_j : A_k = 7:5:3$, and $\max(i,j,k) = j$.
*   $(10,2,6)$
    *   $A_i : A_j : A_k = 14:10:6 = 7:5:3$, and $\min(i,j,k) = j$.
*   $(10,2,8)$
    *   $A_i : A_j : A_k = 14:10:6 = 7:5:3$, and $\min(i,j,k) = j$.
*   $(10,4,6)$
    *   $A_i : A_j : A_k = 14:10:6 = 7:5:3$, and $\min(i,j,k) = j$.
*   $(10,4,8)$
    *   $A_i : A_j : A_k = 14:10:6 = 7:5:3$, and $\min(i,j,k) = j$.
Input #2
6
210 210 210 210 210 210
Output #2
0
Input #3
21
49 30 50 21 35 15 21 70 35 9 50 70 21 49 30 50 70 15 9 21 30
Output #3
34
API Response (JSON)
{
  "problem": {
    "name": "Kadomatsu Subsequence",
    "description": {
      "content": "You are given an integer sequence $A=(A_1,A_2,\\dots,A_N)$ of length $N$.   Find the number of triples of integers $(i,j,k)$ that satisfy all of the following: *   $1 \\le i,j,k \\le N$ *   $A_i : A_j :",
      "description_type": "Markdown"
    },
    "platform": "AtCoder",
    "limit": {
      "time_limit": 2000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "abc439_d"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "You are given an integer sequence $A=(A_1,A_2,\\dots,A_N)$ of length $N$.  \nFind the number of triples of integers $(i,j,k)$ that satisfy all of the following:\n\n*   $1 \\le i,j,k \\le N$\n*   $A_i : A_j :...",
      "is_translate": false,
      "language": "English"
    }
  ]
}
Full JSON Raw Segments