-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbaoli.cpp
More file actions
47 lines (43 loc) · 873 Bytes
/
Copy pathbaoli.cpp
File metadata and controls
47 lines (43 loc) · 873 Bytes
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
#include <bits/stdc++.h>
using namespace std;
const int N =1e5+10;
int bg[N];
void solve() {
vector<int> a[N];
int n,q;
cin>>n>>q;
for (int i=0;i<n;i++) {
int curr;
cin>>curr;
bg[i]=curr;
}
int j=0;
for (int i=0;i<n;i++) {
a[bg[i]].push_back(i);
}
for (int turn=0;turn<q;turn++) {
int ans =0;
int x,y;
cin>>x>>y;
// if (a[x].empty()||a[y].empty()) {
//
// cout<<0<<'\n';
// return;
// }
for (auto it : a[x]) {
for (int i=0;i<a[y].size();i++) {
if (a[y][i]>it) {
ans+=a[y].size()-i;
break;
}
}
}
cout<<ans+1<<'\n';
}
}
int main () {
ios::sync_with_stdio(0);
cin.tie(0);
solve();
return 0;
}