C. Even Path

f:id:peroon:20200809130954p:plain

int main(){
    // input
    ll N,Q;
    cin>>N>>Q;

    VI A(N);
    rep(i, N){
      cin >> A[i];
      A[i]%=2;
    }

    VI B(N);
    rep(i, N){
      cin >> B[i];
      B[i]%=2;
    }

    // 累積和
    AccSum AccA(A);
    AccSum AccB(B);

    while(Q--){
      ll y0,x0,y1,x1;
      cin>>y0>>x0>>y1>>x1;
      y0--;x0--;
      y1--;x1--;
      if(y0>y1) swap(y0,y1);
      if(x0>x1) swap(x0,x1);

      // 縦条件
      bool vertical_ok;
      if(y0==y1){
        vertical_ok = true;
      }else{
        if(B[x0]==1 && AccA.sum(y0, y1)==y1-y0+1){
          vertical_ok = true;
        }
        else if(B[x0]==0 && AccA.sum(y0, y1)==0){
          vertical_ok = true;
        }
        else{
          vertical_ok = false;
        }
      }

      // 横条件
      bool horizontal_ok;
      if(x0==x1){
        horizontal_ok = true;
      }
      else{
        if(A[y0]==1 && AccB.sum(x0,x1)==x1-x0+1){
          horizontal_ok = true;
        }
        else if(A[y0]==0 && AccB.sum(x0,x1)==0){
          horizontal_ok = true;
        }
        else{
          horizontal_ok = false;
        }
      }
      
      if(vertical_ok && horizontal_ok){
        p_yes();
      }else{
        p_no();
      }
    }
    return 0;
}