点数很多,坐标值很大,然后离散化一下用一个点表示一小块的面积对应的颜色,然后更新的时候一块一块更新,查询的时候一块一块查询

#include<map>
#include<set>
#include<ctime>
#include<cmath>
#include<stack>
#include<queue>
#include<string>
#include<vector>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#define lowbit(x) (x & (-x)) typedef unsigned long long int ull;
typedef long long int ll;
const double pi = 4.0*atan(1.0);
const int inf = 0x3f3f3f3f;
const int maxn = ;
const int maxm = ;
const int mod = 1e9+;
using namespace std; int n, m;
int T, tol;
struct Node {
int x1, y1;
int x2, y2;
int w;
};
Node node[maxn];
int X[maxn];
int Y[maxn];
int maps[maxn][maxn];
int ans[maxn]; void init() {
memset(X, , sizeof X);
memset(Y, , sizeof Y);
memset(ans, , sizeof ans);
memset(node, , sizeof node);
memset(maps, , sizeof maps);
} int main() {
int cas = ;
while(scanf("%d%d", &n, &m), n||m) {
if(cas != ) printf("\n");
init();
int q;
scanf("%d", &q);
int cx = , cy = ;
int x1, y1, x2, y2, w;
int mw = ;
for(int i=; i<=q; i++) {
scanf("%d%d%d%d%d", &x1, &y1, &x2, &y2, &w);
X[cx++] = x1, Y[cy++] = y1;
X[cx++] = x2, Y[cy++] = y2;
node[i].x1 = x1, node[i].y1 = y1;
node[i].x2 = x2, node[i].y2 = y2;
node[i].w = w;
mw = max(mw, w);
}
sort(X, X+cx);
sort(Y, Y+cy);
cx = unique(X, X+cx) - X;
cy = unique(Y, Y+cy) - Y;
// for(int i=0; i<cx; i++) printf("%d%c", X[i], i==cx-1 ? '\n' : ' ');
// for(int i=0; i<cy; i++) printf("%d%c", Y[i], i==cy-1 ? '\n' : ' ');
// printf("\n");
for(int i=; i<=q; i++) {
x1 = lower_bound(X, X+cx, node[i].x1) - X;
x2 = lower_bound(X, X+cx, node[i].x2) - X;
y1 = lower_bound(Y, Y+cy, node[i].y1) - Y;
y2 = lower_bound(Y, Y+cy, node[i].y2) - Y;
// printf("%d %d %d %d\n", x1, y1, x2, y2);
for(int x=x1; x<x2; x++) {
for(int y=y1; y<y2; y++) {
maps[x][y] = node[i].w;
}
}
}
// printf("\n");
// for(int i=0; i<cx; i++) for(int j=0; j<cy; j++) printf("%d%c", maps[i][j], j==cy-1 ? '\n' : ' ');
for(int i=; i<cx; i++) {
for(int j=; j<cy; j++) {
if(!maps[i][j]) continue;
w = maps[i][j];
int area = (X[i+] - X[i]) * (Y[j+] - Y[j]);
ans[w] += area;
}
}
tol = ;
printf("Case %d:\n", cas++);
for(int i=; i<=mw; i++) {
if(ans[i]) {
printf("%d %d\n", i, ans[i]);
tol++;
}
}
if(tol <= ) printf("There is %d color left on the wall.\n", tol);
else printf("There are %d colors left on the wall.\n", tol);
}
return ;
}

Paint the Wall ZOJ - 2747的更多相关文章

  1. HDU 4391 Paint The Wall(分块+延迟标记)

    Paint The Wall Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  2. 线段树 扫描线 L - Atlantis HDU - 1542 M - City Horizon POJ - 3277 N - Paint the Wall HDU - 1543

    学习博客推荐——线段树+扫描线(有关扫描线的理解) 我觉得要注意的几点 1 我的模板线段树的叶子节点存的都是 x[L]~x[L+1] 2 如果没有必要这个lazy 标志是可以不下传的 也就省了一个pu ...

  3. ZOJ 2747 Paint the Wall(离散化+暴力)题解

    题意:给你一个面,然后涂颜色,问你最后剩多少颜色,每种颜色面积. 思路:第一反应是二维线段树,代码又臭又长,可以做.但是这题暴力+离散化就可以过.可以看到他给的n只有100,也就是说最坏情况下会涂10 ...

  4. 【HDU4391】【块状链表】Paint The Wall

    Problem Description As a amateur artist, Xenocide loves painting the wall. The wall can be considere ...

  5. hdu 1543 Paint the Wall

    http://acm.hdu.edu.cn/showproblem.php?pid=1543 #include <cstdio> #include <cstring> #inc ...

  6. 【分段哈希】H. Paint the Wall

    https://www.bnuoj.com/v3/contest_show.php?cid=9147#problem/H [题意] 在一个长为H,宽为W的白墙上选一个矩形区域涂颜色,后涂的颜色会覆盖先 ...

  7. HDU 4391 - Paint The Wall - 分块哈希入门

    题目链接 : http://acm.hdu.edu.cn/showproblem.php?pid=4391 题意 : 给一段区间, 有两种操作 1 : 给 x 到 y 的区间染色为 z 2 : 查询 ...

  8. HDU 4391 Paint The Wall 段树(水

    意甲冠军: 特定n多头排列.m操作 以下是各点的颜色 以下m一种操纵: 1 l r col 染色 2 l r col 问间隔col色点 == 通的操作+区间内最大最小颜色数的优化,感觉非常不科学... ...

  9. HDU 4391 Paint The Wall(分块的区间维护)

    题意:给出几个操作,把l-r赋值为z,询问l-r有几个z,其中z < INT_MAX 思路:因为z很大,所以很难直接用线段树去维护.这里可以使用分块来解决.我们可以让每个块用map去储存map[ ...

随机推荐

  1. Docker存储驱动Device Mapper,Overlay,AUFS

    Docker存储驱动之Device Mapper简介 - BookShu - 博客园https://www.cnblogs.com/styshoo/p/6528762.html Docker存储驱动之 ...

  2. Linux的基本解读

    Linux是一套免费使用和自由传播的类Unix操作系统,是一个基于POSIX和UNIX的多用户.多任务.支持多线程和多CPU的操作系统 而严格来讲,Linux这个词本身只表示Linux内核,但实际上人 ...

  3. array_filter与array_map

    php数组array_filter函数和array_slice函数:<?php /* array_filter()用回调函数过滤数组中的单元 array_filter(array,functio ...

  4. vue2.0生命周期

    https://www.cnblogs.com/goloving/p/8616989.html(copy )

  5. spark-shell简单使用介绍(scala)

    >>提君博客原创  http://www.cnblogs.com/tijun/  << 提君博客原创 1.进入命令窗口 ./bin/spark-shell 附上帮助指令,查看一 ...

  6. 打印module查看参数

    module1下的index.js require('./test2') main.js require('./module1')和require('./module2') 打印每个文件的module ...

  7. 所活天数!java Date应用

    package cn.jiu.com; import java.text.ParseException; import java.text.SimpleDateFormat; import java. ...

  8. 使用JAVA获取JSON报文

    基本JSON格式: { "name": "liming", "age": "13", "array" ...

  9. source 和 .

    Linux Source命令及脚本的执行方式解析 当我修改了/etc/profile文件,我想让它立刻生效,而不用重新登录:这时就想到用source命令,如:source /etc/profile 对 ...

  10. 将自己的ubuntu18.04打包成镜像

    将自己的ubuntu18.04打包成镜像 2018年11月10日 10:40:06 舌耳 阅读数:1590 先下载remastersys wget ftp://ftp.gwdg.de/pub/linu ...