Under construction

Still being built. Things may change

Streetlights

Time limit2sMemory limit1024 MB

Summary
Maintain a binary string under range set-to-0 and set-to-1 operations, and after each report how many substrings have ever been all ones at some point in time.
Level

Hard8 of 10

Topics
Segment tree, Intervals, Implementation, Math
Solved
No attempts yet

Problem

The Underwater Canal street is lit by nn streetlights, numbered 1 to nn along the street. A segment is one or more streetlights that stand consecutively. Thus the total number of segments is n(n+1)2\frac{n(n+1)}{2}. A segment is healthy if the bulbs in all of its streetlights are working.

Events of one of two types happen to the streetlights regularly:

  • in some segment, a voltage surge burns out all the bulbs at once;
  • Arkhenergo picks some segment and sends repair crews to replace every burnt-out bulb in it with a working one.

After each event, the city hall demands that Arkhenergo report the number of healthy segments. To make their performance look better, the repair crews include in the report every segment that is healthy now or was ever healthy before.

Write a program that determines, after each event, the number of segments that are healthy at that moment or were healthy at any time before that event.

Input

The first line of the input contains two numbers nn and qq, the number of streetlights and the number of events that happened. The next line of the input consists of nn characters 0 and 1 describing the initial state of the streetlights, where 1 denotes a streetlight with a working bulb and 0 denotes one with a burnt-out bulb.

Each of the following qq lines contains a description of an event as three numbers li,ril_i, r_i, and cic_i, which mean that after this event all bulbs in the streetlights numbered li,li+1,…,ril_i, l_i+1, \ldots, r_i:

  • burn out if ci=0c_i = 0,
  • become working if ci=1c_i = 1.

In the descriptions of all events 1≤li≤ri≤n1 \le l_i \le r_i \le n, and cic_i takes the value 00 or 11.

Output

In the first line of the output, print a single number: the number of healthy segments in the initial state. Then print qq numbers, one per line: for each event that happened, print the number of segments listed in the report after that event.

Constraints

  • 1≤n≤300 0001 \le n \le 300\,000
  • 1≤q≤300 0001 \le q \le 300\,000

Examples1

  1. Example 1

    Input
    7 4
    1100101
    4 6 1
    3 6 0
    3 4 1
    5 7 1
    
    Expected output
    5
    13
    13
    19
    28