luoguP4254 [JSOI2008]Blue Mary开公司
李超树裸题,注意一开始截距是\(S-P\)。
code:
#include<bits/stdc++.h>
using namespace std;
#define ls(p) (p<<1)
#define rs(p) (p<<1|1)
const int maxn=500010;
const int maxm=100010;
const double eps=1e-8;
int n,cnt;
int maxid[maxn<<2];
double k[maxm],b[maxm];
inline double f(int x,int id){return k[id]*x+b[id];}
inline bool check(int a,int b,int x){return fabs(f(x,a)-f(x,b))>eps?f(x,a)<f(x,b):a>b;}
void insert(int p,int l,int r,int ql,int qr,int id)
{
int mid=(l+r)>>1;
if(l>=ql&&r<=qr)
{
if(check(id,maxid[p],l)&&check(id,maxid[p],r))return;
if(!check(id,maxid[p],l)&&!check(id,maxid[p],r)){maxid[p]=id;return;}
if(!check(id,maxid[p],mid))swap(id,maxid[p]);
if(!check(id,maxid[p],l))insert(ls(p),l,mid,ql,qr,id);
else insert(rs(p),mid+1,r,ql,qr,id);
return;
}
if(ql<=mid)insert(ls(p),l,mid,ql,qr,id);
if(qr>mid)insert(rs(p),mid+1,r,ql,qr,id);
}
int query(int p,int l,int r,int pos)
{
if(l==r)return maxid[p];
int mid=(l+r)>>1,res;
res=pos<=mid?query(ls(p),l,mid,pos):query(rs(p),mid+1,r,pos);
res=check(res,maxid[p],pos)?maxid[p]:res;
return res;
}
int main()
{
scanf("%d",&n);
for(int i=1;i<=n;i++)
{
char op[10];scanf("%s",op);
if(op[0]=='Q')
{
int x;scanf("%d",&x);
printf("%d\n",(int)(f(x,query(1,1,50000,x))/100));
}
else
{
double P,S;
scanf("%lf%lf",&S,&P);
cnt++;k[cnt]=P,b[cnt]=S-P;
insert(1,1,50000,1,50000,cnt);
}
}
return 0;
}
luoguP4254 [JSOI2008]Blue Mary开公司的更多相关文章
- 数据结构(线段树):BZOJ 1568 [JSOI2008]Blue Mary开公司
1568: [JSOI2008]Blue Mary开公司 Time Limit: 15 Sec Memory Limit: 162 MBSubmit: 602 Solved: 214[Submit ...
- bzoj千题计划219:bzoj1568: [JSOI2008]Blue Mary开公司
http://www.lydsy.com/JudgeOnline/problem.php?id=1568 写多了就觉着水了... #include<cstdio> #include< ...
- 【BZOJ1568】[JSOI2008]Blue Mary开公司(李超线段树)
[BZOJ1568][JSOI2008]Blue Mary开公司(李超线段树) 题面 BZOJ 洛谷 题解 是模板题啊. #include<iostream> #include<cs ...
- [BZOJ 1568][JSOI2008]Blue Mary开公司
[BZOJ 1568][JSOI2008]Blue Mary开公司 题意 \(n\) 次操作, 维护一个一次函数集合 \(S\). 有两种操作: 给定 \(b\) 和 \(k\), 向 \(S\) 中 ...
- 【BZOJ1568】[JSOI2008]Blue Mary开公司 线段树
[BZOJ1568][JSOI2008]Blue Mary开公司 Description Input 第一行 :一个整数N ,表示方案和询问的总数. 接下来N行,每行开头一个单词“Query”或“P ...
- 1568: [JSOI2008]Blue Mary开公司
1568: [JSOI2008]Blue Mary开公司 题目描述 传送门 题目分析 简单分析可以发现就是不停给出了\(n\)条直线,要求每次给出一条直线后求出所有直线在横坐标为\(x\)时\(y\) ...
- bzoj 1568 [JSOI2008]Blue Mary开公司 超哥线段树
[JSOI2008]Blue Mary开公司 Time Limit: 15 Sec Memory Limit: 162 MBSubmit: 1808 Solved: 639[Submit][Sta ...
- 1568: [JSOI2008]Blue Mary开公司(超哥线段树)
1568: [JSOI2008]Blue Mary开公司 Time Limit: 15 Sec Memory Limit: 162 MBSubmit: 1198 Solved: 418 Descr ...
- [Luogu] P4254 [JSOI2008]Blue Mary开公司
题目背景 Blue Mary 最近在筹备开一家自己的网络公司.由于他缺乏经济头脑,所以先后聘请了若干个金融顾问为他设计经营方案. 题目描述 万事开头难,经营公司更是如此.开始的收益往往是很低的,不过随 ...
随机推荐
- Cisco pppoe上网设置
1.配置虚拟端口: interface Dialer1 ip address negotiated ip nat outside ip virtual-reassembly in encapsulat ...
- python包matplotlib绘制图像
使用matplotlib绘制图像 import matplotlib.pyplot as plt from matplotlib.pyplot import MultipleLocator impor ...
- 详解C++ STL map 容器
详解C++ STL map 容器 本篇随笔简单讲解一下\(C++STL\)中的\(map\)容器的使用方法和使用技巧. map容器的概念 \(map\)的英语释义是"地图",但\( ...
- matlab练习程序(点云密度)
算法思路是首先建立kd树,然后找到每个点距离最近的点的距离,对距离求和再求平均即可. 代码如下: clear all; close all; clc; pc = pcread('rabbit.pcd' ...
- java图形界面 计算器实现
编写程序实现一个简单计算器的基本功能,具体可以模仿Windows附件中的计算器或模拟常见的实物计算器. package beizi; import java.awt.EventQueue; impor ...
- 创意编程,Python开发多功能壁纸自动切换工具!
import ctypes import time import requests import os from threading import Thread from tkinter import ...
- Linq分页排序通用方法
1.通用方法 2.调用 -----------------------------1.------------------------------------------- public class ...
- 【转】理解ASP.NET Core验证模型(Claim, ClaimsIdentity, ClaimsPrincipal)不得不读的英文博文
这篇英文博文是 Andrew Lock 写的 Introduction to Authentication with ASP.NET Core . 以下是简单的阅读笔记: -------------- ...
- laravel中的表单请求类型和CSRF防护(六)
laravel中为我们提供了绑定不同http请求类型的函数. Route::get('/test', function () {}); Route::post('/test', function () ...
- js-xlsx 实现前端 Excel 导出(支持多 sheet)
之前写文章介绍了使用 js-xlsx 实现导入 excel 的功能,现在再介绍一下如何使用 js-xlsx 进行 excel 导出. [实现步骤] 1. 首先安装依赖 npm install xlsx ...