-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCWHIZZ05.java
More file actions
92 lines (74 loc) · 2.89 KB
/
Copy pathCWHIZZ05.java
File metadata and controls
92 lines (74 loc) · 2.89 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
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.StringTokenizer;
/**
*
* @author rn-sshawish
*/
public class CWHIZZ05 {
public static void main(String[] args) throws Exception {
try{
BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
int q = Integer.parseInt(input.readLine());
StringTokenizer tokn;
StringBuilder out = new StringBuilder();
for (int i = 0; i < q; i++) {
tokn = new StringTokenizer(input.readLine());
int n = Integer.parseInt(tokn.nextToken());
int m = Integer.parseInt(tokn.nextToken());
HashMap<Integer, Point> points = new HashMap<>();
for (int j = 0; j < m; j++) {
tokn = new StringTokenizer(input.readLine());
if (tokn.nextToken().equals("UPDATE")) {
Point tar = new Point(
Integer.parseInt(tokn.nextToken()),
Integer.parseInt(tokn.nextToken()),
Integer.parseInt(tokn.nextToken()),
Integer.parseInt(tokn.nextToken()));
points.put(tar.value, tar);
} else {
out.append(getSum(new Point(
Integer.parseInt(tokn.nextToken()),
Integer.parseInt(tokn.nextToken()),
Integer.parseInt(tokn.nextToken())),
new Point(
Integer.parseInt(tokn.nextToken()),
Integer.parseInt(tokn.nextToken()),
Integer.parseInt(tokn.nextToken())),
points)).append("\n");
}
}
}
System.out.print(out);
}catch(Exception e){
}
}
public static boolean check(Point l, Point r, Point p) {
return p.value >= l.value && p.value <= r.value;
}
public static long getSum(Point l, Point r, HashMap<Integer, Point> points) {
long sum = 0;
for (Point point : points.values()) {
if (check(l, r, point)) {
sum += point.sum;
}
}
return sum;
}
static class Point {
long sum;
int value;
public Point(int x, int y, int z, int sum) {
this.value = x * 100;
this.value += y * 10;
this.value += z;
this.sum = sum;
}
public Point(int x, int y, int z) {
this.value = x * 100;
this.value += y * 10;
this.value += z;
}
}
}