###### HDU 5714 (离散化 树状数组)
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <map>
#include <vector>
using namespace std;
#define maxn 21111

int a[maxn][3], b[maxn][3];
int cnt1, cnt2;
int c[maxn], x[maxn], Max[maxn];
int n;
int cnt;

int lowbit (int x) {
return x&(-x);
}

void add (int pos, int num, bool op) {
for (int i = pos; i <= cnt; i += lowbit (i)) {
if (!op) c[i] += num;
else x[i] += num;
}
}

int sum (int pos, int op) {
int ans = 0;
for (int i = pos; i > 0; i -= lowbit (i)) {
if (!op) ans += c[i];
else
ans += x[i];
}
return ans;
}
vector <int> num, l1, r1, l2, r2;
map <int, int> gg;
void init () {
gg.clear ();
sort (num.begin (), num.end ());
int Max = num.size ();
cnt = 1;
for (int i = 0; i < Max; i++) {
if (!i || num[i] != num[i-1]) {
gg[num[i]] = cnt++;
}
}
}

int solve () {
num.clear (); l1.clear (), l2.clear(), r1.clear (), r2.clear ();
memset (c, 0, sizeof c);
for (int i = 0; i < cnt1; i++) {
int r = a[i][0]+a[i][2], l = a[i][1]-a[i][2];
if (r >= l) {
l1.push_back (l);
r1.push_back (r);
num.push_back (l);
num.push_back (r);
}
}
memset (x, 0, sizeof x);
for (int i = 0; i < cnt2; i++) {
int r = b[i][0]+b[i][2], l = b[i][1]-b[i][2];
if (r >= l) {
l2.push_back (l);
r2.push_back (r);
num.push_back (l);
num.push_back (r);
}
}
init ();
for (int i = 0; i < l1.size (); i++) {
int l = gg[l1[i]], r = gg[r1[i]];
}
for (int i = 0; i < l2.size (); i++) {
int l = gg[l2[i]], r = gg[r2[i]];
}
Max[1] = x[1];
for (int i = 2; i <= cnt; i++) {
int cur = sum (i, 1);
Max[i] = max (Max[i-1], cur);
}
int ans = 0;
for (int i = 1; i <= cnt; i++) {
ans = max (ans, sum (i, 0) + Max[i]);
}
return ans;
}

int main () {
//freopen ("in.txt", "r", stdin);
int t, kase = 0;
scanf ("%d", &t);
while (t--) {
scanf ("%d", &n);
printf ("Case #%d:\n", ++kase);
cnt1 = 0, cnt2 = 0;
for (int i = 1; i <= n; i++) {
int x, y, d, op;
scanf ("%d%d%d%d", &x, &y, &d, &op);
if (op == -1) {
a[cnt1][0] = x, a[cnt1][1] = y, a[cnt1][2] = d;
cnt1++;
}
else {
b[cnt2][0] = x, b[cnt2][1] = y, b[cnt2][2] = d;
cnt2++;
}
}
int ans = solve ();
printf ("%d\n", ans);
}
return 0;
}

#### hdu4325 树状数组+离散化

2015-02-06 10:09:23

#### hdu3450之离散化+二分查找+树状数组

2014-03-13 14:35:20

#### HDU 5714 树状数组 + 离散化

2017-03-10 16:46:19

#### hdu 5714 &&2016 百度之星复赛 1003 拍照(排序+思考)

2016-05-30 12:13:26

#### 离散化+树状数组求逆序数

2013-01-19 14:52:12

#### [离散化+树状数组]逆序对

2016-05-01 12:27:31

#### 树状数组--离散化

2016-08-17 09:35:01

#### 树状数组求逆序对及离散化

2017-08-26 22:59:15

#### POJ：2299 Ultra-QuickSort（树状数组+离散化+技巧+求逆序对）

2016-08-17 10:34:25

#### HDU-5714-拍照（区间线段覆盖）

2016-06-02 21:15:15

## 不良信息举报

HDU 5714 (离散化 树状数组)