Screen Saver

Time limit2sMemory limit128 MB

Summary
Given a piecewise linear floor and a water level, update floor heights or the level and report the submerged area to three decimals.
Level

Medium6 of 10

Topics
Geometry, Segment tree, Implementation
Solved
No attempts yet

Problem

Sang-geun installed a new screen saver. When the computer is left idle for 55 minutes, the screen saver starts and shows an aquarium with fish swimming inside it. On the settings screen you can change the shape of the aquarium floor and the height of the water surface.

The aquarium is drawn as a 2D plane of width N−1N-1. The leftmost xx-coordinate is 00 and the rightmost is N−1N-1, and every integer xx-coordinate ii has a floor height HiH_i. The floor consists of, for each pair of adjacent coordinates ii and i+1i+1, the line segment joining the points (i,Hi)(i, H_i) and (i+1,Hi+1)(i+1, H_{i+1}).

If the water surface is at height hh, all of the space between the floor and the line y=hy = h is filled with water. Any part of the floor that rises above hh becomes an island that is not submerged.

Every time Sang-geun changes a floor height or the water surface height, he wants to know the area of the region currently filled with water.

Input

The first line contains two positive integers NN and MM, where MM is the number of changes Sang-geun makes. (3≤N≤100,0003 \le N \le 100{,}000, 1≤M≤100,0001 \le M \le 100{,}000)

The second line contains the initial floor heights H0,H1,…,HN−1H_0, H_1, \dots, H_{N-1}, separated by spaces. (0≤Hi≤10000 \le H_i \le 1000)

Each of the next MM lines describes one change, in one of the following two forms.

  • Q h : set the water surface height to hh. (0≤h≤10000 \le h \le 1000)
  • U i h : set the floor height at xx-coordinate ii to hh, i.e. Hi=hH_i = h. (0≤i≤N−10 \le i \le N-1, 0≤h≤10000 \le h \le 1000)

Output

For every change that begins with Q, print the area of the region filled with water at that moment, to three decimal places.

Examples3

  1. Example 1

    Input
    3 2
    20 20 20
    Q 20
    Q 30
    
    Expected output
    0.000
    20.000
    
  2. Example 2

    Input
    3 5
    0 2 0
    Q 2
    U 1 1
    Q 1
    U 1 10
    Q 5
    
    Expected output
    2.000
    1.000
    2.500
    
  3. Example 3

    Input
    7 7
    0 2 1 3 2 1 0
    Q 1
    Q 2
    Q 3
    U 3 0
    Q 1
    Q 2
    Q 3
    
    Expected output
    0.750
    3.750
    9.000
    1.500
    6.000
    12.000