Submission #53543


ソースコード

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:18:42
言語 C++14
状態 Accepted
得点 10
ソースコード長 1059 Byte
最大実行時間 488 ms
最大メモリ使用量 250452 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 49 ms 24028 KB
1
2
3
4
input-sample2E__ AC 23 ms 24096 KB
1
4
input01EEE AC 38 ms 23908 KB
1
2
3
4
input02EEE AC 28 ms 23972 KB
1
2
3
4
input03E__ AC 32 ms 24040 KB
1
4
input04E__ AC 30 ms 24096 KB
1
4
input05E__ AC 32 ms 24160 KB
1
4
input06_E_ AC 174 ms 29980 KB
2
4
input07_E_ AC 215 ms 38364 KB
2
4
input08_E_ AC 237 ms 49680 KB
2
4
input09__E AC 476 ms 78156 KB
3
4
input10__E AC 184 ms 88324 KB
3
4
input11__E AC 488 ms 117056 KB
3
4
input12___ AC 139 ms 123900 KB
4
input13___ AC 162 ms 133816 KB
4
input14___ AC 147 ms 145264 KB
4
input15___ AC 327 ms 178984 KB
4
input16___ AC 461 ms 215648 KB
4
input17___ AC 383 ms 249372 KB
4
input18 AC 75 ms 250452 KB
4