-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy path1602B.cpp
58 lines (47 loc) · 909 Bytes
/
1602B.cpp
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
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define endl '\n'
#define debug(n) cout<<(n)<<endl;
const ll INF = 2e18 + 99;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t, n;
cin>>t;
while(t--){
cin>>n;
int arr[n];
int max = -1;
for(int i = 0; i < n; i++){
cin>>arr[i];
if(arr[i] > max){
max = arr[i];
}
}
int brr[max][n];
for(int i = 0; i < n; i++){
brr[0][i] = arr[i];
}
for(int j = 0; j < max; j++){
unordered_map<int, int> mp;
for (int i = 0; i < n; i++){
mp[brr[j][i]]++;
}
for(int i = 0; i < n; i++){
brr[j+1][i] = mp[brr[j][i]];
}
}
int q, a, b;
cin>>q;
while(q-- ){
cin>>a>>b;
if(b < max){
cout<<brr[b][a-1]<<endl;
}
else{
cout<<brr[max][a-1]<<endl;
}
}
}
}