题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4022

  一个图上有n个点,之后m个操作,每次操作一行或者一列。使得这一行或者这一列的点全部消除。每次操作输出每次消除的点的个数。

思路:

  因为数据范围很大,刚开始想的是离散化后维护各行各列的点数,但是发现这样离线的做法只能维护当前状态,更新成了一个难题。后来在思考有没有一个方法,可以在不超过数据范围的情况下,在O(lgn)的限制内维护所有线上的坐标。想来想去,一开始想用map<int, vector<int>>的,但是vector扫描是O(n)的。那就要考虑一个非线性结构,最后想到了红黑树。还是保存重复元素的那个——std::multiset<int>。

  所以这道题就变成了一道水题了。

 #include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <climits>
#include <complex>
#include <fstream>
#include <cassert>
#include <cstdio>
#include <bitset>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <ctime>
#include <set>
#include <map>
#include <cmath> using namespace std; #define fr first
#define sc second
#define pb(a) push_back(a)
#define Rint(a) scanf("%d", &a)
#define Rll(a) scanf("%I64d", &a)
#define Rs(a) scanf("%s", a)
#define FRead() freopen("in", "r", stdin)
#define FWrite() freopen("out", "w", stdout)
#define Rep(i, n) for(int i = 0; i < (n); i++)
#define For(i, a, n) for(int i = (a); i < (n); i++)
#define Cls(a) memset((a), 0, sizeof(a))
#define Full(a) memset((a), 0x7f7f, sizeof(a)) const int maxn = ;
int n, m;
int x[maxn], y[maxn];
int hx[maxn], hxcnt;
int hy[maxn], hycnt;
int sx[maxn], sy[maxn];
map<int, multiset<int> > xx;
map<int, multiset<int> > yy;
multiset<int>::iterator it; inline bool scan_d(int &num) {
char in;bool IsN=false;
in=getchar();
if(in==EOF) return false;
while(in!='-'&&(in<''||in>'')) in=getchar();
if(in=='-'){ IsN=true;num=;}
else num=in-'';
while(in=getchar(),in>=''&&in<=''){
num*=,num+=in-'';
}
if(IsN) num=-num;
return true;
} int getid(int* h, int hcnt, int x) {
return lower_bound(h, h+hcnt, x) - h;
} int main() {
// FRead();
int c, d;
while(~scanf("%d%d", &n, &m) && n + m) {
Cls(sx); Cls(sy); xx.clear(), yy.clear();
Rep(i, n) {
scan_d(x[i]); scan_d(y[i]);
hx[i] = x[i]; hy[i] = y[i];
xx[x[i]].insert(y[i]);
yy[y[i]].insert(x[i]);
}
sort(hx, hx+n); sort(hy, hy+n);
hxcnt = unique(hx, hx+n) - hx;
hycnt = unique(hy, hy+n) - hy;
Rep(i, n) {
sx[getid(hx, hxcnt, x[i])]++;
sy[getid(hy, hycnt, y[i])]++;
}
Rep(i, m) {
scan_d(c); scan_d(d);
if(c == ) {
printf("%d\n", xx[d].size());
for(it = xx[d].begin();
it != xx[d].end(); it++) {
yy[*it].erase(d);
}
xx[d].clear();
sx[getid(hx, hxcnt, d)] = ;
}
else {
printf("%d\n", yy[d].size());
for(it = yy[d].begin();
it != yy[d].end(); it++) {
xx[*it].erase(d);
}
sy[getid(hy, hycnt, d)] = ;
yy[d].clear();
}
}
printf("\n"); }
return ;
}

[HDOJ4022]Bombing(离散化+stl)的更多相关文章

  1. HDU 4022 Bombing(stl,map,multiset,iterater遍历)

    题目 参考了     1     2 #define _CRT_SECURE_NO_WARNINGS //用的是STL中的map 和 multiset 来做的,代码写起来比较简洁,也比较好容易理解. ...

  2. Educational Codeforces Round 10 D. Nested Segments 【树状数组区间更新 + 离散化 + stl】

    任意门:http://codeforces.com/contest/652/problem/D D. Nested Segments time limit per test 2 seconds mem ...

  3. 洛谷 [P1995] 程序自动分析

    并查集+ 离散化 首先本题的数据范围很大,需要离散化, STL离散化代码: //dat是原数据,id是编号,sub是数据的副本 sort(sub + 1, sub + tot + 1); size = ...

  4. 数据离散化 ( 以及 stl 中的 unique( ) 的用法 )+ bzoj3289:Mato的文件管理

    http://blog.csdn.net/gokou_ruri/article/details/7723378 ↑惯例Mark大神的博客   bzoj3289:Mato的文件管理 线段树求逆序对+莫队 ...

  5. HDU4022 Bombing STL

    Bombing Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65768/65768 K (Java/Others) Total Su ...

  6. 离散化——化不可能为可能(STL)

    所谓离散,就是化连续为不连续,使得我们某种枚举的方法得以实现. 当然,离散还能够帮助我们将某些数据范围很大达到2^16,但是这些数据并不多(例如才1000+),我们可以把数据进行离散,保持他们之间的相 ...

  7. 使用STL离散化

    把原来的数组a复制一份拷贝b 用sort先把数组a排序 用unique消除a里面重复的元素 对于b中的每一个元素,用lower_bound找到它在a中的位置,也就是离散化之后的编号. 没了. #inc ...

  8. UVa 221 (STL 离散化) Urban Elevations

    题意: 作图为n个建筑物的俯视图,右图为从南向北看的正视图,按从左往右的顺序输出可见建筑物的标号. 分析: 题中已经说了,要么x相同,要么x相差足够大,不会出现精度问题. 给这n个建筑物从左往右排序, ...

  9. CDOJ 1059 秋实大哥与小朋友 STL(set)+离散化+BIT区间更新单点查询

    链接: A - 秋实大哥与小朋友 Time Limit:1000MS     Memory Limit:65535KB     64bit IO Format:%lld & %llu Subm ...

随机推荐

  1. Lightmapping

    当游戏场景包含了大量的多边形时,实时光源和阴影对游戏性能的影响会很大.这时更适合使用Lightmapping技术,将光线效果预渲染成贴图使用到多边形上模拟光影效果.这种方式不用担心光源数量和阴影对性能 ...

  2. How to Implement Bluetooth Low Energy (BLE) in Ice Cream Sandwich

    ShareThis - By Vikas Verma Bluetooth low energy (BLE) is a feature of Bluetooth 4.0 wireless radio t ...

  3. Android SDK Android NDK 官方下载地址

    Android NDK r6b Windows http://dl.google.com/android/ndk/android-ndk-r6b-windows.zip Mac OS X(intel) ...

  4. Learn know more about big data

    As we all know,we are in a big data age now."Every sword has two slides",as a ITer,we shou ...

  5. 使用Lucene.net提升网站搜索速度整合记录

    1.随着网站数据量达到500万条的时候,发现SQL数据库如果使用LIKE语句来查询,总是占用CPU很忙,不管怎么优化,速度还是上不来; 2.经过网上收集资料,HUBBLE.net目前虽然做得不错,但需 ...

  6. 在云服务器搭建WordPress博客(五)创建和管理文章分类

    不同主题的文章划分到不同的分类,有助于访客寻找他们想要的内容,提高用户体验.所以,为你的网站创建文章分类是很有必要的.那么,WordPress系统如何创建和管理文章分类呢?今天倡萌就简单介绍一下. 创 ...

  7. sublime package

    Sublime text 2/3 中 Package Control 的安装与使用方法 2014/05/23前端工具, 工具, 教程, 软件4条评论 Package Control 插件是一个方便 S ...

  8. firefox常用扩展、脚本

    1.AutoPopup.uc.js:鼠标移到菜单和下拉箭头上自动弹出下拉菜单 2.moveButton.uc.js:移动或克隆按钮或菜单到火狐浏览器的任意位置 moveButton.uc.js使用说明 ...

  9. mysql 执行流程

    mysql 执行流程 我们可以人为的把mysql 的主要功能分为如下模块. 1.初始化模块 mysql启动的时候执行初始化工作,如读取配置文件,分配一些全局变量(sql_model,catch buf ...

  10. 【BZOJ】【1834】【ZJOI2010】Network 网络扩容

    网络流/费用流 这题……我一开始sb了. 第一问简单的最大流…… 第二问是要建费用流的图的……但是是在第一问的最大流跑完以后的残量网络上建,而不是重建…… 我们令残量网络上原有的弧的费用全部为0(因为 ...