【HDU】3255 求长方体并的体积

来源:互联网 发布:windows 7 sp2 编辑:程序博客网 时间:2024/04/28 18:06
#define _CRT_SECURE_NO_WARNINGS#include<algorithm>#include<iostream>#include<cstdio>#include<cstring>using namespace std;#define MAX 100003#define ls rt<<1#define rs ls|1#define m (l+r)>>1int col[MAX << 2];long long sum2[MAX << 2];int value[4];int posx[MAX];struct pos{int l, r, h, s, x;pos(){}pos(int _l, int _r, int _h, int _s, int _x){l = _l;r = _r;h = _h;s = _s;x = _x;}bool operator<(pos b){return h < b.h;}}p[MAX],temp[MAX];void uprt(int l, int r, int rt){if (col[rt]){sum2[rt] = posx[r + 1] - posx[l];return;}if (l == r)sum2[rt] = 0;elsesum2[rt] = sum2[ls] + sum2[rs];}void updata(int L, int R, int c,int l, int r, int rt){if (L <= l&&r <= R){col[rt] += c;uprt(l, r, rt);return;}int mid = m;if (L <= mid)updata(L, R, c,l, mid, ls);if (mid < R)updata(L, R, c, mid + 1, r, rs);uprt(l, r, rt);}int main(){int t;cin >> t;int icase = 1;while (t--){int n, k;scanf("%d%d", &n, &k);for (int i = 1; i <= k; i++)scanf("%d", &value[i]);int x1, x2, y1, y2, x;int cnt = 0;for (int i = 0; i < n; i++){scanf("%d%d%d%d%d", &x1, &y1, &x2, &y2, &x);posx[cnt] = x1;p[cnt++] = pos(x1, x2, y1, 1, value[x]);posx[cnt] = x2;p[cnt++] = pos(x1, x2, y2, -1, value[x]);}sort(p, p + cnt);sort(posx, posx + cnt);int cnt2 = unique(posx, posx + cnt) - posx;sort(value + 1, value + 1 + k);long long ans = 0;for (int j = 1; j <=k; j++){int cnt3 = 0;for (int i = 0; i < cnt;i++)if (p[i].x > value[j-1])temp[cnt3++] = p[i];memset(col, 0, sizeof(col));memset(sum2, 0, sizeof(sum2));for (int i = 0; i < cnt3- 1; i++){int curl = lower_bound(posx, posx + cnt2, temp[i].l) - posx;int curr = lower_bound(posx, posx + cnt2, temp[i].r) - posx - 1;updata(curl, curr, temp[i].s, 0, cnt2 - 1, 1);ans += sum2[1] * (temp[i + 1].h - temp[i].h)*(value[j]-value[j-1]);}}printf("Case %d: %lld\n", icase++, ans);}}

0 0
原创粉丝点击