Question 1:
https://codeforces.com/problemset/problem/698/A
Question 2:
There is a number space given from 1 to N. And there are M queries followed by that. In each query, we were given a number between 1 to N (both inclusive). We add these numbers one by one into a set.
Allowed range: A range in which there is exactly one element present from the set.
For each query, we need to find the Allowed ranges. We need to return the sum of the boundary of all the Allowed ranges.
Input:
First-line will take two integers for input N and M.
Then following M lines would be numbers between 1 and N (both inclusive).
Output:
Following M lines contain the sum of boundaries of Allowed ranges.
Note:
Allowed Range can consist of a single element and is represented as (x-y) where boundary sum will be x+y.
Example:
Input:
10 4
2
5
7
9
Output:
11
18
30
46
Explaination:
For query 1: 2
set<2>
allowed ranges: <1, 10> since set has only element and range containing 2 is 1 to 10
ans = sum of allowed ranges: 11
For query 2: 5
set<2, 5>
allowed ranges: <<1, 4>, <3, 10>>
ans = sum of allowed ranges: 18
For query 3: 7
set<2, 5, 7>
allowed ranges: <<1, 4>, <3, 6>, <6, 10>>
ans = sum of allowed ranges: 30
For query 4: 9
set<2, 5, 7, 9>
allowed ranges: <<1, 4>, <3, 6>, <6, 8>, <8, 10>>
ans = sum of allowed ranges: 46