寄包柜

题目

看了不少洛谷的题解,基本都是用了STL解决此题

考虑到内存问题,想到哈希

#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
using namespace std;
const int HASH = 211,N = 3e7 + 10;
int a[N],n,q,opt,x,y,z;
inline int read()
{
    int x=0,w=1; char c=getchar();
    while (c>'9'||c<'0') {if (c=='-') w=-1; c=getchar();}
    while (c<='9'&&c>='0') {x=(x<<1)+(x<<3)+c-'0'; c=getchar();}
    return w*x;
}
int main()
{
    n=read(); q=read();
    while (q--)
    {
        opt=read();
        if (opt==1) {
            x=read(); y=read(); z=read();
            a[x*HASH+y*19]=z;
        }
        else {
            x=read(); y=read();
            printf("%d\n",a[x*HASH+y*19]);
        }
    }
    return 0;
}

  第一次下标只加了y,20分,被hack掉了

  第二次y乘了19,AC

posted @ 2022-08-17 16:09  LyingFlat666  阅读(18)  评论(0编辑  收藏  举报