文章

1

粉丝

0

获赞

2

访问

32

头像
差分计数 题解:hash算法
P1907 华东师范大学2022年机试
发布于2025年8月13日 14:32
阅读数 32

#include <bits/stdc++.h>
using namespace std;

int main(){
    int bound=2000000;
    int n,x;
    cin>>n>>x;
    int p;
    int ans=0;
    vector<int>hash(2*bound+1,0);
    for(int i=0;i<n;i++){
        cin>>p;
        p=p+bound;
        int m=p+x;
        if(m>=1&&m<=2*bound){
            ans+=hash[m];    
        }
        m=p-x;
        if(m>=1&&m<=2*bound){
            ans+=hash[m];    
        }
        if(p>...

登录查看完整内容


登录后发布评论

暂无评论,来抢沙发