Official

F - Make them monochrome Editorial by en_translator


Original proposer: ynymxiaolongbao

In fact, the following information can be managed in a segment tree.

  • \(-1\): the segment does not have a determined value, so the segment can be made equal.
  • \(-2\): the segment has two determined values that are different, so the segment cannot be made equal.
  • \(x (\neq -1, \2)\): the segment has an element whose value is determined to \(x\), and no other elements are determined. The segment can be made equal to \(x\).

Type-\(1\) queries can be handled by just setting the given value.
Type-\(2\) queries can be answered No if the prod of the given segment is \(-2\), and Yes otherwise.

For more details, refer to op in the implementation below.

Sample code (C++):

#include<bits/stdc++.h>
#include<atcoder/segtree>

using namespace std;
using namespace atcoder;

const int many=-2;

int e(){return -1;}
int op(int l,int r){
  if(l==-1){return r;}
  if(r==-1){return l;}
  if(l==many || r==many){return many;}
  if(l!=r){return many;}
  return l;
}

int main(){
  int n,q;
  cin >> n >> q;
  vector<int> a(n);
  for(auto &nx : a){cin >> nx;}
  segtree<int,op,e> seg(a);
  while(q--){
    int typ;
    cin >> typ;
    if(typ==1){
      int i,x;
      cin >> i >> x;
      seg.set(i-1,x);
    }
    else{
      int l,r;
      cin >> l >> r;
      if(seg.prod(l-1,r)==many){cout << "No\n";}
      else{cout << "Yes\n";}
    }
  }
  return 0;
}