HDU 1823 Luck and Love
日期: 2013-09-19 分类: 个人收藏 332次阅读
二维线段树。纠结了好久的一道题,看来我还是没太弄懂二维的更新过程,再练几道,再想想就好了。
单点更新,区间查询。然后就是模板了。
然而discuss里有一组数据:
2
I 170 69.3 96.5
Q 144 184 38.3 69.2
0
答案是-1。网上很多AC代码都过不了这组数据,我的也是。后来发现个问题,一度让我以为是我的电脑坏了。
输入1.2却得不到12,所以之前的那组数据才会过不了,因为输入的69.3乘以10之后变成了692...
换一种方式来写就可以啦。
具体原因不明,求教...大概跟double的存储方式或舍入有关吧,题目的数据没有涉及到这里,所以无所谓,都可以AC。
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<vector>
#include<string>
#include<queue>
#include<map>
///LOOP
#define REP(i, n) for(int i = 0; i < n; i++)
#define FF(i, a, b) for(int i = a; i < b; i++)
#define FFF(i, a, b) for(int i = a; i <= b; i++)
#define FD(i, a, b) for(int i = a - 1; i >= b; i--)
#define FDD(i, a, b) for(int i = a; i >= b; i--)
///INPUT
#define RI(n) scanf("%d", &n)
#define RII(n, m) scanf("%d%d", &n, &m)
#define RIII(n, m, k) scanf("%d%d%d", &n, &m, &k)
#define RIV(n, m, k, p) scanf("%d%d%d%d", &n, &m, &k, &p)
#define RV(n, m, k, p, q) scanf("%d%d%d%d%d", &n, &m, &k, &p, &q)
#define RFI(n) scanf("%lf", &n)
#define RFII(n, m) scanf("%lf%lf", &n, &m)
#define RFIII(n, m, k) scanf("%lf%lf%lf", &n, &m, &k)
#define RFIV(n, m, k, p) scanf("%lf%lf%lf%lf", &n, &m, &k, &p)
#define RS(s) scanf("%s", s)
///OUTPUT
#define PN printf("\n")
#define PI(n) printf("%d\n", n)
#define PIS(n) printf("%d ", n)
#define PS(s) printf("%s\n", s)
#define PSS(s) printf("%s ", s)
#define PC(n) printf("Case %d: ", n)
///OTHER
#define PB(x) push_back(x)
#define CLR(a, b) memset(a, b, sizeof(a))
#define CPY(a, b) memcpy(a, b, sizeof(b))
#define display(A, n, m) {REP(i, n){REP(j, m)PIS(A[i][j]);PN;}}
#define lson l, m, rt << 1
#define rson m + 1, r, rt << 1 | 1
using namespace std;
typedef long long LL;
typedef pair<int, int> P;
const int MOD = 1e9+7;
const int INFI = 1e9 * 2;
const LL LINFI = 1e17;
const double eps = 1e-6;
const int N = 1111;
const int M = 111;
const int move[8][2] = {0, 1, 0, -1, 1, 0, -1, 0, 1, 1, 1, -1, -1, 1, -1, -1};
int sum[M << 2][N << 2];
int x1, x2, y1, y2, L, ans;
void update2(int x0, int l, int r ,int rt)
{
sum[x0][rt] = max(sum[x0][rt], L);
if(l == r)return;
int m = (l + r) >> 1;
if(y1 <= m)update2(x0, lson);
else update2(x0, rson);
}
void update1(int l, int r ,int rt)
{
update2(rt, 0, N - 1, 1);
if(l == r)return;
int m = (l + r) >> 1;
if(x1 <= m)update1(lson);
else update1(rson);
}
void query2(int x0, int l, int r, int rt)
{
if(y1 <= l && r <= y2)
{
ans = max(ans, sum[x0][rt]);
return ;
}
int m = (l + r) >> 1;
if(y1 <= m)query2(x0, lson);
if(y2 > m) query2(x0, rson);
}
void query1(int l, int r, int rt)
{
if(x1 <= l && r <= x2)
{
query2(rt, 0, N - 1, 1);
return;
}
int m = (l + r) >> 1;
if(x1 <= m)query1(lson);
if(x2 > m) query1(rson);
}
int main()
{
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
int t;
char op[5];
double a1, a2;
while(RI(t), t)
{
CLR(sum, -1);
while(t--)
{
RS(op);
if(op[0] == 'I')
{
RI(x1);
RFII(a1, a2);
x1 -= 100;
a1 *= 10;y1 = a1;
a2 *= 10;L = a2;
update1(0, M - 1, 1);
}
else
{
RII(x1, x2);
RFII(a1, a2);
x1 -= 100;
x2 -= 100;
a1 *= 10;y1 = a1;
a2 *= 10;y2 = a2;
if(x1 > x2)swap(x1, x2);
if(y1 > y2)swap(y1, y2);
ans = -1;
query1(0, M - 1, 1);
if(ans == -1)PI(-1);
else printf("%.1lf\n", ans / 10.0);
}
}
}
return 0;
}
除特别声明,本站所有文章均为原创,如需转载请以超级链接形式注明出处:SmartCat's Blog
标签:线段树
上一篇: exe删除自身
精华推荐