Submission #2530806
Source Code Expand
import java.io.IOException; import java.io.InputStream; import java.util.Arrays; import java.util.NoSuchElementException; public class Main { public static void main(String[] args) { FastScanner sc = new FastScanner(); int n = sc.nextInt(); int[] a = new int[n]; int[] b = new int[n]; int[] c = new int[n]; for (int i = 0; i < n; i++) { a[i] = sc.nextInt(); } for (int i = 0; i < n; i++) { b[i] = sc.nextInt(); } for (int i = 0; i < n; i++) { c[i] = sc.nextInt(); } Arrays.sort(a); Arrays.sort(b); Arrays.sort(c); long ans = 0; for (int i = 0; i < n; i++) { ans += binarySearch(a, b[i]) * (n - binarySearch(c, b[i] + 1)); } System.out.println(ans); } // array[i] < targetを満たす最大のiを求める public static long binarySearch(int[] array, int target) { int l = -1; int r = array.length; while (r - l > 1) { int mid = (l + r) / 2; if (array[mid] < target) l = mid; else r = mid; } return r; } } class FastScanner { private final InputStream in = System.in; private final byte[] buffer = new byte[1024]; private int ptr = 0; private int buflen = 0; private boolean hasNextByte() { if (ptr < buflen) { return true; } else { ptr = 0; try { buflen = in.read(buffer); } catch (IOException e) { e.printStackTrace(); } if (buflen <= 0) { return false; } } return true; } private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1; } private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126; } private void skipUnprintable() { while (hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; } public boolean hasNext() { skipUnprintable(); return hasNextByte(); } public String next() { if (!hasNext()) throw new NoSuchElementException(); StringBuilder sb = new StringBuilder(); int b = readByte(); while (isPrintableChar(b)) { sb.appendCodePoint(b); b = readByte(); } return sb.toString(); } public long nextLong() { if (!hasNext()) throw new NoSuchElementException(); long n = 0; boolean minus = false; int b = readByte(); if (b == '-') { minus = true; b = readByte(); } if (b < '0' || '9' < b) { throw new NumberFormatException(); } while (true) { if ('0' <= b && b <= '9') { n *= 10; n += b - '0'; } else if (b == -1 || !isPrintableChar(b)) { return minus ? -n : n; } else { throw new NumberFormatException(); } b = readByte(); } } public int nextInt() { long nl = nextLong(); if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException(); return (int) nl; } public double nextDouble() { return Double.parseDouble(next()); } }
Submission Info
Submission Time | |
---|---|
Task | C - Snuke Festival |
User | mochimochi |
Language | Java8 (OpenJDK 1.8.0) |
Score | 300 |
Code Size | 2919 Byte |
Status | AC |
Exec Time | 324 ms |
Memory | 37472 KB |
Judge Result
Set Name | Sample | All | ||||
---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 300 / 300 | ||||
Status |
|
|
Set Name | Test Cases |
---|---|
Sample | s1.txt, s2.txt, s3.txt |
All | 01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt, 17.txt, 18.txt, 19.txt, 20.txt, 21.txt, 22.txt, 23.txt, 24.txt, 25.txt, 26.txt, 27.txt, 28.txt, 29.txt, s1.txt, s2.txt, s3.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
01.txt | AC | 204 ms | 22172 KB |
02.txt | AC | 197 ms | 24848 KB |
03.txt | AC | 199 ms | 24580 KB |
04.txt | AC | 251 ms | 34420 KB |
05.txt | AC | 185 ms | 25812 KB |
06.txt | AC | 168 ms | 22708 KB |
07.txt | AC | 152 ms | 24468 KB |
08.txt | AC | 175 ms | 25908 KB |
09.txt | AC | 162 ms | 26840 KB |
10.txt | AC | 148 ms | 23236 KB |
11.txt | AC | 156 ms | 23028 KB |
12.txt | AC | 152 ms | 26568 KB |
13.txt | AC | 244 ms | 30832 KB |
14.txt | AC | 237 ms | 31032 KB |
15.txt | AC | 216 ms | 27044 KB |
16.txt | AC | 196 ms | 21568 KB |
17.txt | AC | 207 ms | 23580 KB |
18.txt | AC | 300 ms | 27388 KB |
19.txt | AC | 263 ms | 23132 KB |
20.txt | AC | 144 ms | 26672 KB |
21.txt | AC | 152 ms | 25308 KB |
22.txt | AC | 177 ms | 29024 KB |
23.txt | AC | 197 ms | 24692 KB |
24.txt | AC | 233 ms | 33648 KB |
25.txt | AC | 324 ms | 37472 KB |
26.txt | AC | 68 ms | 18260 KB |
27.txt | AC | 67 ms | 17620 KB |
28.txt | AC | 68 ms | 20308 KB |
29.txt | AC | 69 ms | 18772 KB |
s1.txt | AC | 69 ms | 20180 KB |
s2.txt | AC | 69 ms | 18260 KB |
s3.txt | AC | 69 ms | 17876 KB |