80分代码求纠错

P3613 【深基15.例2】寄包柜

tianyuyang @ 2021-08-27 09:16:32

#include<bits/stdc++.h>
using namespace std;
struct MAXN{
    long long a;
    long long i;
    long long j;
}hashing[500100];
long long p=0;
long long find1(long long key1,long long key2){
    p=(key1+key2)%500000;
    while(1){
        if(hashing[p].a==0){
            return 0;
        }
        if((hashing[p].i==key1)&&(hashing[p].j==key2)){
            return p;
        }
        p++;
    }
}
long long ans[500001];
int main(){
    memset(ans,-1,sizeof(ans));
    long long n,q;
    cin>>n>>q;
    int pd,i,j,k;
    int h=0;
    for(long long y=0;y<q;y++){
        cin>>pd;
        if(pd==1){
            cin>>i>>j>>k;
            find1(i,j);
            hashing[p].a=k;
            hashing[p].i=i;
            hashing[p].j=j;
            continue;
        }
        if(pd==2){
            cin>>i>>j;
            find1(i,j);
            ans[h]=hashing[p].a;
            h++;
            continue;
        }
    }
    for(int y=0;ans[y]!=-1;y++)cout<<ans[y]<<endl;
    return 0;
}

by Leon1995 @ 2021-09-03 19:03:39

if(hashing[p].a==0){ return 0; }

读取的k值可能为0,hashing[p].a存的是k值


|