# CF351D Jeff and Removing Periods Ⅱ(CF351D Jeff and Removing Periods Ⅱ)-其他

## CF351D Jeff and Removing Periods Ⅱ(CF351D Jeff and Removing Periods Ⅱ)

``````void work(int l , int zx){
if(dq[a[zx]].empty()) {
nb[a[zx]] = false;
maxi --;
return ;
}
int now = dq[a[zx]].back();
if(l <= now){
if(nb[a[zx]] == true) maxi --;
nb[a[zx]] = false;
}
if(l > now){
if(nb[a[zx]] == false) maxi ++;
nb[a[zx]] = true;
}
}
``````

Code

————————

See link for the understanding of the topic and the transformation of ideas

Similarly, we only need to preprocess the \ (NXT \) array and \ (del \) array, and then directly maintain them.

Let’s put the most critical function:

``````void work(int l , int zx){
if(dq[a[zx]].empty()) {
nb[a[zx]] = false;
maxi --;
return ;
}
int now = dq[a[zx]].back();
if(l <= now){
if(nb[a[zx]] == true) maxi --;
nb[a[zx]] = false;
}
if(l > now){
if(nb[a[zx]] == false) maxi ++;
nb[a[zx]] = true;
}
}
``````

Here \ (L \) is the left end point of the maintained interval, \ (ZX \) (random variable name) refers to whether the change point is at the head or tail of the queue, \ (DQ \) is a double ended queue for maintaining the value of \ (del \) in the current interval, \ (NB \) is a bucket, which represents whether the color position in the interval forms an equal difference sequence.

Code

However, the code size of Mo team is larger than that of tree array, and the speed is about \ (2S \), so it is not recommended to write Mo team if you want to get tree array.