其他分享
首页 > 其他分享> > map函数映射 洛谷p1102

map函数映射 洛谷p1102

作者:互联网

 1  #include <iostream>
 2     #include <map>
 3     using namespace std;
 4     typedef long long LL;
 5     LL a[200001];
 6     map<LL,LL> m;//建立一个数字到出现次数的映射 map<num,times>
 7     //A-B=C --> A-C=B
 8     int main() {
 9         int n;
10         LL c;
11         LL ans=0;
12         cin >> n >> c;
13         for(int i=1;i<=n;i++) {
14             cin >> a[i];
15             m[a[i]]++;
16             a[i]-=c;    
17         } 
18         for(int i=1;i<=n;i++) ans+=m[a[i]];
19         cout << ans << endl;
20         return 0;
21 }

 

标签:map,洛谷,p1102,映射,int,LL,long,include
来源: https://www.cnblogs.com/rx-1115/p/15865428.html