LightOJ 1089 Points in Segments (II) 离散化 标记
2016-02-27 19:40
351 查看
题目
题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=26806题目来源:2016.2.26ACM群赛
简要题意:给定一些一维线段,问某点处被线段覆盖了多少次。
题解
aia_i的范围小些,就只需要在lil_i处+1+1,ri+1r_i+1处−1-1然后做个前缀就行了。于是只要把数据的li,ri+1l_i,r_i+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 second using namespace std; typedef long long LL; typedef pair<int,int> PII; // head const int N = 5e4+5; PII a ; 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; }
相关文章推荐
- 三种ViewController跳转的异同
- java JDBC 数据库 事务 ACID
- atitit.atiOrmStoreService 框架的原理与设计 part1 概述与新特性
- Java之集合框架
- atitit.atiOrmStoreService 框架的原理与设计 part1 概述与新特性
- 深入理解计算机系统-之-内存寻址(六)--linux中的分页机制
- atitit.atiOrmStoreService 框架的原理与设计 part1 概述与新特性
- Python的zip函数
- 摄像机震动 脚本
- Atitit.code base view 视图的实现原理
- ACdream 1112 Alice and Bob (博弈&&素数筛选优化)
- 两个版本的python在同一系统下的安装
- Atitit.code base view 视图的实现原理
- marshmallow (博弈论)
- poj 2533 Longest Ordered Subsequence
- Atitit.code base view 视图的实现原理
- html5 postMessage解决跨域、跨窗口消息传递
- Emergency relief (枚举+状态压缩)
- leetcode:字符串
- Struts2学习笔记之自定义转换器