Finding sum

Revision en3, by Erisu._.3812, 2023-04-23 04:48:40

The problem is to process Q queries of the form X on N pairs of integers a[i] and b[i] (N, Q <= 2e5 and a[i], b[i] <= 1e6).

Assume there is a pointer initially pointing to a[i] or b[i]. For each query, if the number being pointed to is less than X, the pointer switches between a[i] and b[i]. For each query X, find the sum of the entire N-array based on the value pointed to by the pointer. Calculate the sum of all numbers in all configurations after going through Q queries.

Example input: 5 3

10 20

15 25

5 3

7 12

1 4

5

25

8

Output: 168 Explanation: (10+15+5+7+4) + (20+25+3+12+1) + (20+25+5+12+4)

Tags data structures, help

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en3 English Erisu._.3812 2023-04-23 04:48:40 2 Tiny change: 'n_15 25_\n_5 3_\n\' -> 'n_15 25_\n\n_5 3_\n\'
en2 English Erisu._.3812 2023-04-23 04:48:00 19
en1 English Erisu._.3812 2023-04-23 04:47:23 775 Initial revision (published)