Skip to content

Commit 7daa49c

Browse files
committed
Fixed sonar
1 parent 4667949 commit 7daa49c

File tree

3 files changed

+44
-29
lines changed

3 files changed

+44
-29
lines changed

src/main/java/g3201_3300/s3238_find_the_number_of_winning_players/Solution.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
// #Easy #Array #Hash_Table #Counting #2024_08_06_Time_1_ms_(100.00%)_Space_44.5_MB_(99.46%)
44

5-
@SuppressWarnings("unused")
5+
@SuppressWarnings({"unused", "java:S1172"})
66
public class Solution {
77
public int winningPlayerCount(int n, int[][] pick) {
88
int[][] dp = new int[11][11];

src/main/java/g3201_3300/s3241_time_taken_to_mark_all_nodes/Solution.java

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,12 @@ public int[] timeTaken(int[][] edges) {
2525
int v = edges[i][1];
2626
nxt[j] = head[u];
2727
head[u] = j;
28-
to[j++] = v;
28+
to[j] = v;
29+
j++;
2930
nxt[j] = head[v];
3031
head[v] = j;
31-
to[j++] = u;
32+
to[j] = u;
33+
j++;
3234
}
3335
last = new int[n];
3436
lastNo = new int[n];
@@ -41,7 +43,9 @@ public int[] timeTaken(int[][] edges) {
4143
}
4244

4345
private void dfs2(int f, int u, int preLast) {
44-
for (int e = head[u], v; e != -1; e = nxt[e]) {
46+
int e = head[u];
47+
int v;
48+
while (e != -1) {
4549
v = to[e];
4650
if (f != v) {
4751
int pl;
@@ -53,11 +57,14 @@ private void dfs2(int f, int u, int preLast) {
5357
ans[v] = Math.max(ans[v], pl);
5458
dfs2(u, v, pl);
5559
}
60+
e = nxt[e];
5661
}
5762
}
5863

5964
private void dfs(int f, int u) {
60-
for (int e = head[u], v; e != -1; e = nxt[e]) {
65+
int e = head[u];
66+
int v;
67+
while (e != -1) {
6168
v = to[e];
6269
if (f != v) {
6370
dfs(u, v);
@@ -70,6 +77,7 @@ private void dfs(int f, int u) {
7077
second[u] = t;
7178
}
7279
}
80+
e = nxt[e];
7381
}
7482
}
7583
}

src/main/java/g3201_3300/s3245_alternating_groups_iii/Solution.java

Lines changed: 31 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ private void go(int ind, LST lst, int[] fs, int n, LST ff, int[] c) {
1414
nex = 2 * n;
1515
}
1616
if (pre != -1 && pre < n && --fs[nex - pre] == 0) {
17-
ff.unset(nex - pre);
17+
ff.unsetPos(nex - pre);
1818
}
1919
}
2020
if (lst.get(ind)) {
@@ -24,7 +24,7 @@ private void go(int ind, LST lst, int[] fs, int n, LST ff, int[] c) {
2424
nex = 2 * n;
2525
}
2626
if (pre != -1 && pre < n && --fs[nex - pre] == 0) {
27-
ff.unset(nex - pre);
27+
ff.unsetPos(nex - pre);
2828
}
2929
}
3030
if (lst.get(ind + 1)) {
@@ -34,17 +34,17 @@ private void go(int ind, LST lst, int[] fs, int n, LST ff, int[] c) {
3434
nex = 2 * n;
3535
}
3636
if (pre != -1 && pre < n && --fs[nex - pre] == 0) {
37-
ff.unset(nex - pre);
37+
ff.unsetPos(nex - pre);
3838
}
3939
}
40-
lst.unset(ind);
41-
lst.unset(ind + 1);
40+
lst.unsetPos(ind);
41+
lst.unsetPos(ind + 1);
4242
c[ind] ^= 1;
4343
if (ind > 0 && c[ind] != c[ind - 1]) {
44-
lst.set(ind);
44+
lst.setPos(ind);
4545
}
4646
if (ind + 1 < c.length && c[ind + 1] != c[ind]) {
47-
lst.set(ind + 1);
47+
lst.setPos(ind + 1);
4848
}
4949
if (ind > 0) {
5050
int pre = lst.prev(ind - 1);
@@ -53,7 +53,7 @@ private void go(int ind, LST lst, int[] fs, int n, LST ff, int[] c) {
5353
nex = 2 * n;
5454
}
5555
if (pre != -1 && pre < n && ++fs[nex - pre] == 1) {
56-
ff.set(nex - pre);
56+
ff.setPos(nex - pre);
5757
}
5858
}
5959
if (lst.get(ind)) {
@@ -63,7 +63,7 @@ private void go(int ind, LST lst, int[] fs, int n, LST ff, int[] c) {
6363
nex = 2 * n;
6464
}
6565
if (pre < n && ++fs[nex - pre] == 1) {
66-
ff.set(nex - pre);
66+
ff.setPos(nex - pre);
6767
}
6868
}
6969
if (lst.get(ind + 1)) {
@@ -73,7 +73,7 @@ private void go(int ind, LST lst, int[] fs, int n, LST ff, int[] c) {
7373
nex = 2 * n;
7474
}
7575
if (pre < n && ++fs[nex - pre] == 1) {
76-
ff.set(nex - pre);
76+
ff.setPos(nex - pre);
7777
}
7878
}
7979
}
@@ -87,7 +87,7 @@ public List<Integer> numberOfAlternatingGroups(int[] colors, int[][] queries) {
8787
LST lst = new LST(2 * n + 3);
8888
for (int i = 1; i < 2 * n; i++) {
8989
if (c[i] != c[i - 1]) {
90-
lst.set(i);
90+
lst.setPos(i);
9191
}
9292
}
9393
int[] fs = new int[2 * n + 1];
@@ -99,7 +99,7 @@ public List<Integer> numberOfAlternatingGroups(int[] colors, int[][] queries) {
9999
ne = 2 * n;
100100
}
101101
fs[ne - i]++;
102-
ff.set(ne - i);
102+
ff.setPos(ne - i);
103103
}
104104
}
105105
List<Integer> ans = new ArrayList<>();
@@ -135,26 +135,29 @@ public List<Integer> numberOfAlternatingGroups(int[] colors, int[][] queries) {
135135
}
136136

137137
private static class LST {
138-
public long[][] set;
139-
public int n;
138+
private long[][] set;
139+
private int n;
140140

141141
public LST(int n) {
142142
this.n = n;
143143
int d = 1;
144-
{
145-
int m = n;
146-
while (m > 1) {
147-
m >>>= 6;
148-
d++;
149-
}
150-
}
144+
d = getD(n, d);
151145
set = new long[d][];
152146
for (int i = 0, m = n >>> 6; i < d; i++, m >>>= 6) {
153147
set[i] = new long[m + 1];
154148
}
155149
}
156150

157-
public LST set(int pos) {
151+
private int getD(int n, int d) {
152+
int m = n;
153+
while (m > 1) {
154+
m >>>= 6;
155+
d++;
156+
}
157+
return d;
158+
}
159+
160+
public LST setPos(int pos) {
158161
if (pos >= 0 && pos < n) {
159162
for (int i = 0; i < set.length; i++, pos >>>= 6) {
160163
set[i][pos >>> 6] |= 1L << pos;
@@ -163,7 +166,7 @@ public LST set(int pos) {
163166
return this;
164167
}
165168

166-
public LST unset(int pos) {
169+
public LST unsetPos(int pos) {
167170
if (pos >= 0 && pos < n) {
168171
for (int i = 0;
169172
i < set.length && (i == 0 || set[i - 1][pos] == 0L);
@@ -179,7 +182,8 @@ public boolean get(int pos) {
179182
}
180183

181184
public int prev(int pos) {
182-
for (int i = 0; i < set.length && pos >= 0; i++, pos >>>= 6, pos--) {
185+
int i = 0;
186+
while (i < set.length && pos >= 0) {
183187
int pre = prev(set[i][pos >>> 6], pos & 63);
184188
if (pre != -1) {
185189
pos = pos >>> 6 << 6 | pre;
@@ -188,6 +192,9 @@ public int prev(int pos) {
188192
}
189193
return pos;
190194
}
195+
i++;
196+
pos >>>= 6;
197+
pos--;
191198
}
192199
return -1;
193200
}

0 commit comments

Comments
 (0)