Submission #37631


ソースコード

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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
import java.io.*;
import java.util.*;
import java.lang.*;
import java.math.*;
class Main{
static final Scanner in = new Scanner(System.in);
static final PrintWriter out = new PrintWriter(System.out);
public static void main(String args[]){
int[] a = new int[3000000];
int[] b = new int[3000000];
int n = fgetInt();
int i;
for ( i = 0; i < n; i++ ) {
a[i] = fgetInt();
}
int q = fgetInt();
for ( i = 0; i < q; i++ ) {
int temp = fgetInt();
b[i] = upperBound(a, n, temp) - upperBound(a, n, temp-1);
}
for ( i = 0; i < q; i++ ) {
iprint(b[i]);
}
ifin();
}
static int upperBound(int[] a, int n, int val){
int low = 0;
int hi = n;
while ( low < hi ) {
int mid = (low+hi) / 2;
if ( a[mid] <= val ) low = mid + 1;
else hi = mid;
}
return low;
}
static String fgetStr(){
return FastScanner.next();
}
static String fgetLine(){
return in.nextLine();
}
static char fgetChar(){
return fgetStr().charAt(0);
}
static int fgetInt(){
return FastScanner.nextInt();
}
static long fgetLong(){
return FastScanner.nextLong();
}
static double fgetDouble(){
return FastScanner.nextDouble();
}
static BigInteger getBig(){
return in.nextBigInteger();
}
static String reverseStr(String str){
StringBuffer sb = new StringBuffer(str);
return sb.reverse().toString();
}
static void iprint(Object a){
out.println(a);
}
static void iprintf(Object a){
out.print(a);
}
static void ifin(){
out.flush();
}
@Deprecated
static String getStr(){
return in.next();
}
@Deprecated
static int getInt(){
return Integer.parseInt(getStr());
}
@Deprecated
static long getLong(){
return Long.parseLong(getStr());
}
@Deprecated
static double getDouble(){
return Double.parseDouble(getStr());
}
@Deprecated
static void print(Object a){
System.out.println(a);
}
@Deprecated
static void printf(Object a){
System.out.print(a);
}
}
class FastScanner {
private static final InputStream in = System.in;
private static final byte[] buffer = new byte[1024];
private static int ptr = 0;
private static int buflen = 0;
private static 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 static int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
public static boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
public static 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();
}
static 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 static int nextInt() {
long nl = nextLong();
if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
return (int) nl;
}
public static double nextDouble() { return Double.parseDouble(next());}
}

ステータス

項目 データ
問題 0948 - Number-Collection
ユーザー名 r1825
投稿日時 2018-06-19 20:37:20
言語 Java
状態 Accepted
得点 10
ソースコード長 4721 Byte
最大実行時間 426 ms
最大メモリ使用量 64676 KB

セット

セット 得点 Cases
1 a_NQ-small 1 / 1 *E??
2 b_a-small-positive 1 / 1 *?E?
3 c_a-unique 3 / 3 *??E
4 d_ALL 5 / 5 *

テストケース

ファイル名 状態 実行時間 メモリ使用量 #
input-sample1EEE AC 208 ms 36524 KB
1
2
3
4
input-sample2E__ AC 96 ms 37756 KB
1
4
input01EEE AC 99 ms 37796 KB
1
2
3
4
input02EEE AC 101 ms 39892 KB
1
2
3
4
input03E__ AC 101 ms 40048 KB
1
4
input04E__ AC 103 ms 39020 KB
1
4
input05E__ AC 101 ms 40088 KB
1
4
input06_E_ AC 308 ms 60232 KB
2
4
input07_E_ AC 287 ms 60932 KB
2
4
input08_E_ AC 353 ms 62280 KB
2
4
input09__E AC 426 ms 62788 KB
3
4
input10__E AC 326 ms 63708 KB
3
4
input11__E AC 269 ms 46800 KB
3
4
input12___ AC 247 ms 64428 KB
4
input13___ AC 255 ms 64676 KB
4
input14___ AC 153 ms 44680 KB
4
input15___ AC 291 ms 49988 KB
4
input16___ AC 300 ms 49812 KB
4
input17___ AC 292 ms 51472 KB
4
input18 AC 113 ms 51436 KB
4