-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathNaiveSolution.java
More file actions
93 lines (89 loc) · 3.38 KB
/
NaiveSolution.java
File metadata and controls
93 lines (89 loc) · 3.38 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
package test;
import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Scanner;
public class NaiveSolution {
static final int TEST_CASE_NUM = Gen.TESTCASE_NUM;
public static void main(String[] args) {
for (int i = 0; i < TEST_CASE_NUM; i++) {
String inputFileName = String.format("LazySegTree/test/in/testcase_%d", i);
String outputFileName = String.format("LazySegTree/test/answer/answer_%d", i);
try (Scanner sc = new Scanner(new File(inputFileName))) {
try (PrintWriter pw = new PrintWriter(new File(outputFileName))) {
solve(sc, pw);
sc.close();
pw.flush();
pw.close();
}
} catch (IOException e) {
e.printStackTrace();
System.exit(1);
}
}
}
static final long INF = 1l << 60;
public static void solve(Scanner sc, PrintWriter pw) {
final int N = Integer.parseInt(sc.next());
final int Q = Integer.parseInt(sc.next());
final long[] A = new long[N];
Arrays.setAll(A, i -> Integer.parseInt(sc.next()));
for (int i = 0; i < Q; i++) {
int queryType = Integer.parseInt(sc.next());
if (queryType == 0) {
int p = Integer.parseInt(sc.next());
int v = Integer.parseInt(sc.next());
A[p] = v;
} else if (queryType == 1) {
int p = Integer.parseInt(sc.next());
int v = Integer.parseInt(sc.next());
A[p] += v;
} else if (queryType == 2) {
int l = Integer.parseInt(sc.next());
int r = Integer.parseInt(sc.next());
int v = Integer.parseInt(sc.next());
for (int j = l; j < r; j++) {
A[j] += v;
}
} else if (queryType == 3) {
int p = Integer.parseInt(sc.next());
pw.println(A[p]);
} else if (queryType == 4) {
int l = Integer.parseInt(sc.next());
int r = Integer.parseInt(sc.next());
long min = INF;
for (int j = l; j < r; j++) {
min = Math.min(min, A[j]);
}
pw.println(min == INF ? "INF" : min);
} else if (queryType == 5) {
long min = INF;
for (int j = 0; j < N; j++) {
min = Math.min(min, A[j]);
}
pw.println(min);
} else if (queryType == 6) {
int l = Integer.parseInt(sc.next());
int v = Integer.parseInt(sc.next());
for (int j = l; j <= N; j++) {
if (j == N || A[j] <= v) {
pw.println(j);
break;
}
}
} else if (queryType == 7) {
int r = Integer.parseInt(sc.next());
int v = Integer.parseInt(sc.next());
for (int j = r; j >= 0; j--) {
if (j == 0 || A[j - 1] <= v) {
pw.println(j);
break;
}
}
} else {
throw new AssertionError();
}
}
}
}