BZOJ 3578: GTY的人类基因组计划2 STL
来源:互联网 发布:java mainframe 编辑:程序博客网 时间:2024/05/21 17:29
3578: GTY的人类基因组计划2
Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 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
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
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*/
阅读全文
0 0
- 【bzoj 3578】 GTY的人类基因组计划2(STL的应用)
- bzoj 3578: GTY的人类基因组计划2 (STL+hash)
- BZOJ 3578: GTY的人类基因组计划2 STL
- bzoj 3578: GTY的人类基因组计划2
- BZOJ 3578 GTY的人类基因组计划2 set
- [bzoj3578]GTY的人类基因组计划2(hash+STL)
- bzoj3578: GTY的人类基因组计划2
- [BZOJ3578]GTY的人类基因组计划2(hash+set)
- 【BZOJ】【P3578】【GTY的人类基因组计划2】【题解】【线段树套set or 线段树+set+hash】
- BZOJ 3729 Gty的游戏
- BZOJ 3729: Gty的游戏
- [Splay] BZOJ 3729 Gty的游戏
- BZOJ 3720 gty的妹子树
- [倍增 堆] BZOJ 4458 GTY的OJ
- BZOJ 3720 Gty的妹子树
- BZOJ P3744 Gty的妹子序列
- BZOJ 3744: Gty的妹子序列
- bzoj 3720: Gty的妹子树
- [FAQ14357]MT8127/MT8163 如何开启WITH_PREODEX功能
- 算法题/最小的k个数
- span中文本内容有空格会自动换行(某些Android手机)
- sudo 出现unable to resolve host 解决方法
- JavaEE面试题2
- BZOJ 3578: GTY的人类基因组计划2 STL
- Nginx入门案例(Mac版)
- 第11章 晚期(运行期)优化
- 常用端口及其所代表的协议
- BZOJ2034最大收益 [贪心优化特殊图最优匹配]
- ApplicationContext AlertDialog IllegalStateException: You need to use a Theme.AppCompat theme
- genericity(泛型)
- ios多线程浅谈和使用
- AutoCAD 记录