题目描述
blablabla
样例
#include <cstring>
#include <iostream>
using namespace std;
const int N = 100003;
int head[N], son[N], ne[N], idx = 0;
void insert(int x)
{
int k = (x % N + N) % N;
son[idx] = x;
ne[idx] = head[k];
head[k] = idx++;
}
bool Find(int x)
{
int k = (x % N + N) % N;
for (int i = head[k]; i != -1; i = ne[i])
{
if (son[i] == x)
return true;
}
return false;
}
int main()
{
int n;
scanf("%d",&n);
memset(head, -1, sizeof head);
while (n--)
{
char op[2];
int x;
cin >> op >> x;
if (*op == 'I') insert(x);
if (*op == 'Q')
{
if (Find(x)) cout << "Yes" << endl;
else cout << "No" << endl;
}
}
return 0;
}
算法1
(暴力枚举) $O(n^2)$
blablabla
时间复杂度
参考文献
C++ 代码
blablabla
算法2
(暴力枚举) $O(n^2)$
blablabla
时间复杂度
参考文献
C++ 代码
blablabla