LightOJ 1089 Points in Segments (II) 离散化 标记
来源:互联网 发布:网络搜索优化方案 编辑:程序博客网 时间:2024/05/19 06:47
题目
题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=26806
题目来源:2016.2.26ACM群赛
简要题意:给定一些一维线段,问某点处被线段覆盖了多少次。
题解
ai 的范围小些,就只需要在li 处+1 ,ri+1 处−1 然后做个前缀就行了。于是只要把数据的
li,ri+1 排序然后离散化就行了。了解相关的方法可以比较快写出,一道典型的乱搞题。
代码
#include <iostream>#include <cstdio>#include <cmath>#include <algorithm>#include <cstring>#include <stack>#include <queue>#include <string>#include <vector>#include <set>#include <map>#define fi first#define se secondusing namespace std;typedef long long LL;typedef pair<int,int> PII;// headconst int N = 5e4+5;PII a[N];int dis[N*2];int res[N*2];int main() { int t, n, q, x, cas = 1; scanf("%d", &t); while (t--) { memset(res, 0, sizeof res); scanf("%d%d", &n, &q); int cnt = 0; for (int i = 0; i < n; i++) { scanf("%d%d", &a[i].fi, &a[i].se); a[i].se++; dis[cnt++] = a[i].fi; dis[cnt++] = a[i].se; } dis[cnt++] = 0; dis[cnt++] = 1e8+5; sort(dis, dis + cnt); int m = unique(dis, dis + cnt) - dis; for (int i = 0; i < n; i++) { int l = lower_bound(dis, dis + m, a[i].fi) - dis; int r = lower_bound(dis, dis + m, a[i].se) - dis; res[l]++; res[r]--; } for (int i = 1; i < m; i++) { res[i] += res[i-1]; } printf("Case %d:\n", cas++); while (q--) { scanf("%d", &x); int pos = upper_bound(dis, dis + m, x) - dis - 1; printf("%d\n", res[pos]); } } return 0;}
0 0
- LightOJ 1089 Points in Segments (II) 离散化 标记
- [线段树+离散化]LightOJ 1089 - Points in Segments (II)
- LightOJ--1089 - Points in Segments (II)
- LightOJ - 1088 Points in Segments
- Lightoj 1088 - Points in Segments 【二分】
- LightOJ 1088 - Points in Segments (二分)
- Points in Segments (II)(线段树)
- LOJ 1088 Points in Segments
- UVA 10869 - Brownie Points II(树状数组+离散化)
- lighoj 1088 Points in Segments | 二分
- 二分法应用--light oj1088 Points in Segments
- lightoj 1089 【离散化+线段树】
- LightOJ-1089-线段树,离散化
- [树状数组]LightOJ 1266 - Points in Rectangle
- c++二分法简单应用(Points in Segments)
- Light OJ 1088 Points in Segments-二分(水)
- bnu36905 Nested Segments 离散化+线段树
- LightOJ 1112 Curious Robin Hood && LightOJ 1266 Points in Rectangle(树状数组)
- 使用Python的SnowNLP模块实现情感分析
- 主成分分析法
- Atitit.code base view 视图的实现原理
- win10java环境配置
- Hanoi Tower Troubles Again! (找规律)
- LightOJ 1089 Points in Segments (II) 离散化 标记
- 263. Ugly Number
- BlueTooth: 蓝牙协议栈实现模式分析
- Struts2入门~工作原理及访问Servlet API
- Knots (组合数学)
- HDU 3078Network (LCA)
- Internet Explorer 升级到IE11遇到问题案例分析
- leetcode:字符串
- Emergency relief (枚举+状态压缩)