hihocoder1079 离散化
思路:
线段树 + 离散化。
测试用例:
3 10
1 10
1 3
6 10
实现:
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pii;
const int N = ;
int tree[N << ], lazy[N << ], a[N]; void init()
{
memset(tree, , sizeof tree);
memset(lazy, , sizeof lazy);
} void pushdown(int num, int cl, int cr)
{
if (!lazy[num]) return;
tree[num << ] = lazy[num] * cl;
tree[num << | ] = lazy[num] * cr;
lazy[num << ] = lazy[num];
lazy[num << | ] = lazy[num];
lazy[num] = ;
} void update(int num, int l, int r, int x, int y, int p)
{
if (x <= l && y >= r) { tree[num] = (r - l + ) * p; lazy[num] = p; return; }
int m = l + r >> ;
pushdown(num, m - l + , r - m);
if (x <= m) update(num << , l, m, x, y, p);
if (y >= m + ) update(num << | , m + , r, x, y, p);
tree[num] = tree[num << ] + tree[num << | ];
} int query(int num, int l, int r, int x, int y)
{
if (x <= l && y >= r) return tree[num];
int m = l + r >> ;
pushdown(num, m - l + , r - m);
int ans = ;
if (x <= m) ans += query(num << , l, m, x, y);
if (y >= m + ) ans += query(num << | , m + , r, x, y);
return ans;
} int main()
{
ios::sync_with_stdio(false);
init();
int n, l, x, y;
cin >> n >> l;
vector<pii> q;
vector<int> v;
for (int i = ; i < n; i++)
{
cin >> x >> y;
q.push_back(pii(x, y));
v.push_back(x); v.push_back(y);
}
sort(v.begin(), v.end());
v.erase(unique(v.begin(), v.end()), v.end());
map<int, int> mp;
for (int i = ; i < v.size(); i++) mp[v[i]] = * i + ;
int ans = , m = v.size() * ;
for (int i = n - ; i >= ; i--)
{
int x = mp[q[i].first], y = mp[q[i].second];
if (query(, , m, x, y) < y - x + ) ans++;
update(, , m, x, y, );
}
cout << ans << endl;
return ;
}
hihocoder1079 离散化的更多相关文章
- hihocoder-1079题解(线段树+离散化)
一.题目链接 http://hihocoder.com/problemset/problem/1079 二.题意 给定一个长度为L的区间,给你n个子区间,没一个区间涂成一种颜色,问最后这个区间内有几种 ...
- NBUT 1457 莫队算法 离散化
Sona Time Limit:5000MS Memory Limit:65535KB 64bit IO Format: Submit Status Practice NBUT 145 ...
- 项目安排(离散化+DP)
题目来源:网易有道2013年校园招聘面试二面试题 题目描述: 小明每天都在开源社区上做项目,假设每天他都有很多项目可以选,其中每个项目都有一个开始时间和截止时间,假设做完每个项目后,拿到报酬都是不同的 ...
- P1774 最接近神的人_NOI导刊2010[树状数组 逆序对 离散化]
题目描述 破解了符文之语,小FF开启了通往地下的道路.当他走到最底层时,发现正前方有一扇巨石门,门上雕刻着一幅古代人进行某种活动的图案.而石门上方用古代文写着“神的殿堂”.小FF猜想里面应该就有王室的 ...
- 洛谷P1462 通往奥格瑞玛的道路[二分答案 spfa 离散化]
题目背景 在艾泽拉斯大陆上有一位名叫歪嘴哦的神奇术士,他是部落的中坚力量 有一天他醒来后发现自己居然到了联盟的主城暴风城 在被众多联盟的士兵攻击后,他决定逃回自己的家乡奥格瑞玛 题目描述 在艾泽拉斯, ...
- POJ1151Atlantis 矩形面积并[线段树 离散化 扫描线]
Atlantis Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 21734 Accepted: 8179 Descrip ...
- POJ2528Mayor's posters[线段树 离散化]
Mayor's posters Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 59683 Accepted: 17296 ...
- HDU 3333 | Codeforces 703D 树状数组、离散化
HDU 3333:http://acm.hdu.edu.cn/showproblem.php?pid=3333 这两个题是类似的,都是离线处理查询,对每次查询的区间的右端点进行排序.这里我们需要离散化 ...
- HDU 3743 Frosh Week (线段树+离散化)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3743 Frosh Week Time Limit : 2000/1000ms (Java/Other) ...
随机推荐
- String常量池
http://developer.51cto.com/art/201106/266454.htm
- [RK3288][Android6.0] 调试笔记 --- pmu(rk818)寄存器读写【转】
本文转载自:http://blog.csdn.net/kris_fei/article/details/76919134 Platform: Rockchip OS: Android 6.0 Kern ...
- Oracle :多实例切换
Connecting to 10.1.4.21:22...Connection established.To escape to local shell, press 'Ctrl+Alt+]'. La ...
- Oracle:impdb导入
最近有现场给我一份用expdp导出dmp文件,我用imp导入时,报错.因为导出dmp的数据库是11g,导入的数据库也是11g, 但客户端安装的是10g,不能用imp导入:所以只能试着用impdp导入: ...
- codeforces 672A A. Summer Camp(水题)
题目链接: A. Summer Camp time limit per test 1 second memory limit per test 256 megabytes input standard ...
- Python机器视觉编程常用数据结构与示例
本文总结了使用Python进行机器视觉(图像处理)编程时常用的数据结构,主要包括以下内容: 数据结构 通用序列操作:索引(indexing).分片(slicing).加(adding).乘(multi ...
- 【Educational Codeforces Round 38 (Rated for Div. 2)】 Problem A-D 题解
[比赛链接] 点击打开链接 [题解] Problem A Word Correction[字符串] 不用多说了吧,字符串的基本操作 Problem B Run for your prize[贪心] ...
- In-App Purchase Programming Guide----(六) ----Working with Subscriptions
Working with Subscriptions Apps that use subscriptions have some additional behaviors and considerat ...
- View Controller Programming Guide for iOS---(二)---View Controller Basics
View Controller Basics Apps running on iOS–based devices have a limited amount of screen space for d ...
- Tomcat调整JVM大小,启动闪退
Tomcat因调整过JVM运存大小,导致闪退:解决方法是: -XX:PermSize -XX:MaxPermSize 值调小些就可以了 set "JAVA_OPTS=-server -Xms ...