Skip to content

Commit bd24218

Browse files
committed
modify code
1 parent 24824fd commit bd24218

File tree

2 files changed

+36
-34
lines changed

2 files changed

+36
-34
lines changed

src/class166/Code01_SegmentTreeDivideConquer1.java

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,7 @@ public class Code01_SegmentTreeDivideConquer1 {
1818
public static int MAXT = 5000001;
1919
public static int n, m;
2020

21-
public static int[] op = new int[MAXM];
22-
public static int[] a = new int[MAXM];
23-
public static int[] b = new int[MAXM];
24-
21+
public static int[][] event = new int[MAXM][3];
2522
public static int[][] last = new int[MAXN][MAXN];
2623

2724
public static int[] father = new int[MAXN];
@@ -99,8 +96,11 @@ public static void dfs(int l, int r, int i) {
9996
}
10097
}
10198
if (l == r) {
102-
if (op[l] == 2) {
103-
ans[l] = find(a[l]) == find(b[l]);
99+
int op = event[l][0];
100+
int x = event[l][1];
101+
int y = event[l][2];
102+
if (op == 2) {
103+
ans[l] = find(x) == find(y);
104104
}
105105
} else {
106106
int mid = (l + r) / 2;
@@ -117,12 +117,13 @@ public static void prepare() {
117117
father[i] = i;
118118
siz[i] = 1;
119119
}
120-
for (int i = 1, x, y; i <= m; i++) {
121-
x = a[i];
122-
y = b[i];
123-
if (op[i] == 0) {
120+
for (int i = 1, op, x, y; i <= m; i++) {
121+
op = event[i][0];
122+
x = event[i][1];
123+
y = event[i][2];
124+
if (op == 0) {
124125
last[x][y] = i;
125-
} else if (op[i] == 1) {
126+
} else if (op == 1) {
126127
add(last[x][y], i - 1, x, y, 1, m, 1);
127128
last[x][y] = 0;
128129
}
@@ -140,18 +141,18 @@ public static void main(String[] args) {
140141
FastIO io = new FastIO(System.in, System.out);
141142
n = io.nextInt();
142143
m = io.nextInt();
143-
for (int i = 1, x, y, t; i <= m; i++) {
144-
t = io.nextInt();
144+
for (int i = 1, op, x, y; i <= m; i++) {
145+
op = io.nextInt();
145146
x = io.nextInt();
146147
y = io.nextInt();
147-
op[i] = t;
148-
a[i] = Math.min(x, y);
149-
b[i] = Math.max(x, y);
148+
event[i][0] = op;
149+
event[i][1] = Math.min(x, y);
150+
event[i][2] = Math.max(x, y);
150151
}
151152
prepare();
152153
dfs(1, m, 1);
153154
for (int i = 1; i <= m; i++) {
154-
if (op[i] == 2) {
155+
if (event[i][0] == 2) {
155156
if (ans[i]) {
156157
io.write("Y\n");
157158
} else {

src/class166/Code01_SegmentTreeDivideConquer2.java

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,7 @@
1414
//const int MAXT = 5000001;
1515
//int n, m;
1616
//
17-
//int op[MAXM];
18-
//int a[MAXM];
19-
//int b[MAXM];
20-
//
17+
//int event[MAXM][3];
2118
//int last[MAXN][MAXN];
2219
//
2320
//int father[MAXN];
@@ -95,8 +92,11 @@
9592
// }
9693
// }
9794
// if (l == r) {
98-
// if (op[l] == 2) {
99-
// ans[l] = find(a[l]) == find(b[l]);
95+
// int op = event[l][0];
96+
// int x = event[l][1];
97+
// int y = event[l][2];
98+
// if (op == 2) {
99+
// ans[l] = find(x) == find(y);
100100
// }
101101
// } else {
102102
// int mid = (l + r) >> 1;
@@ -113,12 +113,13 @@
113113
// father[i] = i;
114114
// siz[i] = 1;
115115
// }
116-
// for (int i = 1, x, y; i <= m; i++) {
117-
// x = a[i];
118-
// y = b[i];
119-
// if (op[i] == 0) {
116+
// for (int i = 1, op, x, y; i <= m; i++) {
117+
// op = event[i][0];
118+
// x = event[i][1];
119+
// y = event[i][2];
120+
// if (op == 0) {
120121
// last[x][y] = i;
121-
// } else if (op[i] == 1) {
122+
// } else if (op == 1) {
122123
// add(last[x][y], i - 1, x, y, 1, m, 1);
123124
// last[x][y] = 0;
124125
// }
@@ -136,16 +137,16 @@
136137
// ios::sync_with_stdio(false);
137138
// cin.tie(nullptr);
138139
// cin >> n >> m;
139-
// for (int i = 1, t, x, y; i <= m; i++) {
140-
// cin >> t >> x >> y;
141-
// op[i] = t;
142-
// a[i] = min(x, y);
143-
// b[i] = max(x, y);
140+
// for (int i = 1, op, x, y; i <= m; i++) {
141+
// cin >> op >> x >> y;
142+
// event[i][0] = op;
143+
// event[i][1] = min(x, y);
144+
// event[i][2] = max(x, y);
144145
// }
145146
// prepare();
146147
// dfs(1, m, 1);
147148
// for (int i = 1; i <= m; i++) {
148-
// if (op[i] == 2) {
149+
// if (event[i][0] == 2) {
149150
// if (ans[i]) {
150151
// cout << "Y" << "\n";
151152
// } else {

0 commit comments

Comments
 (0)