xiaoz 征婚,首先输入M,表示有M个操作。

借下来M行,对每一行   Ih a l     I 表示有一个MM报名,H是高度, a是活泼度,L是缘分。

或   Q h1 h2 a1 a2    求出身高在h1  h2  活泼度在a1  a2之间的最大缘分值。

 #include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <list>
#include <iomanip>
#include <cstdlib>
#include <sstream>
using namespace std;
typedef long long LL;
const int INF=0x5fffffff;
const double EXP=1e-;
const int MS=; struct active
{
int l,r;
double maxv;
int mid()
{
return (l+r)>>;
}
}; struct node
{
int l,r;
active actives[*MS];
int mid()
{
return (l+r)>>;
}
}nodes[]; void init()
{
for(int i=;i<;i++)
for(int j=;j<*MS;j++)
nodes[i].actives[j].maxv=-;
} void creat_a(int p,int root,int l,int r)
{
nodes[p].actives[root].l=l;
nodes[p].actives[root].r=r;
if(nodes[p].actives[root].l==nodes[p].actives[root].r)
return ;
int mid=(l+r)/;
creat_a(p,root<<,l,mid);
creat_a(p,root<<|,mid+,r);
} void creat(int root,int l,int r)
{
nodes[root].l=l;
nodes[root].r=r;
creat_a(root,,,MS);
if(nodes[root].l==nodes[root].r)
return ;
int mid=(l+r)/;
creat(root<<,l,mid);
creat(root<<|,mid+,r);
} void insert_a(int p,int root,int pos,double value)
{
if(nodes[p].actives[root].maxv<value)
nodes[p].actives[root].maxv=value;
if(nodes[p].actives[root].l==nodes[p].actives[root].r)
return ;
if(pos<=nodes[p].actives[root].mid())
insert_a(p,root<<,pos,value);
else
insert_a(p,root<<|,pos,value);
} void insert(int root,int pos,int value,double s)
{
insert_a(root,,value,s);
if(nodes[root].l==nodes[root].r)
return ;
if(pos<=nodes[root].mid())
insert(root<<,pos,value,s);
else
insert(root<<|,pos,value,s);
} double query_a(int p,int root,int l,int r)
{
double ans=-;
if(nodes[p].actives[root].l>=l&&nodes[p].actives[root].r<=r)
return nodes[p].actives[root].maxv;
if(l<=nodes[p].actives[root].mid())
ans= max(ans,query_a(p,root<<,l,r));
if(r>nodes[p].actives[root].mid())
ans=max(ans,query_a(p,root<<|,l,r));
return ans;
} double query(int root,int l1,int r1,int l2,int r2)
{
double ans=-;
if(nodes[root].l>=l1&&nodes[root].r<=r1)
return query_a(root,,l2,r2);
// 如果是叶子节点会在上一条语句中返回。
if(l1<=nodes[root].mid())
ans=max(ans,query(root<<,l1,r1,l2,r2));
if(r1>nodes[root].mid())
ans=max(ans,query(root<<|,l1,r1,l2,r2));
return ans;
} int main()
{
int n,h1,h2;
double a1,a2,fate;
creat(,,);
while(scanf("%d",&n)==&&n)
{
init();
char cmd[MS];
while(n--)
{
scanf("%s",cmd);
if(cmd[]=='I')
{
scanf("%d %lf %lf",&h1,&a1,&fate); insert(,h1,(int)(a1*+EXP),fate);
}
else
{
scanf("%d %d %lf %lf",&h1,&h2,&a1,&a2);
if(h1>h2)
swap(h1,h2);
if(a1>a2)
swap(a1,a2);
double ans=query(,h1,h2,(int)(a1*+EXP),(int)(a2*+EXP));
if(ans>=)
printf("%.1lf\n",ans);
else
printf("-1\n");
}
}
}
return ;
}

最新文章

  1. CSS3 border-image 属性
  2. node04-buffer
  3. 数据库.bak文件还原报错的处理办法
  4. [deviceone开发]-数据绑定示例
  5. 第十一篇:SOUI系统资源管理
  6. 小白学习mysql之优化基础(EXPLAIN的连接类型)
  7. #Linux学习笔记# 自定义shell终端提示符
  8. an optimal solution to the problem
  9. QQ互联OAuth2.0 .NET SDK 发布以及网站QQ登陆示例代码(转)
  10. 进程环境之getrlimit和setrlimit函数
  11. Linux下Apache与Tomcat的完全分布式集群配置(负载均衡)
  12. 【转】sublime text 2 中文乱码解决办法
  13. 数组对象-new Array
  14. BizTalk 2010/2013 EDI B2B
  15. 安卓学习笔记--已root设备应用请求root权限
  16. hdu1556 树状数组区间更新单点查询板子
  17. Introducing Makisu: Uber’s Fast, Reliable Docker Image Builder for Apache Mesos and Kubernetes
  18. Android拦截外拨电话
  19. Syncthing源码解析 - 在Gogland中对Syncthing的各个模块进行调试?
  20. nodejs文件上传组件multer使用

热门文章

  1. sql联接那点儿事儿
  2. 线性模型(3):Logistic Regression
  3. HDU 1890 Robotic Sort(splay)
  4. C# 字符串格式
  5. Mahout应用(一)
  6. UVALive 7456 Least Crucial Node (并查集)
  7. 第八章、Linux 磁盘与文件系统管理
  8. CodeForces 548A Mike and Fax (回文,水题)
  9. UVALIVE 4970 最小权匹配
  10. MVC神韵---你想在哪解脱!(十八)