如题,原题是HDU-1823
因为蒟蒻的四分树没有过,所以随了数据,但是用来对照的题解却读入不了,求助谷内大佬,我是哪里有问题呢?
下面是随的数据和运行情况,(test)是题解,没有的是我自己的,更下面附有代码:

数据生成代码:
#include <algorithm>
#include <random>
#include <cstring>
#include <iostream>
#include <time.h>
using namespace std;
int randint(int l,int r){
return rand()%(r-l+1)+l;
}
double randdouble(int l,int r){
return 1.0*randint(l,r)/10;
}
int main(){
freopen("HDU1823.in","w",stdout);
srand(time(0));
int t=randint(1,5);
while(t--){
int m=randint(1,20);
printf("%d\n",m);
while(m--){
int op=randint(0,5);
if(op<=3){
int h=randint(100,200);
double a=randdouble(0,1000),l=randdouble(0,1000);
printf("I %d %.1lf %.1lf\n",h,a,l);
}
else{
double h1=randdouble(1000,2000),h2=randdouble(1000,2000);
double a1=randdouble(0,1000),a2=randdouble(0,1000);
printf("Q %.1lf %.1lf %.1lf %.1lf\n",h1,h2,a1,a2);
}
}
}
printf("0\n");
return 0;
}
我的代码:
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cstring>
#define lt lefttop
#define rt righttop
#define lb leftbottom
#define rb rightbottom
using namespace std;
const int N=1e5+10;
int m,tot=1;
struct node{
int lefttop,righttop,leftbottom,rightbottom;
int xl,xr,yl,yr;
double maxl;
}tr[N<<2];
void pushup(int x){
tr[x].maxl=max(tr[x].maxl,tr[tr[x].lt].maxl);
tr[x].maxl=max(tr[x].maxl,tr[tr[x].rt].maxl);
tr[x].maxl=max(tr[x].maxl,tr[tr[x].lb].maxl);
tr[x].maxl=max(tr[x].maxl,tr[tr[x].rb].maxl);
}
void build(){
tr[1].xl=0,tr[1].xr=100,tr[1].yl=0,tr[1].yr=1000,tr[1].maxl=-1;
}
int newnode(int xl,int xr,int yl,int yr){
int p=++tot;
tr[p].xl=xl,tr[p].xr=xr,tr[p].yl=yl,tr[p].yr=yr;
tr[p].maxl=-1;
return p;
}
void insert(int p,int x,int y,double k){
if(tr[p].xl==tr[p].xr&&tr[p].yl==tr[p].yr){
tr[p].maxl=fmax(tr[p].maxl,k);
return;
}
int xmid=(tr[p].xl+tr[p].xr)>>1,ymid=(tr[p].yl+tr[p].yr)>>1;
if(x<=xmid){
if(y<=ymid){
if(tr[p].lb==0){
tr[p].lb=newnode(tr[p].xl,xmid,tr[p].yl,ymid);
}
insert(tr[p].lb,x,y,k);
}
else{
if(tr[p].lt==0){
tr[p].lt=newnode(tr[p].xl,xmid,ymid+1,tr[p].yr);
}
insert(tr[p].lt,x,y,k);
}
}
else{
if(y<=ymid){
if(tr[p].rb==0){
tr[p].rb=newnode(xmid+1,tr[p].xr,tr[p].yl,ymid);
}
insert(tr[p].rb,x,y,k);
}
else{
if(tr[p].rt==0){
tr[p].rt=newnode(xmid+1,tr[p].xr,ymid+1,tr[p].yr);
}
insert(tr[p].rt,x,y,k);
}
}
pushup(p);
}
double query(int x,int xl,int xr,int yl,int yr){
if(xl<=tr[x].xl&&tr[x].xr<=xr&&yl<=tr[x].yl&&tr[x].yr<=yr){
return tr[x].maxl;
}
double ans=-1;
int xmid=(tr[x].xl+tr[x].xr)>>1,ymid=(tr[x].yl+tr[x].yr)>>1;
if(xl<=xmid){
if(yl<=ymid){
if(tr[x].lb!=0){
ans=max(ans,query(tr[x].lb,xl,xr,yl,yr));
}
}
if(yr>ymid){
if(tr[x].lt!=0){
ans=max(ans,query(tr[x].lt,xl,xr,yl,yr));
}
}
}
if(xr>xmid){
if(yl<=ymid){
if(tr[x].rb!=0){
ans=max(ans,query(tr[x].rb,xl,xr,yl,yr));
}
}
if(yr>ymid){
if(tr[x].rt!=0){
ans=max(ans,query(tr[x].rt,xl,xr,yl,yr));
}
}
}
return ans;
}
int main(){
freopen("HDU1823.in","r",stdin);
freopen("HDU1823.out","w",stdout);
while(scanf("%d",&m)&&m!=0){
int h,a,xx1,xx2,yy1,yy2;
double tema,l;
double x1,x2,y1,y2;
memset(tr,0,sizeof tr);
tot=1;
build();
while(m--){
char op[2];
scanf("%s",op);
if(op[0]=='I'){
scanf("%d%lf%lf",&h,&tema,&l);
h-=100;
a=(int)tema*10;
insert(1,h,a,l);
}
else{
scanf("%lf%lf%lf%lf",&x1,&x2,&y1,&y2);
if(x1>x2){
swap(x1,x2);
}
if(y1>y2){
swap(y1,y2);
}
xx1=ceil(x1),xx2=floor(x2),yy1=(int)y1*10,yy2=(int)y2*10;
xx1-=100,xx2-=100;
double res=query(1,xx1,xx2,yy1,yy2);
if(res<0){
printf("-1\n");
continue;
}
printf("%.1lf\n",res);
}
}
}
}
题解代码:
#include<bits/stdc++.h>
using namespace std;
#define lson l, m, rt << 1
#define rson m + 1, r, rt << 1 | 1
int n, s[1005][4005];
void subBuild(int xrt, int l, int r, int rt) {
s[xrt][rt] = -1;
if(l != r) {
int m = l + r >> 1;
subBuild(xrt, lson);
subBuild(xrt, rson);
}
}
void build(int l, int r, int rt) {
subBuild(rt, 0, n, 1);
if(l != r) {
int m = l + r >> 1;
build(lson);
build(rson);
}
}
void subUpdate(int xrt, int y, int c, int l, int r, int rt) {
if(l == r && l == y) s[xrt][rt] = max(s[xrt][rt], c);
else {
int m = l + r >> 1;
if(y <= m) subUpdate(xrt, y, c, lson);
else subUpdate(xrt, y, c, rson);
s[xrt][rt] = max(s[xrt][rt << 1], s[xrt][rt << 1 | 1]);
}
}
void update(int x, int y, int c, int l, int r, int rt) {
subUpdate(rt, y, c, 0, n, 1);
if(l != r) {
int m = l + r >> 1;
if(x <= m) update(x, y, c, lson);
else update(x, y, c, rson);
}
}
int subQuery(int xrt, int yl, int yr, int l, int r, int rt) {
if(yl <= l && r <= yr) return s[xrt][rt];
else {
int m = l + r >> 1;
int res = -1;
if(yl <= m) res = subQuery(xrt, yl, yr, lson);
if(yr > m) res = max(res, subQuery(xrt, yl, yr, rson));
return res;
}
}
int query(int xl, int xr, int yl, int yr, int l, int r, int rt) {
if(xl <= l && r <= xr) return subQuery(rt, yl, yr, 0, n, 1);
else {
int m = l + r >> 1;
int res = -1;
if(xl <= m) res = query(xl, xr, yl, yr, lson);
if(xr > m) res = max(res, query(xl, xr, yl, yr, rson));
return res;
}
}
int main() {
freopen("HDU1823.in","r",stdin);
freopen("HDU1823(test).out","w",stdout);
int t;
while(scanf("%d", &t) && t) {
n = 1000;
build(100, 200, 1);
while(t--) {
char ch[2];
int a, b;
double c, d;
scanf("%s", ch);
if(ch[0] == 'I') {
scanf("%d%lf%lf", &a, &c, &d);
update(a, c * 10, d * 10, 100, 200, 1);
} else {
scanf("%d%d%lf%lf", &a, &b, &c, &d);
// cout<<a<<" "<<b<<" "<<c<<" "<<d<<endl;
int cc = c * 10, dd = d * 10;
if(a > b) swap(a, b);
if(cc > dd) swap(cc, dd);
int ans = query(a, b, cc, dd, 100, 200, 1);
if(ans == -1) printf("-1\n");
else printf("%.1f\n", ans / 10.0);
}
}
}
return 0;
}