首页 > 其他分享 >POI2008POC-Trains

POI2008POC-Trains

时间:2024-04-15 19:47:26浏览次数:29  
标签:val int res hsh POI2008POC st Trains rep

哈希 #STL #POI #Year2008

对于每个串做 \(hash\) ,每次操作后只对被影响的等价类更新答案

// Author: xiaruize
int n, l, m;
char s[1005][105];
multiset<ull> st;
ull hsh[1005];
int res[1005];

void solve()
{
	cin >> n >> l >> m;
	rep(i, 1, n) cin >> (s[i] + 1);
	rep(i, 1, n)
	{
		ull val = 0;
		rep(j, 1, l) val = val * 13331ull + s[i][j];
		st.insert(val);
		hsh[i] = val;
	}
	rep(i, 1, n) res[i] = st.count(hsh[i]);
	rep(i, 1, m)
	{
		int a, b, c, d;
		cin >> a >> b >> c >> d;
		swap(s[a][b], s[c][d]);
		if (a == c)
		{
			st.erase(st.find(hsh[a]));
			ull val = 0;
			rep(j, 1, l) val = val * 13331ull + s[a][j];
			st.insert(val);
			hsh[a] = val;
			int tmp = st.count(val);
			rep(j, 1, n)
			{
				if (hsh[j] == hsh[a])
					res[j] = max(res[j], tmp);
			}
		}
		else
		{
			st.erase(st.find(hsh[a]));
			st.erase(st.find(hsh[c]));
			ull val = 0;
			rep(j, 1, l) val = val * 13331ull + s[a][j];
			st.insert(val);
			hsh[a] = val;
			val = 0;
			rep(j, 1, l) val = val * 13331ull + s[c][j];
			st.insert(val);
			hsh[c] = val;
			int tmp = st.count(hsh[a]), tmp2 = st.count(hsh[c]);
			rep(j, 1, n)
			{
				if (hsh[j] == hsh[a])
					res[j] = max(res[j], tmp);
				if (hsh[j] == hsh[c])
					res[j] = max(res[j], tmp2);
			}
		}
	}
	rep(i, 1, n) cout << res[i] << endl;
}

#ifndef ONLINE_JUDGE
bool end_of_memory_use;
#endif

signed main()
{
	// freopen(".in","r",stdin);
	// freopen(".out","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int testcase = 1;
	// cin >> testcase;
	while (testcase--)
		solve();
#ifndef ONLINE_JUDGE
	cerr << "Memory use:" << (&end_of_memory_use - &start_of_memory_use) / 1024.0 / 1024.0 << "MiB" << endl;
	cerr << "Time use:" << (double)clock() / CLOCKS_PER_SEC * 1000.0 << "ms" << endl;
#endif
	return 0;
}

标签:val,int,res,hsh,POI2008POC,st,Trains,rep
From: https://www.cnblogs.com/xiaruize/p/18136781

相关文章

  • Codeforces 1621H - Trains and Airplanes
    这能3500?对于一组在\(u\)上的询问,考虑每种线路\(x\),假设\(1\tou\)路径上线路\(x\)的长度为\(len\),那么不难发现收罚款的次数只有两种可能:\(\lfloor\dfrac{len}{T}\rfloor\)或者\(\lfloor\dfrac{len}{T}\rfloor+1\),且对于一个\(v\)满足\(z_u=z_v\)且\(v\)在\(u......
  • Huggingface:trainsformers的PreTrainedTokenizer类
    PreTrainedTokenizer类是所有分词类Tokenizer的基类,这个类不能够被实例化,所有的transformers中预训练模型的分词器(例如BertTokenizer,RoBertaTokenizer)等等都继承自PreT......