I

 1 #include<cstdio>
 2 #include<cstring>
 3 #include<algorithm>
 4 #include<map>
 5 #include<vector>
 6 using namespace std;
 7 const int N=1e5+10;
 8 int n,m;
 9 int a[N];
10 map<int,int>h;
11 
12 int main()
13 {
14     while (~scanf("%d%d",&n,&m)) {
15         h.clear();
16         vector<int>g[N];
17         int tot=0;
18         for (int i=1;i<=n;i++) {
19             scanf("%d",&a[i]);
20             if (h[a[i]]==0) {
21                 h[a[i]]=++tot;
22                 a[i]=tot;
23             }
24             else a[i]=h[a[i]];
25             g[a[i]].push_back(i);
26         }
27         while (m--) {
28             int l,r,x;
29             scanf("%d%d%d",&l,&r,&x);
30             if (h[x]==0) {
31                 printf("0 ");
32                 continue;
33             }
34             x=h[x];
35             l=lower_bound(g[x].begin(),g[x].end(),l)-g[x].begin();
36             r=upper_bound(g[x].begin(),g[x].end(),r)-g[x].begin();
37             printf("%d ",r-l);
38         }
39     }
40     return 0;
41 }
View Code
原文地址:https://www.cnblogs.com/acvc/p/4419861.html