BZOJ 3578: GTY的人类基因组计划2 STL

本博客介绍了一个模拟GTY的人类基因组计划实验的算法问题,通过调用人员进行房间转移及实验操作来获取实验信息点数。文章提供了一种利用STL的数据结构解决方案。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

3578: GTY的人类基因组计划2

Time Limit: 10 Sec  Memory Limit: 128 MB
Submit: 485  Solved: 206
[Submit][Status][Discuss]

Description

  GTY召唤了n个人来做实验,GTY家的房子很大,有m个房间一开始所有人都在1号房间里,GTY会命令某人去某个房间等待做实验,或者命令一段区间的房间开始实验,实验会获得一些实验信息点数,点数为房间里的人数,如果一个房间里的一群人已经做过实验了那么这些人将不会增加实验信息点数(不会增加是针对这一群人的,不是对这群人中的每个人,即1,2,3做了实验,1,2再做实验还会增加2点实验点数)

Input

第一行两个整数n,m,q(n,m,q<=10^5)表示人数,房间数和操作数
接下来q行每行一个操作 "C i j"表示让第i个人去房间j "W l r" 表示让区间[l,r]的房间做实验

Output

对于每一个W操作,输出一个数,表示此次操作所获得的实验点数

Sample Input

3 5 7
C 1 2
C 2 2
W 1 2
C 3 2
W 1 2
C 3 3
W 1 3

Sample Output

3
3
0

HINT

善用STL


善用STL

膜力传送门

有一点需要说一下

srand()选种子

按照传送门中的方法

一定要用妹子的生日啊


#include<cmath>
#include<ctime>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#include<iomanip>
#include<vector>
#include<string>
#include<bitset>
#include<queue>
#include<set>
#include<map>
using namespace std;

typedef long long ll;

inline int read()
{
	int x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch<='9'&&ch>='0'){x=(x<<1)+(x<<3)+ch-'0';ch=getchar();}
	return x*f;
}
void print(int x)
{if(x<0)putchar('-'),x=-x;if(x>=10)print(x/10);putchar(x%10+'0');}

const int N=100100;

ll gethash(){return (ll(rand())<<15|rand());};

ll hh[N],room[N];

int pos[N],num[N],n,m,q;

map<ll,bool>mp;
set<int>st;

inline void change(int x,int y)
{
	if(pos[x]==y)return;
	st.erase(pos[x]);st.erase(y);
	room[pos[x]]^=hh[x];num[pos[x]]--;
	if(!mp[room[pos[x]]])st.insert(pos[x]);
	pos[x]=y;
	room[y]^=hh[x];num[y]++;
	if(!mp[room[y]])st.insert(y);
}

inline void solve(int l,int r)
{
	int res=0;
	set<int>::iterator it;
	for(it=st.lower_bound(l);it!=st.end()&&*it<=r;it=st.lower_bound(l))
	{mp[room[*it]]=1;res+=num[*it];st.erase(it);}
	print(res);puts("");
}

int main()
{
	srand(2018);
	n=read();m=read();q=read();
	register int i,x,y;                       
	for(i=1;i<=n;++i)
	{hh[i]=gethash();room[1]^=hh[i];pos[i]=1;}num[1]=n;
	st.insert(1);
	char opt[2];
	while(q--)
	{
		scanf("%s",opt);
		x=read();y=read();
		opt[0]=='C'?change(x,y):solve(x,y);
	}
	return 0;
}
/*
3 5 7
C 1 2
C 2 2
W 1 2
C 3 2
W 1 2
C 3 3
W 1 3

3
3
0
*/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值