好
2025-06-30 22:59:39
发布于:广东
26阅读
0回复
0点赞
众嗦粥汁,如果按题意暴力模拟(即记录所有出现的数,没出现的更新为0)的话,肯定会超时。
但是,STL 有一个神级卡常数据结构:bitset!如果对整个 bitset 进行位运算的话,时间复杂度可以除一个 。至于这个数是多少得看评测机位数。显然ACGO评测机是  位的,所以 。
我们惊奇的发现:这样子暴力竟然能过!甚至更新 bitset 比输入还快。
#include <iostream>
#include <cstdio>
#include <bitset>
using namespace std;
bitset <100001> bits, tmp;
int n, m;
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0), cout.tie(0);
	cin >> n >> m;
	bits.set();
	for(int i = 1; i <= n; i++){
		tmp.reset();
		for(int j = 1; j <= m; j++){
			int x;
			cin >> x;
			tmp.set(x);
		}
		bits &= tmp;
	}
	cout << bits.count();
	return 0;
}
时间复杂度:。
全部评论 1
- %%% - 2025-07-03 来自 浙江 0












有帮助,赞一个