【codevs 1299】切水果
来源:互联网 发布:网络服务器搭建 编辑:程序博客网 时间:2024/04/27 17:13
1299 切水果
时间限制: 1 s
空间限制: 128000 KB
题目等级 : 大师 Master
题解
题目描述 Description
简单的说,一共N个水果排成一排,切M次,每次切[L,R]区间的所有水果(可能有的水果被重复切),每切完一次输出剩下水果数量
数据已重新装配,不会出现OLE错误
时限和数据范围适当修改,避免数据包过大而浪费空间资源
输入描述 Input Description
第1行共包括2个正整数,分别为N,M。
接下来m行每行两个正整数L,R
输出描述 Output Description
一共输出M行,每行输出切完之后剩下水果数量
样例输入 Sample Input
10 3
3 5
2 8
1 5
样例输出 Sample Output
7
3
2
数据范围及提示 Data Size & Hint
30%的数据满足N,M<=5,000
60%的数据满足N,M<=100,000
100% 的数据满足1<=L<=R<=N<=500,000,1<=M<=500,000
Orz并查集
#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>using namespace std;const int MAXN = 600005;int n,m,f,t,qq,x,y;int ans = 0,tot = 0,fa[MAXN];inline int read(){ int x = 0,f = 1; char ch = getchar(); while(!('0' <= ch && ch <= '9')) { if(ch == '-') f = -1; ch = getchar(); } while('0' <= ch && ch <= '9') { x = x * 10 + (ch - '0'); ch = getchar(); } return x * f;}int find(int x)//从i向右包括i的第一个没有被删除的数字 { return x == fa[x] ? x : fa[x] = find(fa[x]);}bool same(int x,int y){ return find(x) == find(y);}void merge(int x,int y){ x = find(x),y = find(y); fa[x] = y; return;}void init(){ for(int i = 1; i <= n + 1; i ++) fa[i] = i; return;}void change(int l,int r){ for(int i = l; i <= r;) { i = find(i); if(i <= r) merge(i,i + 1),ans --; i = find(i); } return;}int main(){ n = read(),m = read(); init();//输入以后才能更新fa[] ans = n; for(int i = 1; i <= m; i ++) { f = read(),t = read(); if(f < 1) f = 1; if(t > n) t = n; change(f,t); printf("%d\n",ans); } return 0;}
0 0
- Codevs 1299 切水果
- 【codevs 1299】切水果
- 【codevs 1299】切水果
- Codevs 1299 切水果 水一发
- CODEVS PROBLEM1299切水果
- [codevs]: 切水果(线段树)
- Codevs 题目1299 切水果 (线段树)
- CODEVS 1299 切水果(线段树||并查集)
- codevs 切水果(线段树做法)
- 1299 切水果
- 【codevs 3304~3306】水果姐逛水果街系列
- 【线段树】codevs 3304 水果姐逛水果街
- codevs 3304 水果姐逛水果街Ⅰ 题解
- codevs 3304 水果姐逛水果街Ⅰ 解题记录
- codevs 3305 水果姐逛水果街Ⅱ 题解报告
- Codevs 3305 水果姐逛水果街Ⅱ
- Codevs 3304 水果姐逛水果街Ⅰ
- <倍增lca>codevs 3305 水果姐逛水果街Ⅱ
- Android Studio主题设置、颜色背景配置
- mysql主从复制环境搭建
- vim 常用命令示意图
- [转]Linux下调用system()函数导致的问题
- Java 加密 base64 encode
- 【codevs 1299】切水果
- HttpServletRequest和HttpServletResponse对象介绍
- 完全跨域的单点登录SSO
- How to connected to intarnet with ssh proxy in Windows
- DVWA-1.9系列操作之Brute Force
- javascript 中逻辑判断为false的情况
- Java基本概念-JSTL标签
- spark Error initializing SparkContext System memory 466092032 must be at least 471859200.
- Web开发环境搭建 Eclipse