-
Notifications
You must be signed in to change notification settings - Fork 22
/
count elements
71 lines (60 loc) · 1.34 KB
/
count elements
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
/*
Given two arrays A and B. Given Q queries each having a positive integer i denoting an index of the array A. For each query, your task is to
find all the elements less than or equal to Ai in the array B.
Input:
The first line contains a single integer T, the number of test cases. The first line of each test case consists of a integer N. The second and
third line of each test case consists of N spaced integers representing array A and array B respectively. The third line contains a positive
integer Q, denoting the number of queries. Next Q lines contains queries.
Output:
For each testcase, print the required answer.
Constraints:
1 <= T <= 100
1 <= N <= 107
1 <= Ai, Bi <= 107
1 <= Q <= 103
Example:
Input:
1
6
1 2 3 4 7 9
0 1 2 1 1 4
2
5
4
Output:
6
6
Explanation:
Testcase 1: For 1st query, the given index is 5, A[5] is 9 and in B all the elements are smaller than 9.
For 2nd query, the given index is 4, A[4] is 7 and in B all the elements are smaller than 7.
*/
#include<bits/stdc++.h>
using namespace std;
int main() {
int t;
cin>>t;
while(t--){
int n;
cin>>n;
int a[n],b[n];
int max=INT_MIN;
for(int i=0;i<n;i++) {
cin>>a[i];
if(a[i]>max) max=a[i];
}
int c[max+1]={0};
for(int i=0;i<n;i++) {cin>>b[i];
c[b[i]]++;
}
for(int i=1;i<=max;i++){
c[i]=c[i-1]+c[i];
}
int q;
cin>>q;
int x;
while(q--){
cin>>x;
cout<<c[a[x]]<<endl;
}
} return 0;
}