#P7110. Mountain Height Deduction

    ID: 20316 Type: Default 1000ms 256MiB

Mountain Height Deduction

Mountain Height Deduction

In late autumn, admiring the famous view of Cangwu Mountain in country L is a delight. There are ( n ) peaks numbered from (1) to ( n ). Initially, all peaks are shrouded in autumn fog so that their heights are unknown.

A peak ( i ) (with ( 2 \le i \le n-1 )) is called an ( \textbf{intermediate peak} ) if and only if its height equals the average of its two neighbors, i.e.: [ h_i = \frac{h_{i-1} + h_{i+1}}{2} ] At the base of some intermediate peaks, flags are hung (initially, no flags are present).

There are ( m ) days of events. On each day, one of the following occurs:

  • Fog clear/fog return: The autumn fog on the top of mountain ( x ) disappears or reappears.
  • Flag up/flag down: A flag is hung at or taken down from the base of mountain ( x ).
  • Visitor: A mountain enthusiast visits mountain ( x ) and wishes to know its height on that day.

A visitor can determine a mountain’s height in one of two ways:

  1. Directly, if the fog has cleared for that mountain (its height is observed).
  2. Indirectly, by using the information provided by flagged intermediate peaks. In particular, if mountain ( x ) is not directly observed, and if there exist two measured (fog‐free) mountains ( L ) and ( R ) with ( L < x < R ) such that for every mountain ( j ) with ( L < j < R ) that is not measured, the flag is up (thus enforcing ( h_j = \frac{h_{j-1}+h_{j+1}}{2} )), then the height of mountain ( x ) can be deduced uniquely.

Determine for each visitor event whether the height of the target mountain can be deduced.

inputFormat

The first line contains two integers ( n ) and ( m ) representing the number of mountains and the number of events. Each of the next ( m ) lines describes an event in one of the following formats:

clear x
   – The fog on mountain ( x ) clears (its height becomes directly available).

fog x
   – The fog on mountain ( x ) returns (its height becomes unobserved).

flagup x
   – A flag is hung at the base of mountain ( x ) (effective only if ( 1 < x < n )).

flagdown x
   – The flag at mountain ( x ) is removed (effective only if ( 1 < x < n )).

visit x
   – A visitor comes to mountain ( x ) and asks whether its height can be deduced.

outputFormat

For each visit event, output a single line with either YES if the height of the specified mountain can be uniquely determined, or NO otherwise.

sample

5 9
clear 1
clear 5
flagup 2
flagup 3
flagup 4
visit 3
flagdown 3
visit 3
visit 2
YES

NO NO

</p>