BZOJ3578 : GTY的人类基因组计划2
关于如何判断一个集合是否出现过:
给每个元素随机一个hash权值,然后xor起来即可
插入删除都只需xor
线段树维护区间有效人数和,以及打标记表示这个区间的集合要全部标记为出现过,并把区间内sum值都置0
写hash用了map被虐了TAT
#include<cstdio>
#include<map>
#define N 100010
#define M 200010
inline void read(int&a){char c;while(!(((c=getchar())>='0')&&(c<='9')));a=c-'0';while(((c=getchar())>='0')&&(c<='9'))(a*=10)+=c-'0';}
int n,m,q,i,j,loc[N];
int tot,l[M],r[M],val[M],sum[M],ran,set[M],hash[N];bool tag[M];
std::map<int,bool>vis;
char ch;
int build(int a,int b){
int x=++tot;
if(a==b)return x;
int mid=(a+b)>>1;
l[x]=build(a,mid);r[x]=build(mid+1,b);
return x;
}
inline void clean(int x,int a,int b){
if(!x)return;
tag[x]=1;sum[x]=0;
if(a==b)vis[set[x]]=1;
}
inline void pb(int x,int a,int b){
if(tag[x]){
int mid=(a+b)>>1;
clean(l[x],a,mid);clean(r[x],mid+1,b);
tag[x]=0;
}
}
inline void up(int x){sum[x]=sum[l[x]]+sum[r[x]];}
void add(int x,int a,int b,int c,int p,int w){
if(a==b){
set[x]^=p;
val[x]+=w;
sum[x]=vis[set[x]]?0:val[x];
return;
}
int mid=(a+b)>>1;
pb(x,a,b);
if(c<=mid)add(l[x],a,mid,c,p,w);else add(r[x],mid+1,b,c,p,w);
up(x);
}
int ask(int x,int a,int b,int c,int d){
int t=0;
if(c<=a&&b<=d){
t=sum[x];
clean(x,a,b);
return t;
}
int mid=(a+b)>>1;
pb(x,a,b);
if(c<=mid)t+=ask(l[x],a,mid,c,d);
if(d>mid)t+=ask(r[x],mid+1,b,c,d);
up(x);
return t;
}
int main(){
read(n),read(m),read(q);
build(1,m);
for(i=1;i<=n;i++)ran*=233,ran+=17,add(1,1,m,loc[i]=1,hash[i]=ran,1);
while(q--){
while(!(((ch=getchar())=='C')||(ch=='W')));
read(i),read(j);
if(ch=='C')add(1,1,m,loc[i],hash[i],-1),add(1,1,m,loc[i]=j,hash[i],1);
else printf("%d\n",ask(1,1,m,i,j));
}
return 0;
}
BZOJ3578 : GTY的人类基因组计划2的更多相关文章
- BZOJ3578:GTY的人类基因组计划2(集合hash,STL)
Description GTY召唤了n个人来做实验,GTY家的房子很大,有m个房间一开始所有人都在1号房间里,GTY会命令某人去某个房间等待做实验,或者命令一段区间的房间开始实验,实验会获得一些实验信 ...
- 【分块】【哈希】bzoj3578 GTY的人类基因组计划2
每个房间用一个集合来维护,具体来说,就是给1-n的数每个数一个long long的hash值,往集合S里insert(i),就是S^=HASH[i]:erase(i),也是S^=HASH[i]. 用m ...
- 【BZOJ-3578】GTY的人类基因组计划2 set + map + Hash 乱搞
3578: GTY的人类基因组计划2 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 367 Solved: 159[Submit][Status][ ...
- NOIP2018 - 暑期博客整理
暑假写的一些博客复习一遍.顺便再写一遍或者以现在的角度补充一点东西. 盛暑七月 初涉基环外向树dp&&bzoj1040: [ZJOI2008]骑士 比较经典的基环外向树dp.可以借鉴的 ...
- bzoj AC倒序
Search GO 说明:输入题号直接进入相应题目,如需搜索含数字的题目,请在关键词前加单引号 Problem ID Title Source AC Submit Y 1000 A+B Problem ...
- CHAPTER 38 Reading ‘the Book of Life’ The Human Genome Project 第38章 阅读生命之书 人体基因组计划
CHAPTER 38 Reading ‘the Book of Life’ The Human Genome Project 第38章 阅读生命之书 人体基因组计划 Humans have about ...
- AI-Info-Micron:人如其食:人工智能和人类微生物组
ylbtech-AI-Info-Micron:人如其食:人工智能和人类微生物组 1.返回顶部 1. 人如其食:人工智能和人类微生物组 “相信你身体发出的信号”,的确是一个很好的建议.研究人员在不遗余力 ...
- 编程的毛病——C++之父访谈
原文见:http://www.technologyreview.com/InfoTech/17831/ 翻译:xeon 11/29/2006 在20世纪的80年代和90年代,Bjarne Strou ...
- 在大型项目上,Python 是个烂语言吗
Robert Love, Google Software Engineer and Manager on Web Search. Upvoted by Kah Seng Tay, I was the ...
随机推荐
- 详解HttpURLConnection
请求响应流程 设置连接参数的方法 setAllowUserInteraction setDoInput setDoOutput setIfModifiedSince setUseCaches setD ...
- LocalResizeIMG前端HTML5本地压缩图片上传,兼容移动设备IOS,android
LocalResizeIMG前端HTML5本地压缩图片上传,兼容移动设备IOS,android jincon 发表于 2015-02-26 18:31:01 发表在: php开发 localresiz ...
- Remove Nth Node From End of List
Given a linked list, remove the nth node from the end of list and return its head. Notice The minimu ...
- c++11之bind
std::bind是个c++推出的新的特性,非常有用,让你写起来率试不爽. #include <iostream> using namespace std; #include <fu ...
- NEFU 2016省赛演练一 B题(递推)
HK Problem:B Time Limit:2000ms Memory Limit:65535K Description yy is interested in numbers and yy nu ...
- Thread源码分析
本文为转载,请珍惜别人的劳动成果,注明转载地址:http://www.cnblogs.com/gw811/archive/2012/10/15/2724602.html 1.Runnable接口源码: ...
- 案例(JQuery的ajax无刷新评论)
CommentsTest.html代码: <head> <meta http-equiv="Content-Type" content="text/ht ...
- 集群管理 secondaryNameNode和NameNode(转)
为了达到以下负责均衡,需要调整以下 改变负载 三台机器,改变负载 host2(NameNode.DataNode.TaskTracker) host6(SecondaryNameNode.DataNo ...
- SQL 查询45题
表格代码 create table student ( sno ) primary key, sname ) not null, ssex ) not null, sbirthday datetime ...
- mysql修改表的存储引擎(myisam<=>innodb)
查看当前数据库的所支持的数据库引擎以及默认数据库引擎 mysql> show engines; +--------------------+---------+----------------- ...