G. Magical Indices

Codeforces
IDCF10153G
Time3000ms
Memory256MB
Difficulty
English · Original
Formal · Original
Alaa sometimes feels bored at work, so at such times she starts playing with a beautiful array a consisting of n integers a1, a2, ..., an. Alaa starts counting the number of magical indices in the array a. An index x is said to be magical if it satisfying the following rules: Can you help Alaa by counting the number of magical indices in the array a. The first line contains an integer T, where T is the number of test cases. The first line of each test case contains an integer n (1 ≤ n ≤ 106), where n is the size of the array a. The second line of each test case contains n integers a1, a2, ..., an (1 ≤ ai ≤ 106), giving the array a. For each test case, print a single line containing the number of magical indices in the array a. As input/output can reach huge size it is recommended to use fast input/output methods: for example, prefer to use _scanf/printf_ instead of _cin/cout_ in C++, prefer to use _BufferedReader/PrintWriter_ instead of _Scanner/System.out_ in Java. ## Input The first line contains an integer T, where T is the number of test cases.The first line of each test case contains an integer n (1 ≤ n ≤ 106), where n is the size of the array a.The second line of each test case contains n integers a1, a2, ..., an (1 ≤ ai ≤ 106), giving the array a. ## Output For each test case, print a single line containing the number of magical indices in the array a. [samples] ## Note As input/output can reach huge size it is recommended to use fast input/output methods: for example, prefer to use _scanf/printf_ instead of _cin/cout_ in C++, prefer to use _BufferedReader/PrintWriter_ instead of _Scanner/System.out_ in Java.
**Definitions** Let $ T \in \mathbb{Z} $ be the number of test cases. For each test case $ k \in \{1, \dots, T\} $: - Let $ n_k \in \mathbb{Z} $ denote the size of the array. - Let $ A_k = (a_{k,1}, a_{k,2}, \dots, a_{k,n_k}) $ be the array of integers. **Constraints** 1. $ 1 \le T \le 10^5 $ 2. For each $ k \in \{1, \dots, T\} $: - $ 1 \le n_k \le 10^6 $ - $ 1 \le a_{k,i} \le 10^6 $ for all $ i \in \{1, \dots, n_k\} $ **Objective** For each test case $ k $, count the number of indices $ x \in \{1, \dots, n_k\} $ such that: $$ a_{k,x} = \sum_{\substack{j=1 \\ j \ne x}}^{n_k} a_{k,j} $$
API Response (JSON)
{
  "problem": {
    "name": "G. Magical Indices",
    "description": {
      "content": "Alaa sometimes feels bored at work, so at such times she starts playing with a beautiful array a consisting of n integers a1, a2, ..., an. Alaa starts counting the number of magical indices in the ar",
      "description_type": "Markdown"
    },
    "platform": "Codeforces",
    "limit": {
      "time_limit": 3000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "CF10153G"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "Alaa sometimes feels bored at work, so at such times she starts playing with a beautiful array a consisting of n integers a1, a2, ..., an.\n\nAlaa starts counting the number of magical indices in the ar...",
      "is_translate": false,
      "language": "English"
    },
    {
      "statement_type": "Markdown",
      "content": "**Definitions**  \nLet $ T \\in \\mathbb{Z} $ be the number of test cases.  \nFor each test case $ k \\in \\{1, \\dots, T\\} $:  \n- Let $ n_k \\in \\mathbb{Z} $ denote the size of the array.  \n- Let $ A_k = (a_...",
      "is_translate": false,
      "language": "Formal"
    }
  ]
}
Full JSON Raw Segments