Skip to content

Commit 508e703

Browse files
committedApr 25, 2017
csacademy 26C clean up
1 parent f1d6829 commit 508e703

File tree

1 file changed

+7
-10
lines changed

1 file changed

+7
-10
lines changed
 

‎csacademy.com/rounds/1-100/26C.java

+7-10
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,9 @@ void solve() throws IOException {
1212
int l = in.nextInt();
1313
int r = in.nextInt();
1414
int[] a = new int[n];
15-
long ans = 0, j = 0, m, extra = 0;
15+
long ans = 0, m;
1616
Set<Integer> s = new HashSet<>();
1717
Queue<Integer> q = new LinkedList<>();
18-
List<Integer> chunks = new LinkedList<>();
1918

2019
for (int i = 0; i < n; i++) {
2120
a[i] = in.nextInt();
@@ -24,7 +23,8 @@ void solve() throws IOException {
2423
for (int i = 0; i < n; i++) {
2524
if (s.contains(a[i])) {
2625
if (q.size() >= l) {
27-
chunks.add(q.size());
26+
m = Integer.min(q.size(), r);
27+
ans += (2*q.size()-l-m+2) * (m-l+1)/2;
2828
}
2929

3030
while (q.peek() != a[i]) {
@@ -34,7 +34,7 @@ void solve() throws IOException {
3434
q.poll();
3535
if (q.size() >= l) {
3636
m = Integer.min(q.size(), r);
37-
extra += (2*q.size()-l-m+2) * (m-l+1)/2;
37+
ans -= (2*q.size()-l-m+2) * (m-l+1)/2;
3838
}
3939
q.add(a[i]);
4040
} else {
@@ -44,14 +44,11 @@ void solve() throws IOException {
4444
}
4545

4646
if (q.size() >= l) {
47-
chunks.add(q.size());
47+
m = Integer.min(q.size(), r);
48+
ans += (2*q.size()-l-m+2) * (m-l+1)/2;
4849
}
4950

50-
for (Integer chunk : chunks) {
51-
m = Integer.min(chunk, r);
52-
ans += (2*chunk-l-m+2) * (m-l+1)/2;
53-
}
54-
out.println(ans-extra);
51+
out.println(ans);
5552
out.flush();
5653
}
5754

0 commit comments

Comments
 (0)
Please sign in to comment.