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

来源:互联网 发布:java mainframe 编辑:程序博客网 时间:2024/05/21 17:29

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 7C 1 2C 2 2W 1 2C 3 2W 1 2C 3 3W 1 3330*/