codevs 1191 数轴染色 题解报告
来源:互联网 发布:软件测试基础知识ppt 编辑:程序博客网 时间:2024/04/28 08:11
题目描述 Description
在一条数轴上有N个点,分别是1~N。一开始所有的点都被染成黑色。接着
我们进行M次操作,第i次操作将[Li,Ri]这些点染成白色。请输出每个操作执行后
剩余黑色点的个数。
输入描述 Input Description
输入一行为N和M。下面M行每行两个数Li、Ri
输出描述 Output Description
输出M行,为每次操作后剩余黑色点的个数。
样例输入 Sample Input
10 3
3 3
5 7
2 8
样例输出 Sample Output
9
6
3
数据范围及提示 Data Size & Hint
数据限制
对30%的数据有1<=N<=2000,1<=M<=2000
对100%数据有1<=Li<=Ri<=N<=200000,1<=M<=200000
吃果果的线段树;;
#include<cstdio>#include<iostream>#include<algorithm>#include<cstring>#include<cmath>#include<vector>#include<queue>#include<map>#include<set>#include<stack>#include<cstdlib>#include<string>#include<bitset>#include<iomanip>#include<deque>#define INF 1000000000#define fi first#define se second#define N 100005#define P 1000000007#define debug(x) cerr<<#x<<"="<<x<<endl#define MP(x,y) make_pair(x,y)using namespace std;int n,m;int t[1000010],lazy[1000010]; inline int get_num(){int num = 0;char c;bool flag = false;while ((c = getchar()) == ' ' || c == '\n' || c == '\r');if (c == '-') flag = true;else num = c - '0';while (isdigit(c = getchar()))num = num * 10 + c - '0';return (flag ? -1 : 1) * num;}void build(int x,int l,int r){ if(l==r) { t[x]=1; return; } int mid=(l+r)>>1; build(2*x,l,mid); build(2*x+1,mid+1,r); t[x]=t[2*x]+t[2*x+1];}void find(int x,int l,int r,int q,int w){ if(t[x]==0) return; if(l==q&&r==w) { t[x]=0; return; } int mid=(l+r)>>1; if(mid>=w) { find(2*x,l,mid,q,w); }else { if(mid<q) find(2*x+1,mid+1,r,q,w); else { find(2*x,l,mid,q,mid); find(2*x+1,mid+1,r,mid+1,w); } } t[x]=t[2*x]+t[2*x+1];}int main(){ cin>>n>>m; build(1,1,n); for(int i=1;i<=m;i++) { int q,w; q=get_num(); w=get_num(); find(1,1,n,q,w); cout<<t[1]<<endl; }}
0 0
- codevs 1191 数轴染色 题解报告
- codevs 1191 数轴染色 模拟? 解题报告
- Codevs 1191 数轴染色
- 【codevs 1191】数轴染色
- Codevs 1191 数轴染色
- Codevs 1191 数轴染色
- 【codevs 1191】数轴染色
- Codevs 数轴染色
- Codevs题目1191 数轴染色 (线段树)
- codevs 1191 数轴染色(并查集)
- codevs 1191 数轴染色 (并查集)
- Wikioi-1191-数轴染色
- wiki-1191数轴染色
- 1191 数轴染色
- 1191 数轴染色
- 【CodeVS】1191 数轴染色 分块 线段树 树状数组 平衡树 开放性
- 数轴染色
- 数轴染色
- 最新Mac OS X 10.12.1 安装cocoapods及使用详解
- 安装redis
- 用text-align、vertical-align、line-height进行居中布局
- iOS 第二阶段笔记
- static关键字的作用
- codevs 1191 数轴染色 题解报告
- smdk2440移植、修改、编译kernel笔记
- hdu1878 欧拉回路--入门题
- (leetcode)Valid Parentheses --- 括号匹配问题
- mac 命令行 安装 需要管理员 权限“Please try running this command again as root/Administrator”的解决办法
- Linux上Redis加入服务(开机自启)
- CAS 3.2.1内外网映射问题的解决办法
- python爬虫scrapy安装
- 【神经网络与深度学习】转-caffe安装吐血总结