题目链接: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. mysql存储过程 OUT or INOUT argument 3 for routine

    mysql存储过程出现: OUT or INOUT argument 3 for routine gotask.UserLogin is not a variable or NEW pseudo-va ...

  2. 【AutoMapper】实体类间自动实现映射关系,及其转换。

    官方项目下载: http://automapper.codeplex.com/ 博文 http://www.iteye.com/blogs/tag/AutoMapper 图解: 第一步:创建映射Map ...

  3. uva 10994

    一开始想法太简单  错了好多遍 #include <cstdio> #include <cstdlib> #include <cmath> #include < ...

  4. sigleSchool 存储过程例1

    CREATE OR REPLACE PROCEDURE SINGLSCHOOL( PICIID IN VARCHAR2, SCHOOLID IN NUMBER, SCHETYPE IN number, ...

  5. MonoBehaviour.StopCoroutine

    MonoBehaviour.StopCoroutine Description Stops all coroutines named methodName running on this behavi ...

  6. 一个很吊的swing循环生成窗口。

    import javax.swing.*; import java.awt.event.ActionListener; import java.awt.event.ActionEvent; publi ...

  7. 在mac上安装hadoop伪分布式

    换了macbook pro之后,要重新安装hadoop,但是mac上的jdk跟windows上的不同,导致折腾了挺久的,现在分享出来,希望对大家有用. 一:下载jdk 选择最新版本下载,地址:http ...

  8. JsRender系列demo(4)-if else

    <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <m ...

  9. Oracle 9 - redo和undo

    1.redo redo 有在线redo日志和归档redo日志, 从Oracle 10g开始还新增加了flashback技术. 每个Oracle数据库至少有2个在线重做日志组,循环写. 只有INSERT ...

  10. 各种实用的js,bootstrap插件

    1.nivoSlider  非常优秀的Banner轮播插件 2.BootstrapTable 表格插件使用技巧 = http://www.cnblogs.com/landeanfen/p/497683 ...