-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathart2.java
More file actions
77 lines (58 loc) · 1.72 KB
/
art2.java
File metadata and controls
77 lines (58 loc) · 1.72 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
import java.io.*;
import java.util.StringTokenizer;
import java.lang.reflect.Array;
import java.util.*;
public class art2 {
public static void main(String[] args) throws IOException {
BufferedReader f = new BufferedReader(new FileReader("art2.in"));
PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("art2.out")));
int n = Integer.parseInt(f.readLine());
int[][] places= new int[n+1][2];
for(int i = 0; i<n;i++){
int k = Integer.parseInt(f.readLine());
if(k!=0) {
if (places[k][0] == 0) {
places[k][0] = i;
places[k][1] = i;
}
else {
places[k][1] = i;
}
}
}
int[] bit = new int[n+2];
System.out.println("yo");
for (int i = 0; i<n;i++){
updateBIT(bit,places[i][1]+1,1);
updateBIT(bit,places[i][0],-1);
}
int max = -1;
for(int i = 0; i<n;i++){
System.out.println(places[i][1]);
int num = getSum(bit,places[i][1]+1)-getSum(bit,places[i][0]);
max = Math.max(num,max);
}
out.println(max-1);
out.close();
}
static int getSum(int BITree[], int index)
{
int sum = 0;
index = index + 1;
while (index>0)
{
sum += BITree[index];
index -= index & (-index);
}
return sum;
}
static void updateBIT(int BITree[], int index, int val)
{
index = index + 1;
while (index < BITree.length)
{
BITree[index] += val;
index += index & (-index);
}
}
}