洛谷 2184
来源:互联网 发布:red hat linux发展史 编辑:程序博客网 时间:2024/06/04 17:55
这道题我们可以把它抽象成一个更直观的模型,有2种操作,一种是添加一条[l,r]的线段,另一种是查询与[l,r]线段相交的线段数。怎么维护呢?我们可以将一条[l,r]的线段看成是(l,0)和(r,0)两个点,那么对于一次查询,我们只需知道l左边有多少个右端点,r右边有多少个左端点,以这些点为端点的线段是一定不与[l,r]的线段相交的,剩下的就一定是相交的,这样我们需要的操作就是单点修改,区间查询,用树状数组就可以了。
#include<cstdio>#include<cstring>#include<algorithm>using namespace std;#define maxn 100005int n,m,tot;int c[maxn][2];void add(int x,int p){ for (;x<=n;x+=(x&(-x))) c[x][p]++;}int query(int x,int p){ int ans=0; for (;x>=1;x-=(x&(-x))) ans+=c[x][p]; return ans; }int main(){ scanf("%d%d",&n,&m); for (int i=1;i<=m;i++) { int opt,l,r; scanf("%d%d%d",&opt,&l,&r); if (opt==1) { add(l,0); add(r,1); tot++; } else printf("%d\n",tot-query(l-1,1)-query(n,0)+query(r,0)); } return 0; }
0 0
- 洛谷 2184
- poj 2184
- POJ 2184:
- poj 2184
- PKU 2184
- poj 2184
- 洛谷
- 洛谷
- 洛谷
- pku 2184 Cow Exhibition
- HDU 2184 汉诺塔VIII
- poj 2184 Cow Exhibition
- POJ 2184 Cow Exhibition
- Poj 2184 Cow Exhibition
- poj 2184 背包变形
- poj 2184 Cow Exhibition
- 2184 cow exhibition
- poj 2184 Cow Exhibition
- 数据库
- Hibernate(一)环境搭建
- 【转】——Jade 模板引擎使用
- Android 图片框架的比较
- 配置colorAccent,colorPrimary,colorPrimaryDark,toolbar主题颜色
- 洛谷 2184
- 什么是 Landing Page?
- 【24.63%】【codefroces 686D】Kay and Snowflake
- 关于IE浏览器下面路径跳转问题
- Golden Goose Superstar mist snow smiled to
- ztree异步加载数据
- eclipse4.3里修改项目在tomcat中的上下文访问路径和部署路径
- CentOS nginx django uwsgi mysql 部署项目
- Spring源码阅读-DefaultListableBeanFactory的属性注释翻译