2e5+10吧?
要开long long
by Dreamer_002 @ 2023-10-17 06:48:39
不用开long long
by Dreamer_002 @ 2023-10-17 06:51:14
@[zhongruqian](/user/639449) 试了一下,好像有一个数据res会爆int,而且我想问的是用unordered_map为什么不对呢。那个N本题没用到诶
by zxyall @ 2023-10-17 13:15:38
@[zxyall](/user/1067001)
```cpp
int x;scanf("%lld",&x);
```
有问题吧?2
by Dreamer_002 @ 2023-10-17 17:32:51
@[zxyall](/user/1067001)
```cpp
int res=0;
```
这行也是
by Dreamer_002 @ 2023-10-17 17:34:31
不好意思刚才没测,您WA的代码能给我看一下吗?
by Dreamer_002 @ 2023-10-17 17:39:34
@[zhongruqian](/user/639449) #define int long long 偷懒写法(
by zxyall @ 2023-10-18 13:02:54
@[zhongruqian](/user/639449) 就是把map改成unordered_map
```
#include <iostream>
#include <cstring>
#include <algorithm>
#include <unordered_map>
using namespace std;
#define int long long
const int N = 1e5+10;
unordered_map<int,int>m;
int n,c;
signed main(){
cin>>n>>c;
for(int i=0;i<n;i++){
int x;scanf("%lld",&x);
m[x]++;
}
int res=0;
for(auto x:m){
res+=m[x.first-c]*m[x.first];
}
cout<<res;
return 0;
}
```
原来代码是AC代码
by zxyall @ 2023-10-18 13:05:42
[https://blog.csdn.net/qq_45890970/article/details/123955261](https://blog.csdn.net/qq_45890970/article/details/123955261)
by Dreamer_002 @ 2023-10-18 17:32:46
```cpp
#include<iostream>
#include<cstdio>
#include<unordered_map>
using namespace std;
const int N = 10000005;///10000005
long long a[N];
int n,c;
unordered_map<long long,long long> m;
int main()
{
scanf("%d%d",&n,&c);
for(int i=1;i<=n;i++)
{
scanf("%lld",&a[i]);
m[a[i]]++;
a[i]=a[i]-c;
}
long long ans=0;
for(int i=1;i<=n;i++)
{
ans+=m[a[i]];
}
printf("%lld\n",ans);
return 0;
}
```
过了!
by Dreamer_002 @ 2023-10-18 17:38:00