forked from ngthanhtrung23/CompetitiveProgramming
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathE.java
More file actions
176 lines (146 loc) · 5.2 KB
/
E.java
File metadata and controls
176 lines (146 loc) · 5.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
import java.io.*;
import java.math.*;
import java.util.*;
public class RR {
public static void main(String[] args) {
(new Solver()).go();
}
}
class Solver {
void go() {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
InputReader in = new InputReader(inputStream);
PrintWriter out = new PrintWriter(outputStream);
long[] hash = new long[100111];
hash[0] = 777;
for (int i = 1; i < hash.length; i++) {
hash[i] = hash[i-1] * 3;
}
Fenwick fenwick = new Fenwick(5000, 5000);
int n = in.nextInt();
int m = in.nextInt();
int q = in.nextInt();
Rect[] queries = new Rect[q + 1];
TreeMap<Rect,Integer> allRects = new TreeMap<>();
for (int i = 1; i <= q; i++) {
int type = in.nextInt();
if (type == 1) {
int x1 = in.nextInt();
int y1 = in.nextInt();
int x2 = in.nextInt();
int y2 = in.nextInt();
int top = Math.max(y1, y2);
int bottom = Math.min(y1, y2);
int left = Math.min(x1, x2);
int right = Math.max(x1, x2);
queries[i] = new Rect(bottom, top, left, right);
queries[i].update(fenwick, hash[i]);
allRects.put(queries[i], i);
}
if (type == 2) {
int x1 = in.nextInt();
int y1 = in.nextInt();
int x2 = in.nextInt();
int y2 = in.nextInt();
int top = Math.max(y1, y2);
int bottom = Math.min(y1, y2);
int left = Math.min(x1, x2);
int right = Math.max(x1, x2);
queries[i] = new Rect(bottom, top, left, right);
queries[i].update(fenwick, hash[allRects.get(queries[i])]);
}
if (type == 3) {
int x1 = in.nextInt();
int y1 = in.nextInt();
int x2 = in.nextInt();
int y2 = in.nextInt();
int sw;
sw = x1; x1 = y1; y1 = sw;
sw = x2; x2 = y2; y2 = sw;
if (fenwick.get(x1, y1) == fenwick.get(x2, y2)) {
out.println("Yes");
} else {
out.println("No");
}
}
}
out.close();
}
static class Rect implements Comparable<Rect> {
public int bottom, top, left, right;
public int compareTo(Rect a) {
if (bottom != a.bottom) return bottom - a.bottom;
if (top != a.top) return top - a.top;
if (left != a.left) return left - a.left;
if (right != a.right) return right - a.right;
return 0;
}
public Rect(int bottom, int top, int left, int right) {
this.bottom = bottom;
this.top = top;
this.left = left;
this.right = right;
}
public void update(Fenwick fenwick, long hash) {
fenwick.update(bottom, top, left, right, hash);
}
}
static class Fenwick {
public int m, n;
long[][] hash;
public Fenwick(int m, int n) {
this.m = m;
this.n = n;
hash = new long[m + 2][n + 2];
for (int i = 0; i < hash.length; i++) {
for (int j = 0; j < hash[i].length; j++) {
hash[i][j] = 0;
}
}
}
public long get(int x, int y) {
long res = 0;
for (; x >= 1; x -= x & -x) {
for (int t = y; t >= 1; t -= t & -t) {
res ^= hash[x][t];
}
}
return res;
}
public void update(int bottom, int top, int left, int right, long d) {
this.update(bottom, left, d);
this.update(bottom, right + 1, d);
this.update(top + 1, left, d);
this.update(top + 1, right + 1, d);
}
public void update(int x, int y, long d) {
for (; x <= m; x += x & -x) {
for (int t = y; t <= n; t += t & -t) {
hash[x][t] ^= d;
}
}
}
}
static class InputReader {
public BufferedReader reader;
public StringTokenizer tokenizer;
public InputReader(InputStream stream) {
reader = new BufferedReader(new InputStreamReader(stream), 32768);
tokenizer = null;
}
public String next() {
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
try {
tokenizer = new StringTokenizer(reader.readLine());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return tokenizer.nextToken();
}
public int nextInt() {
return Integer.parseInt(next());
}
}
}