F. Unusual Sum

Codeforces
IDCF10079F
Time1000ms
Memory256MB
Difficulty
English · Original
Formal · Original
Bob is an aspiring archaeologist. He has found n ancient scrolls, each with an unusual sum written on it. The sum on the i-th scroll reads as Bob thinks that precise values of these sums encode the location of Aldoredo, the not-so-famous city of gold. Help him calculate the values of the sums! The first line contains a single integer n, the number of scrolls (1 ≤ n ≤ 105). The i-th of the next n lines contains two space-separated integer numbers li and ri, the description of the sum on the i-th scroll (1 ≤ li ≤ ri ≤ 1018). Output n lines: in the i-th line output the value of the sum written on the i-th scroll. Your answer will be considered correct if its relative or absolute error doesn't exceed 10 - 9. ## Input The first line contains a single integer n, the number of scrolls (1 ≤ n ≤ 105). The i-th of the next n lines contains two space-separated integer numbers li and ri, the description of the sum on the i-th scroll (1 ≤ li ≤ ri ≤ 1018). ## Output Output n lines: in the i-th line output the value of the sum written on the i-th scroll. Your answer will be considered correct if its relative or absolute error doesn't exceed 10 - 9. [samples]
**Definitions** Let $ n \in \mathbb{Z} $ be the number of scrolls. For each scroll $ i \in \{1, \dots, n\} $, let $ l_i, r_i \in \mathbb{Z} $ denote the bounds of the sum, with $ 1 \leq l_i \leq r_i \leq 10^{18} $. **Constraints** 1. $ 1 \leq n \leq 10^5 $ 2. For each $ i \in \{1, \dots, n\} $: $ 1 \leq l_i \leq r_i \leq 10^{18} $ **Objective** For each scroll $ i $, compute the sum: $$ S_i = \sum_{k=l_i}^{r_i} k $$ which simplifies to: $$ S_i = \frac{(r_i - l_i + 1)(l_i + r_i)}{2} $$
API Response (JSON)
{
  "problem": {
    "name": "F. Unusual Sum",
    "description": {
      "content": "Bob is an aspiring archaeologist. He has found n ancient scrolls, each with an unusual sum written on it. The sum on the i-th scroll reads as  Bob thinks that precise values of these sums encode the ",
      "description_type": "Markdown"
    },
    "platform": "Codeforces",
    "limit": {
      "time_limit": 1000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "CF10079F"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "Bob is an aspiring archaeologist. He has found n ancient scrolls, each with an unusual sum written on it. The sum on the i-th scroll reads as \n\nBob thinks that precise values of these sums encode the ...",
      "is_translate": false,
      "language": "English"
    },
    {
      "statement_type": "Markdown",
      "content": "**Definitions**  \nLet $ n \\in \\mathbb{Z} $ be the number of scrolls.  \nFor each scroll $ i \\in \\{1, \\dots, n\\} $, let $ l_i, r_i \\in \\mathbb{Z} $ denote the bounds of the sum, with $ 1 \\leq l_i \\leq r...",
      "is_translate": false,
      "language": "Formal"
    }
  ]
}
Full JSON Raw Segments