--- title: "集合询问" created: 2025-11-28 tags: - 算法 --- # 集合询问 ## 题目 [集合询问](https://www.acwing.com/problem/content/description/4607/) ![[image-befa5164.png]] ## 思路分析 反过来想 把每个串变成01序列的形式 再拿01序列做询问 又是键值 计数 可以用值做下标写 也可以unordered\_map写 ## 代码实现 ```cpp #include using namespace std; unordered_map h; int n; int main() { cin>>n; char op[2],str[20]; while(n--){ cin>>op>>str; int x=0; for(int i=0;str[i];i++) x=x*2+((str[i]-'0')&1); if(*op=='+') h[x]++; else if(*op=='-') h[x]--; else cout< using namespace std; const int N=1<<18; int cnt[N]; int n; int main() { cin>>n; char op[2],str[20]; while(n--){ cin>>op>>str; int x=0; for(int i=0;str[i];i++) x=x*2+((str[i]-'0')&1); if(*op=='+') cnt[x]++; else if(*op=='-') cnt[x]--; else cout<