Unique Subsequence

AtCoder
IDarc125_d
Time2000ms
Memory256MB
Difficulty
Given is a sequence of $N$ integers $A_1,A_2,\cdots,A_N$. Find the number of non-empty subsequences $s$ of $A$ satisfying the following condition, modulo $998244353$. * There is only one way to extract $s$ from $A$. Formally, there uniquely exists a sequence of indices $1 \leq idx(1)<idx(2)<\cdots<idx(k) \leq N$ such that $A_{idx(i)}=s_i$ ($1 \leq i \leq k$), where $s=(s_1,s_2,\cdots,s_k)$. ## Constraints * $1 \leq N \leq 2 \times 10^5$ * $1 \leq A_i \leq N$ * All values in input are integers. ## Input Input is given from Standard Input in the following format: $N$ $A_1$ $A_2$ $\cdots$ $A_N$ [samples]
Samples
Input #1
3
1 2 1
Output #1
5

The following five subsequences satisfy the condition.

*   $(1,1)$
*   $(1,2)$
*   $(1,2,1)$
*   $(2)$
*   $(2,1)$

The subsequence $(1)$ does not satisfy the condition since there are two ways to extract it.
Input #2
4
4 2 1 3
Output #2
15
Input #3
12
1 2 3 6 9 2 3 3 9 6 1 6
Output #3
1178
API Response (JSON)
{
  "problem": {
    "name": "Unique Subsequence",
    "description": {
      "content": "Given is a sequence of $N$ integers $A_1,A_2,\\cdots,A_N$. Find the number of non-empty subsequences $s$ of $A$ satisfying the following condition, modulo $998244353$. *   There is only one way to ext",
      "description_type": "Markdown"
    },
    "platform": "AtCoder",
    "limit": {
      "time_limit": 2000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "arc125_d"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "Given is a sequence of $N$ integers $A_1,A_2,\\cdots,A_N$.\nFind the number of non-empty subsequences $s$ of $A$ satisfying the following condition, modulo $998244353$.\n\n*   There is only one way to ext...",
      "is_translate": false,
      "language": "English"
    }
  ]
}
Full JSON Raw Segments