package tb;

import java.util.Arrays;

/* JADX INFO: loaded from: classes.dex */
public final class b implements Cloneable {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public int f33005a;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public int f33006b;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public int f33007c;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public int[] f33008d;

    public b(int i10, int i11) {
        if (i10 < 1 || i11 < 1) {
            throw new IllegalArgumentException("Both dimensions must be greater than 0");
        }
        this.f33005a = i10;
        this.f33006b = i11;
        int i12 = (i10 + 31) / 32;
        this.f33007c = i12;
        this.f33008d = new int[i12 * i11];
    }

    public final void a(int i10, int i11) {
        int i12 = (i10 / 32) + (i11 * this.f33007c);
        int[] iArr = this.f33008d;
        iArr[i12] = (1 << (i10 & 31)) ^ iArr[i12];
    }

    public final boolean b(int i10, int i11) {
        return ((this.f33008d[(i10 / 32) + (i11 * this.f33007c)] >>> (i10 & 31)) & 1) != 0;
    }

    public final int[] c() {
        int length = this.f33008d.length - 1;
        while (length >= 0 && this.f33008d[length] == 0) {
            length--;
        }
        if (length < 0) {
            return null;
        }
        int i10 = this.f33007c;
        int i11 = length / i10;
        int i12 = (length % i10) * 32;
        int i13 = 31;
        while ((this.f33008d[length] >>> i13) == 0) {
            i13--;
        }
        return new int[]{i12 + i13, i11};
    }

    public final Object clone() {
        int i10 = this.f33005a;
        int i11 = this.f33006b;
        int i12 = this.f33007c;
        int[] iArr = (int[]) this.f33008d.clone();
        b bVar = new b();
        bVar.f33005a = i10;
        bVar.f33006b = i11;
        bVar.f33007c = i12;
        bVar.f33008d = iArr;
        return bVar;
    }

    public final a d(int i10, a aVar) {
        int i11 = aVar.f33004b;
        int i12 = this.f33005a;
        if (i11 < i12) {
            aVar = new a(i12);
        } else {
            int length = aVar.f33003a.length;
            for (int i13 = 0; i13 < length; i13++) {
                aVar.f33003a[i13] = 0;
            }
        }
        int i14 = i10 * this.f33007c;
        for (int i15 = 0; i15 < this.f33007c; i15++) {
            aVar.f33003a[(i15 * 32) / 32] = this.f33008d[i14 + i15];
        }
        return aVar;
    }

    public final int[] e() {
        int[] iArr;
        int i10 = 0;
        int i11 = 0;
        while (true) {
            iArr = this.f33008d;
            if (i11 >= iArr.length || iArr[i11] != 0) {
                break;
            }
            i11++;
        }
        if (i11 == iArr.length) {
            return null;
        }
        int i12 = this.f33007c;
        int i13 = i11 / i12;
        int i14 = (i11 % i12) * 32;
        while ((iArr[i11] << (31 - i10)) == 0) {
            i10++;
        }
        return new int[]{i14 + i10, i13};
    }

    public final boolean equals(Object obj) {
        if (!(obj instanceof b)) {
            return false;
        }
        b bVar = (b) obj;
        return this.f33005a == bVar.f33005a && this.f33006b == bVar.f33006b && this.f33007c == bVar.f33007c && Arrays.equals(this.f33008d, bVar.f33008d);
    }

    public final void f() {
        a aVar = new a(this.f33005a);
        a aVar2 = new a(this.f33005a);
        int i10 = (this.f33006b + 1) / 2;
        for (int i11 = 0; i11 < i10; i11++) {
            aVar = d(i11, aVar);
            int i12 = (this.f33006b - 1) - i11;
            aVar2 = d(i12, aVar2);
            aVar.i();
            aVar2.i();
            int[] iArr = aVar2.f33003a;
            int[] iArr2 = this.f33008d;
            int i13 = this.f33007c;
            System.arraycopy(iArr, 0, iArr2, i11 * i13, i13);
            int[] iArr3 = aVar.f33003a;
            int[] iArr4 = this.f33008d;
            int i14 = this.f33007c;
            System.arraycopy(iArr3, 0, iArr4, i12 * i14, i14);
        }
    }

    public final void g() {
        int i10 = this.f33006b;
        int i11 = this.f33005a;
        int i12 = (i10 + 31) / 32;
        int[] iArr = new int[i12 * i11];
        for (int i13 = 0; i13 < this.f33006b; i13++) {
            for (int i14 = 0; i14 < this.f33005a; i14++) {
                if (((this.f33008d[(i14 / 32) + (this.f33007c * i13)] >>> (i14 & 31)) & 1) != 0) {
                    int i15 = (i13 / 32) + (((i11 - 1) - i14) * i12);
                    iArr[i15] = iArr[i15] | (1 << (i13 & 31));
                }
            }
        }
        this.f33005a = i10;
        this.f33006b = i11;
        this.f33007c = i12;
        this.f33008d = iArr;
    }

    public final void h(int i10, int i11) {
        int i12 = (i10 / 32) + (i11 * this.f33007c);
        int[] iArr = this.f33008d;
        iArr[i12] = (1 << (i10 & 31)) | iArr[i12];
    }

    public final int hashCode() {
        int i10 = this.f33005a;
        return Arrays.hashCode(this.f33008d) + (((((((i10 * 31) + i10) * 31) + this.f33006b) * 31) + this.f33007c) * 31);
    }

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

    public final String toString() {
        StringBuilder sb = new StringBuilder((this.f33005a + 1) * this.f33006b);
        for (int i10 = 0; i10 < this.f33006b; i10++) {
            for (int i11 = 0; i11 < this.f33005a; i11++) {
                sb.append(b(i11, i10) ? "X " : "  ");
            }
            sb.append("\n");
        }
        return sb.toString();
    }
}
