Problem Description

You have a big farm, and you want to grow vegetables in it. You're too lazy to seed the seeds yourself, so you've hired n people to do the job for you.
Each person works in a rectangular piece of land, seeding one seed in one unit square. The working areas of different people may overlap, so one unit square can be seeded several times. However, due to limited space, different seeds in one square fight each other -- finally, the most powerful seed wins. If there are several "most powerful" seeds, one of them win (it does not matter which one wins).

There are m kinds of seeds. Different seeds grow up into different vegetables and sells for different prices. 
As a rule, more powerful seeds always grow up into more expensive vegetables.
Your task is to calculate how much money will you get, by selling all the vegetables in the whole farm.

Input

The first line contains a single integer T (T <= 10), the number of test cases. 
Each case begins with two integers n, m (1 <= n <= 30000, 1 <= m <= 3).
The next line contains m distinct positive integers pi (1 <= pi <= 100), the prices of each kind of vegetable. 
The vegetables (and their corresponding seeds) are numbered 1 to m in the order they appear in the input. 
Each of the following n lines contains five integers x1, y1, x2, y2, s, indicating a working seeded a rectangular area with lower-left corner (x1,y1), upper-right corner (x2,y2), with the s-th kind of seed.
All of x1, y1, x2, y2 will be no larger than 106 in their absolute values.

Output

For each test case, print the case number and your final income.

Sample Input

2
1 1
25
0 0 10 10 1
2 2
5 2
0 0 2 1 1
1 0 3 2 2

Sample Output

Case 1: 2500
Case 2: 16
 #include<cstdio>
#include<iostream>
#include<algorithm>
#define ls rt<<1
#define rs rt<<1|1
#define lson l,m,ls
#define rson m,r,rs
using namespace std;
const int mm=;
const int mn=mm<<;
struct seg
{
int x,y1,y2,c,v;
} g[mm];
int t[mn][],sum[mn][],p[],q[];
int y[mm];
int L,R,C,val,T;
void build(int n)
{
while(n--)for(int i=; i<T; ++i)t[n][i]=sum[n][i]=;
}
void updata(int l,int r,int rt)
{
if(L<=y[l]&&R>=y[r])t[rt][C]+=val;
else
{
int m=(l+r)>>;
if(L<y[m])updata(lson);
if(R>y[m])updata(rson);
}
int i,j;
for(i=T-; i>=; --i)
if(t[rt][i])
{
sum[rt][i]=y[r]-y[l];
for(j=i+; j<T; ++j)
sum[rt][i]-=sum[rt][j];
for(j=; j<i; ++j)sum[rt][j]=;
break;
}
else if(l>=r)sum[rt][i]=;
else sum[rt][i]=sum[ls][i]+sum[rs][i];
}
bool cmp(seg a,seg b)
{
return a.x<b.x;
}
int main()
{
int i,j,k,n,m,t,cs=;
__int64 ans;
scanf("%d",&t);
while(t--)
{
scanf("%d%d",&n,&T);
for(i=; i<T; ++i)scanf("%d",&p[i]),y[i]=i;
for(i=; i<T; ++i)
for(j=i+; j<T; ++j)
if(p[i]>p[j])swap(y[i],y[j]),swap(p[i],p[j]);
for(i=; i<T; ++i)q[y[i]]=i;
for(i=; i<n; ++i)
{
scanf("%d%d%d%d%d",&g[i].x,&y[i],&g[i+n].x,&y[i+n],&g[i].c);
g[i+n].c=g[i].c=q[g[i].c-];
g[i].y1=y[i],g[i].y2=y[i+n],g[i].v=;
g[i+n].y1=y[i],g[i+n].y2=y[i+n],g[i+n].v=-;
}
sort(y,y+n+n);
sort(g,g+n+n,cmp);
for(m=i=; i<n+n; ++i)
if(y[m]<y[i])y[++m]=y[i];
for(ans=i=; i<n+n; ++i)
{
L=g[i].y1,R=g[i].y2,C=g[i].c,val=g[i].v;
updata(,m,);
if(g[i].x<g[i+].x)
for(j=; j<T; ++j)
ans+=(__int64)(g[i+].x-g[i].x)*(__int64)sum[][j]*(__int64)p[j];
}
printf("Case %d: %I64d\n",++cs,ans);
}
return ;
}

Farming的更多相关文章

  1. hdu 3255 Farming(扫描线)

    题目链接:hdu 3255 Farming 题目大意:给定N个矩形,M个植物,然后给定每一个植物的权值pi,pi表示种植物i的土地,单位面积能够收获pi,每一个矩形给定左下角和右上角点的坐标,以及s, ...

  2. unity疯狂牧场完整项目源码 - Frenzy Farming time management game kit V1.0

    You will love this game kit! Have you ever wondered what it would be like to run your own farm? Look ...

  3. HDU 3255 Farming (线段树+扫面线,求体积并)

    题意:在一块地上种蔬菜,每种蔬菜有个价值.对于同一块地蔬菜价值高的一定是最后存活,求最后的蔬菜总值. 思路:将蔬菜的价值看做高度的话,题目就转化成求体积并,这样就容易了. 与HDU 3642 Get ...

  4. HDU 3255 Farming

    矩形面积并变形,一层一层的算体积 #include<cstdio> #include<cstring> #include<cmath> #include<ma ...

  5. 线段树 hdu3255 Farming

    做了这么多扫描线的题,,基本都是一个思路. 改来改去,,无非就是维护的节点的内容以及push_up越写越复杂了而已 首先将价格排序处理一下编号,变成编号越大的powerfol越大 然后后面加入扫描线的 ...

  6. 【转】windows和linux中搭建python集成开发环境IDE

    本系列分为两篇: 1.[转]windows和linux中搭建python集成开发环境IDE 2.[转]linux和windows下安装python集成开发环境及其python包 3.windows和l ...

  7. blade and soul zone overview

    The world of Blade and Soul, is a vast extension of land containing two continents (the Southern Con ...

  8. 【英语魔法俱乐部——读书笔记】 3 高级句型-简化从句&倒装句(Reduced Clauses、Inverted Sentences) 【完结】

    [英语魔法俱乐部——读书笔记] 3 高级句型-简化从句&倒装句(Reduced Clauses.Inverted Sentences):(3.1)从属从句简化的通则.(3.2)形容词从句简化. ...

  9. [SharePoint] SharePoint 错误集 2

    1 Run command “New-SPConfigurationDatabase" Feature Description: error message popup after run ...

随机推荐

  1. 【转】notepad++设置字体和字体大小

    原文网址:http://www.aichengxu.com/view/604 今天很多朋友问我怎么设置notepad++的代码字体和代码字体的大小,习惯了editplus的朋友可能会在notepad+ ...

  2. chrome无法使用非官方商店扩展解决办法

        自己开发的工具性插件不想放在官方商店(当然也有可能是工作相关的工具不能放在官方商店),由于新版本的chrome不允许非官方商店的插件进行安装使用,所以出现一个头疼的问题:每次开启chrome都 ...

  3. <转载>Wait and Waitpid

    转载http://www.cnblogs.com/lihaosky/articles/1673341.html 一.Wait #include <sys/types.h> /* 提供类型p ...

  4. linux环境下java读取sh脚本并执行

    Process process;           String cmd = "/home/ty/t.sh";//这里必须要给文件赋权限 chmod u+x fileName; ...

  5. aop动态代理学习

    学习,顺便做个demo,方便理解. A接口有c方法,类B实现A接口,原本应该是执行B类中的c方法,可现在不这样做: 我声明产生B类的代理类B',由它来冒充B类的“兄弟”并“实现”A接口, 对外界来说B ...

  6. Linux TCP/IP 协议栈之 Socket 的实现分析(一)

    内核版本:2.6.37参考[作者:kendo的文章(基于内涵版本2.6.12)] 第一部份 Socket套接字的创建 socket 并不是 TCP/IP协议的一部份. 从广义上来讲,socket 是U ...

  7. ListView之SimpleAdapter

    SimpleAdapter是安卓内置的适配器,本文展示的是listview的子项为{图片,文件}组合 如下图所示: 具体代码: SimpleAdapter_test.java /* ListView ...

  8. python之路-模块 WebDriver API

    相关文档: http://selenium-python.readthedocs.org/en/latest/api.html#selenium.common.exceptions.InvalidEl ...

  9. web文档类型DOCTYPE html很重要

    之前写html或者jsp页面,从来不注意DOCTYPE 的声明,也不太明白DOCTYPE 的作用.直到最近碰到了一个非常奇葩的bug:某一个页面在IE7和8,Chrome,ff等下正常,但是在IE9下 ...

  10. BOOST 线程完全攻略 - 扩展 - 事务线程

    扩展threadtimermoduleexceptionsocket 什么叫事务线程 举个例子: 我们写一个IM客户端的登录子线程,则该子线程会有这么几个事务要处理 No.1 TCP Socket物理 ...