Submission #53544


ソースコード

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
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define all(x) (x).begin(),(x).end()
#define int long long
#define mk_p(a,b) make_pair((a),(b))
using pii = pair<int,int>;
constexpr int INF = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
int gcd(int a,int b){return b ? gcd(b,a%b) : a;}
int lcm(int a,int b){return a/gcd(a,b)*b;}
vector<int> a(3000050);
int n;
int up_b(int v){
int low = -1;
int high = n;
while(high - low > 1){
int mid = (high + low) / 2;
if(a[mid] > v) high = mid;
else low = mid;
}
return high;
}
int low_b(int v){
int low = -1;
int high = n;
while(high - low > 1){
int mid = (high + low) / 2;
if(a[mid] >= v) high = mid;
else low = mid;
}
return high;
}
signed main(){
cin.tie(0);
ios::sync_with_stdio(false);
cin >> n;
rep(i,n) cin >> a[i];
int q;
cin >> q;
rep(i,q){
int v;
cin >> v;
cout << up_b(v) - low_b(v) << '\n';
}
return 0;
}

ステータス

項目 データ
問題 0948 - Number-Collection
ユーザー名 ei1903
投稿日時 2019-08-25 13:19:08
言語 C++14
状態 Accepted
得点 10
ソースコード長 1059 Byte
最大実行時間 281 ms
最大メモリ使用量 31336 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 34 ms 24028 KB
1
2
3
4
input-sample2E__ AC 23 ms 24100 KB
1
4
input01EEE AC 28 ms 24036 KB
1
2
3
4
input02EEE AC 29 ms 23976 KB
1
2
3
4
input03E__ AC 24 ms 24040 KB
1
4
input04E__ AC 25 ms 24100 KB
1
4
input05E__ AC 25 ms 24032 KB
1
4
input06_E_ AC 133 ms 24988 KB
2
4
input07_E_ AC 159 ms 25816 KB
2
4
input08_E_ AC 196 ms 27156 KB
2
4
input09__E AC 281 ms 27608 KB
3
4
input10__E AC 155 ms 28308 KB
3
4
input11__E AC 221 ms 28500 KB
3
4
input12___ AC 107 ms 29076 KB
4
input13___ AC 120 ms 29900 KB
4
input14___ AC 95 ms 29952 KB
4
input15___ AC 239 ms 30264 KB
4
input16___ AC 254 ms 30708 KB
4
input17___ AC 253 ms 31148 KB
4
input18 AC 32 ms 31336 KB
4