hdu-1823 Luck and Love

news/2024/10/23 8:37:37/

题目链接:hdu1823二维线段树单点更新区间查询

题意

向一个100*1000的二维空间中插入点,每次查询时,查询区间最大值.

题解

身高既然是100~200,那就相当于100;活泼度相当于1000.所以建立100*1000的二维线段树.

大坑有如下几个
输出-1,而不是-1.0
输入的h1,h2,a1,a2,大小不一定,需要加上一个判断

代码

#include<iostream>
#include<vector>
#include<algorithm>
#include<stdio.h>
#include<string.h>
#include<string>
using namespace std;
typedef long long ll;
#define re(i,n) for(int i=0;i<n;i++) 
const int maxn = 4;
const int xsz = 107, ysz = 1007;
double h,a, l;
double hf, ht, af, at; 
double tr[(xsz+1)<<2][(ysz+1)<<2];
#define lson(id) id<<1,f,mid
#define rson(id)  id<<1|1,mid+1,t
void yinsert(int x, int y, int f, int t){tr[x][y] = max(tr[x][y], l);if (f == t)return;int mid = (f + t) >> 1;if (a <= mid)yinsert(x, lson(y));else yinsert(x, rson(y));
}
void xinsert(int id,int f,int t){yinsert(id, 1, 0, ysz);if (f == t)return;int mid = (f + t) >> 1;if (h <= mid)xinsert(lson(id));else xinsert(rson(id));
}
void yquery(int x, int y, int f, int t){if (af <= f&&at >= t){l = max(l, tr[x][y]);return;}int mid = (f + t) >> 1;if (af <= mid)yquery(x, lson(y));if (at > mid)yquery(x, rson(y));
}
void xquery(int x, int f, int t){if (hf <= f&&ht >= t){yquery(x, 1, 0, ysz);return;}int mid = (f + t) >> 1;if (ht > mid)xquery(rson(x));if(hf<=mid) xquery(lson(x));
}
void yclear(int x, int y, int f, int t){tr[x][y] = -1;if (f == t)return;int mid = (f + t) >> 1;yclear(x, lson(y)), yclear(x, rson(y));
}
void xclear(int x, int f, int t){yclear(x, 1, 0, ysz);if (f == t)return;int mid = (f + t) >> 1;xclear(lson(x)), xclear(rson(x));
}
int main(){freopen("in.txt", "r", stdin);  int Q;while (scanf("%d", &Q) && Q){xclear(1, 0, xsz);while (Q--){char op[2]; scanf("%s", op);if (op[0] == 'I'){ scanf("%lf%lf%lf", &h, &a, &l);h -= 100, a *= 10;xinsert(1,0,xsz);}else{scanf("%lf%lf%lf%lf", &hf, &ht, &af, &at);hf -= 100, ht -= 100, af *= 10, at *= 10;if (hf > ht)swap(hf, ht); if (af > at)swap(af, at);l= -1;xquery(1,0,xsz);if (l == -1)puts("-1");else printf("%.1lf\n", l);}}}return 0;
}

转载于:https://www.cnblogs.com/weiyinfu/p/4831106.html


http://www.ppmy.cn/news/703474.html

相关文章

hdu1823

/* 分析&#xff1a; 二维线段树。 很早就明白什么是二维线段树了&#xff0c;不过没有见过二维线段树的代码&#xff0c; 想趁这次敲一个&#xff0c;不过最后发现敲的有那么一点儿点儿毛病&#xff0c;感觉没有 像二维树状数组那样发挥出二维情况下的线段树的速度&#xff0c…

poj 1823

题意&#xff1a;一个hotel&#xff0c;有n间连续的房间&#xff0c;现在有m组操作&#xff1a; type 1: 1, a, b: 第a个房间起的b个房间有旅客入住。 type 2: 2, a, b: 第a个房间起的b个房间的旅客离开。 type 3: 3: 问最长的连续空房间有多少间。 思路&#xff1a;…

codeforces 1354A 菜鸟题解

codeforces 1354A 菜鸟题解 题目链接&#xff1a;https://codeforc.es/problemset/problem/1354/A 题目解释&#xff1a; 输入为a b c d 总共要睡a分钟&#xff1b;每次休息时间为b分钟&#xff1b;闹铃每次设置后c分钟响&#xff1b;每次被闹铃吵醒需要d分钟睡着&#xff1…

Quectel EC200A-CN移植

Quectel EC200A-CN移植 一:usb转串口二:usb网卡驱动三:源码修改四:测试 一:usb转串口 usb-serial-option,USB转串口驱动&#xff0c;生产/dev/ttyUSB0-2,分别是DM&#xff0c;AT&#xff0c;PPP 需要使能内核选项如下: CONFIG_USB_SERIALy CONFIG_USB_SERIAL_WWANy CONFIG_US…

倍福TwinCAT Error starting TwinCAT System ADS 1823 / 0x71f

If ADS error 1823 (0x71f) occurs when an IP stack TcCOM object is started, the configuration of the network card is probably incorrect. Check the settings under “Adapter” for the network card in the project folder:

1823. 数组的最长前缀

1823. 数组的最长前缀 给定两个正整数X和Y&#xff0c;以及正整数数组nums。 我们需要找到一个最大的index&#xff0c;使得在nums[0], nums[1], .... , nums[index]中&#xff0c;出现X、Y的次数相等&#xff0c;且至少均出现一次&#xff0c;返回该index。 若不存在这样的ind…

Hdu-1823的题解

题目链接&#xff1a;http://acm.hdu.edu.cn/showproblem.php?pid1823 Problem Description 世界上上最远的距离不是相隔天涯海角 而是我在你面前 可你却不知道我爱你 ―― 张小娴 前段日子&#xff0c;枫冰叶子给Wiskey做了个征婚启事&#xff0c;聘礼达到500万哦&#xff0c…

CVE-2012-1823漏洞复现

前言 这个漏洞简单来说&#xff0c;就是用户请求的querystring&#xff08;querystring字面上的意思就是查询字符串&#xff0c;一般是对http请求所带的数据进行解析&#xff0c;这里也是指http请求中所带的数据&#xff09;被作为了php-cgi的参数&#xff0c;最终导致了一系列…