第四个点RE,求大佬?
  • 板块P1102 A-B 数对
  • 楼主leoluuu
  • 当前回复0
  • 已保存回复0
  • 发布时间2024/3/12 14:55
  • 上次更新2024/3/12 14:55:35
查看原帖
第四个点RE,求大佬?
914594
leoluuu楼主2024/3/12 14:55
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5+10;
#define int long long
map<int,int> ma;
int arr[N];
int tmp;
int cnt ;
// 没说是有序的!!!先排序
signed main(){
    int n,m;
    scanf("%lld%lld",&n,&m);
    for(int i=0;i<n;++i){
        scanf("%d",&tmp);
        if(ma.find(tmp)==ma.end()){
            ma[tmp]=1;arr[cnt++] = tmp;
        }else ma[tmp]++;
        
    }
    sort(arr,arr+cnt);
    int j=1;
    int ans = 0;
    for(int i=0;i<cnt;++i){
        
        while(arr[j]-arr[i]<m){
            j++;
        }
        if(arr[j]-arr[i]==m){
            ans += ma[arr[i]]*ma[arr[j]];
        }
        //cout<<i<<" "<<j<<" "<<ans<<endl;
    }
    cout<<ans<<endl;
    return 0;
}
2024/3/12 14:55
加载中...