二维线段树。wa了几次,不存在输出-1,而不再是一位小数。
#include <cstdio>
#include <cstring> #define MAXN 105
#define MAXM 1005
#define lson l, mid, rt<<1
#define rson mid+1, r, rt<<1|1 double sons[MAXN<<][MAXM<<]; inline double mymax(double a, double b) {
return (a>b) ? a:b;
} inline void PushUP(int rt, int index) {
sons[index][rt] = mymax(sons[index][rt<<], sons[index][rt<<|]);
} void build_son(int l, int r, int rt, int index) {
sons[index][rt] = -;
if (l == r)
return ;
int mid = (l+r)>>;
build_son(lson, index);
build_son(rson, index);
} void build(int l, int r, int rt) {
build_son(, , , rt);
if (l == r)
return ;
int mid = (l+r)>>;
build(lson);
build(rson);
} void Update_son(int l, int r, int rt, int A, double L, int index) {
if (l == r) {
if (L > sons[index][rt])
sons[index][rt] = L;
return ;
}
int mid = (l+r)>>;
if (A <= mid)
Update_son(lson, A, L, index);
else
Update_son(rson, A, L, index);
PushUP(rt, index);
} void Update(int l, int r, int rt, int H, int A, double L) {
Update_son(, , , A, L, rt);
if (l == r)
return ;
int mid = (l+r)>>;
if (H <= mid)
Update(lson, H, A, L);
else
Update(rson, H, A, L);
} double query_son(int ll, int rr, int l, int r, int rt, int index) {
if (ll<=l && rr>=r)
return sons[index][rt]; int mid = (l+r)>>;
double max = -; if (ll <= mid)
max = mymax(max, query_son(ll, rr, lson, index));
if (rr > mid)
max = mymax(max, query_son(ll, rr, rson, index));
return max;
} double query(int ll, int rr, int l, int r, int rt, int A1, int A2) {
if (ll<=l && rr>=r)
return query_son(A1, A2, , , , rt); int mid = (l+r)>>;
double max = -; if (ll <= mid)
max = mymax(max, query(ll, rr, lson, A1, A2));
if (rr > mid)
max = mymax(max, query(ll, rr, rson, A1, A2));
return max;
} int main() {
int n;
int h1, h2, tmp;
double a, b, c;
char cmd[]; while (scanf("%d", &n)!=EOF && n) {
build(, , );
while (n--) {
scanf("%s", cmd);
if (cmd[] == 'I') {
scanf("%d %lf %lf", &h1, &a, &b);
Update(, , , h1, (int)(a*), b);
} else {
scanf("%d %d %lf %lf", &h1, &h2, &a, &b);
if (h1 > h2) {
tmp = h1;
h1 = h2;
h2 = tmp;
}
if (a > b) {
c = a;
a = b;
b = c;
}
b = query(h1, h2, , , , (int)(a*), (int)(b*));
if (b < )
printf("-1\n");
else
printf("%.1lf\n", b);
}
}
} return ;
}