Farming
Total Submission(s): 1614 Accepted Submission(s): 479
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.
Each case begins with two integers n, m (1 <= n <= 30000, 1 <= m <= 3).
The next line contains m distinct positive integers p i (1 <= p i <= 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 10 6 in their absolute values.
2 1 1 25 0 0 10 10 1 2 2 5 2 0 0 2 1 1 1 0 3 2 2
Case 1: 2500 Case 2: 16
#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;
#define maxn 35000
#define ll long long int
ll sum[maxn<<2];
int mark[maxn<<2], val[5], Hash[maxn<<1];
struct seg{
int l, r, h, c, val;
seg(){}
seg(int x1, int x2, int y, int v, int d):l(x1),r(x2),h(y),val(v),c(d){}
bool operator <(const seg &a)const{
return h<a.h;
}
}s[maxn<<1], tmp[maxn<<1];
int Search(int key, int a[], int right){
int l = 0, r = right-1;
while(l <= r){
int mid = (l+r)>>1;
if(a[mid] == key) return mid;
if(a[mid] > key) r = mid-1;
else l = mid+1;
}
return -1;
}
void upfather(int n, int left, int right){
if(mark[n]) sum[n] = Hash[right+1] - Hash[left];
else if(left == right) sum[n] = 0;
else sum[n] = sum[n<<1] + sum[n<<1|1];
}
void update(int L, int R, int rt, int d, int left, int right){
if(L<=left&&right<=R){
mark[rt]+=d;
upfather(rt, left, right);
return;
}
int mid = (left+right)>>1;
if(L<=mid) update(L, R, rt<<1, d, left, mid);
if(mid<R) update(L, R, rt<<1|1, d, mid+1, right);
upfather(rt, left, right);
}
int main()
{
int T, k, i, j, n, m, x1, x2, y1, y2, Case, v, p;
scanf("%d", &T);
Case = 1;
while(T--){
scanf("%d %d", &n, &m);
for(i = 1;i <= m;i++) scanf("%d", &val[i]);
k = 0;
for(i = 0;i < n;i++){
scanf("%d %d %d %d %d", &x1, &y1, &x2, &y2, &v);
Hash[k]= x1;
s[k++] = seg(x1, x2, y1, val[v], 1);
Hash[k]= x2;
s[k++] = seg(x1, x2, y2, val[v], -1);
}
val[0] = 0;
sort(Hash, Hash+k);
sort(s, s+k);
sort(val, val+m+1);
p = 1;
for(i = 1;i < k;i++)
if(Hash[i] != Hash[i-1])
Hash[p++] = Hash[i];
ll ans = 0;
for(i = 1;i <= m;i++){
int c = 0;
for(j = 0;j < k;j++)
if(s[j].val > val[i-1])
tmp[c++] = s[j];
for(j = 0;j < c;j++){
int L = Search(tmp[j].l, Hash, p);
int R = Search(tmp[j].r, Hash, p)-1;
//printf("%d %d\n", tmp[j].l, tmp[j].r);
update(L, R, 1, tmp[j].c, 0, p-1);
//printf("%I64d\n", sum[1]);
ans += sum[1]*(val[i] - val[i-1])*(tmp[j+1].h - tmp[j].h);
//printf("%I64d\n", sum[1]);
}
}
printf("Case %d: %I64d\n", Case++, ans);
}
}
682


&spm=1001.2101.3001.11974&articleId=51165207&d=1&t=3&u=14535791b00c427995e4e228cb4e4509)

被折叠的 条评论
为什么被折叠?



