Official
F - Make them monochrome Editorial
by
F - Make them monochrome Editorial
by
physics0523
Editorial for printing
原案: ynymxiaolongbao
実は、以下の情報を segment tree で管理することができます。
- \(-1\) … 区間内に値が確定している要素が存在しない。任意の正整数を選択し、その整数に区間全体を揃えることができる。
- \(-2\) … 区間内に異なる値が確定している \(2\) つの要素が存在するため、区間全体を同じ値に揃えることはできない。
- \(x (\neq -1,-2)\) … 区間に値が \(x\) であると確定している要素が存在し、 \(x\) 以外の値が確定している要素が存在しない。区間全体を \(x\) に揃えることはできる。
タイプ \(1\) のクエリに対しては入力をそのままそこに set すればよいです。
タイプ \(2\) のクエリに対しては、区間全体の情報の prod を計算した結果 \(-2\) であれば答えは No 、そうでなければ答えは Yes です。
詳しい計算の方法は実装例内 op も参照してください。
実装例 (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;
}
posted:
last update:
