package fl;

import java.util.Arrays;

/* loaded from: classes3.dex */
public final class b implements Cloneable {

    /* renamed from: p, reason: collision with root package name */
    private final int f18550p;

    /* renamed from: q, reason: collision with root package name */
    private final int f18551q;

    /* renamed from: r, reason: collision with root package name */
    private final int f18552r;

    /* renamed from: s, reason: collision with root package name */
    private final int[] f18553s;

    public b(int i10) {
        this(i10, i10);
    }

    private String a(String str, String str2, String str3) {
        StringBuilder sb2 = new StringBuilder(this.f18551q * (this.f18550p + 1));
        for (int i10 = 0; i10 < this.f18551q; i10++) {
            for (int i11 = 0; i11 < this.f18550p; i11++) {
                sb2.append(f(i11, i10) ? str : str2);
            }
            sb2.append(str3);
        }
        return sb2.toString();
    }

    public void b() {
        int length = this.f18553s.length;
        for (int i10 = 0; i10 < length; i10++) {
            this.f18553s[i10] = 0;
        }
    }

    /* renamed from: c, reason: merged with bridge method [inline-methods] */
    public b clone() {
        return new b(this.f18550p, this.f18551q, this.f18552r, (int[]) this.f18553s.clone());
    }

    public void d(int i10, int i11) {
        int i12 = (i11 * this.f18552r) + (i10 / 32);
        int[] iArr = this.f18553s;
        iArr[i12] = (1 << (i10 & 31)) ^ iArr[i12];
    }

    public boolean equals(Object obj) {
        if (!(obj instanceof b)) {
            return false;
        }
        b bVar = (b) obj;
        return this.f18550p == bVar.f18550p && this.f18551q == bVar.f18551q && this.f18552r == bVar.f18552r && Arrays.equals(this.f18553s, bVar.f18553s);
    }

    public boolean f(int i10, int i11) {
        return ((this.f18553s[(i11 * this.f18552r) + (i10 / 32)] >>> (i10 & 31)) & 1) != 0;
    }

    public int[] h() {
        int length = this.f18553s.length - 1;
        while (length >= 0 && this.f18553s[length] == 0) {
            length--;
        }
        if (length < 0) {
            return null;
        }
        int i10 = this.f18552r;
        int i11 = length / i10;
        int i12 = (length % i10) << 5;
        int i13 = this.f18553s[length];
        int i14 = 31;
        while ((i13 >>> i14) == 0) {
            i14--;
        }
        return new int[]{i12 + i14, i11};
    }

    public int hashCode() {
        int i10 = this.f18550p;
        return (((((((i10 * 31) + i10) * 31) + this.f18551q) * 31) + this.f18552r) * 31) + Arrays.hashCode(this.f18553s);
    }

    public int[] i() {
        int i10 = this.f18550p;
        int i11 = this.f18551q;
        int i12 = -1;
        int i13 = -1;
        for (int i14 = 0; i14 < this.f18551q; i14++) {
            int i15 = 0;
            while (true) {
                int i16 = this.f18552r;
                if (i15 < i16) {
                    int i17 = this.f18553s[(i16 * i14) + i15];
                    if (i17 != 0) {
                        if (i14 < i11) {
                            i11 = i14;
                        }
                        if (i14 > i13) {
                            i13 = i14;
                        }
                        int i18 = i15 << 5;
                        if (i18 < i10) {
                            int i19 = 0;
                            while ((i17 << (31 - i19)) == 0) {
                                i19++;
                            }
                            int i20 = i19 + i18;
                            if (i20 < i10) {
                                i10 = i20;
                            }
                        }
                        if (i18 + 31 > i12) {
                            int i21 = 31;
                            while ((i17 >>> i21) == 0) {
                                i21--;
                            }
                            int i22 = i18 + i21;
                            if (i22 > i12) {
                                i12 = i22;
                            }
                        }
                    }
                    i15++;
                }
            }
        }
        if (i12 < i10 || i13 < i11) {
            return null;
        }
        return new int[]{i10, i11, (i12 - i10) + 1, (i13 - i11) + 1};
    }

    public int j() {
        return this.f18551q;
    }

    public a k(int i10, a aVar) {
        if (aVar == null || aVar.n() < this.f18550p) {
            aVar = new a(this.f18550p);
        } else {
            aVar.d();
        }
        int i11 = i10 * this.f18552r;
        for (int i12 = 0; i12 < this.f18552r; i12++) {
            aVar.u(i12 << 5, this.f18553s[i11 + i12]);
        }
        return aVar;
    }

    public int[] l() {
        int[] iArr;
        int i10 = 0;
        int i11 = 0;
        while (true) {
            iArr = this.f18553s;
            if (i11 >= iArr.length || iArr[i11] != 0) {
                break;
            }
            i11++;
        }
        if (i11 == iArr.length) {
            return null;
        }
        int i12 = this.f18552r;
        int i13 = i11 / i12;
        int i14 = (i11 % i12) << 5;
        while ((iArr[i11] << (31 - i10)) == 0) {
            i10++;
        }
        return new int[]{i14 + i10, i13};
    }

    public int n() {
        return this.f18550p;
    }

    public void o() {
        a aVar = new a(this.f18550p);
        a aVar2 = new a(this.f18550p);
        int i10 = (this.f18551q + 1) / 2;
        for (int i11 = 0; i11 < i10; i11++) {
            aVar = k(i11, aVar);
            int i12 = (this.f18551q - 1) - i11;
            aVar2 = k(i12, aVar2);
            aVar.s();
            aVar2.s();
            s(i11, aVar2);
            s(i12, aVar);
        }
    }

    public void p(int i10, int i11) {
        int i12 = (i11 * this.f18552r) + (i10 / 32);
        int[] iArr = this.f18553s;
        iArr[i12] = (1 << (i10 & 31)) | iArr[i12];
    }

    public void q(int i10, int i11, int i12, int i13) {
        if (i11 < 0 || i10 < 0) {
            throw new IllegalArgumentException("Left and top must be nonnegative");
        }
        if (i13 <= 0 || i12 <= 0) {
            throw new IllegalArgumentException("Height and width must be at least 1");
        }
        int i14 = i12 + i10;
        int i15 = i13 + i11;
        if (i15 > this.f18551q || i14 > this.f18550p) {
            throw new IllegalArgumentException("The region must fit inside the matrix");
        }
        while (i11 < i15) {
            int i16 = this.f18552r * i11;
            for (int i17 = i10; i17 < i14; i17++) {
                int[] iArr = this.f18553s;
                int i18 = (i17 / 32) + i16;
                iArr[i18] = iArr[i18] | (1 << (i17 & 31));
            }
            i11++;
        }
    }

    public void s(int i10, a aVar) {
        int[] j10 = aVar.j();
        int[] iArr = this.f18553s;
        int i11 = this.f18552r;
        System.arraycopy(j10, 0, iArr, i10 * i11, i11);
    }

    public String t(String str, String str2) {
        return a(str, str2, "\n");
    }

    public String toString() {
        return t("X ", "  ");
    }

    public b(int i10, int i11) {
        if (i10 > 0 && i11 > 0) {
            this.f18550p = i10;
            this.f18551q = i11;
            int i12 = (i10 + 31) / 32;
            this.f18552r = i12;
            this.f18553s = new int[i12 * i11];
            return;
        }
        throw new IllegalArgumentException("Both dimensions must be greater than 0");
    }

    private b(int i10, int i11, int i12, int[] iArr) {
        this.f18550p = i10;
        this.f18551q = i11;
        this.f18552r = i12;
        this.f18553s = iArr;
    }
}
