bzoj3878
当初只会暴力,现在差不多觉得水了
显然离线处理,对输入的数排序然后会发现不管怎么修改都是结果总是单调不降的
对于每次处理,我们只要找到那段越界的即可
显然上线段树,话说jsoi这么喜欢线段树?
下面在bzoj上过不去,因为pascal编译器处理比较严格,可能某处爆了int64,我也懒得查了,本地是能过的
type node=record
mi,mx,att,mul,an:int64;
end; var tree:array[..*] of node;
ans,b,c:array[..] of longint;
a:array[..] of int64;
ch:array[..] of char;
m,f,t,i,n:longint; procedure swap(var a,b:longint);
var c:longint;
begin
c:=a;
a:=b;
b:=c;
end; procedure sort(l,r:longint);
var i,j:longint;
x,y:int64; begin
i:=l;
j:=r;
x:=a[(l+r) shr ];
repeat
while a[i]<x do inc(i);
while x<a[j] do dec(j);
if not(i>j) then
begin
y:=a[i]; a[i]:=a[j]; a[j]:=y;
swap(c[i],c[j]);
inc(i);
dec(j);
end;
until i>j;
if l<j then sort(l,j);
if i<r then sort(i,r);
end; procedure cal(i,x,y:longint;x1,x2,x3:int64);
begin
with tree[i] do
begin
mi:=mi*x1+x2*a[x]+x3;
mx:=mx*x1+x2*a[y]+x3;
mul:=mul*x1;
att:=att*x1;
an:=an*x1;
att:=att+x2;
an:=an+x3;
end;
end; procedure build(i,l,r:longint);
var m:longint;
begin
tree[i].mi:=a[l];
tree[i].mx:=a[r];
tree[i].mul:=;
if l<>r then
begin
m:=(l+r) shr ;
build(i*,l,m);
build(i*+,m+,r);
end;
end; procedure push(i,l,r:longint);
var m:longint;
begin
m:=(l+r) shr ;
with tree[i] do
begin
cal(i*,l,m,mul,att,an);
cal(i*+,m+,r,mul,att,an);
mul:=;
att:=;
an:=;
end;
end; procedure max(i,l,r:longint);
var m:longint;
begin
if l=r then cal(i,l,l,,,t)
else begin
m:=(l+r) shr ;
push(i,l,r);
if tree[i*].mx>t then
begin
cal(i*+,m+,r,,,t);
max(i*,l,m);
end
else max(i*+,m+,r);
tree[i].mx:=tree[i*+].mx;
tree[i].mi:=tree[i*].mi;
end;
end; procedure min(i,l,r:longint);
var m:longint;
begin
if l=r then cal(i,l,l,,,f)
else begin
m:=(l+r) shr ;
push(i,l,r);
if tree[i*+].mi<f then
begin
cal(i*,l,m,,,f);
min(i*+,m+,r);
end
else min(i*,l,m);
tree[i].mx:=tree[i*+].mx;
tree[i].mi:=tree[i*].mi;
end;
end; procedure ask(i,l,r:longint);
var m:longint;
begin
if l=r then
ans[c[l]]:=tree[i].mx
else begin
m:=(l+r) shr ;
push(i,l,r);
ask(i*,l,m);
ask(i*+,m+,r);
end;
end; begin
readln(m,f,t);
for i:= to m do
readln(ch[i],b[i]);
readln(n);
for i:= to n do
begin
readln(a[i]);
if a[i]>t then a[i]:=t;
if a[i]<f then a[i]:=f;
c[i]:=i;
end;
sort(,n);
build(,,n);
for i:= to m do
if ch[i]='+' then
begin
cal(,,n,,,b[i]);
if tree[].mx>t then max(,,n);
end
else if ch[i]='-' then
begin
cal(,,n,,,-b[i]);
if tree[].mi<f then min(,,n);
end
else if ch[i]='*' then
begin
cal(,,n,b[i],,);
if tree[].mx>t then max(,,n);
end
else begin
cal(,,n,,b[i],);
if tree[].mx>t then max(,,n);
end;
ask(,,n);
for i:= to n do
writeln(ans[i]);
end.
bzoj3878的更多相关文章
- BZOJ3878: [Ahoi2014&Jsoi2014]奇怪的计算器
BZOJ3878: [Ahoi2014&Jsoi2014]奇怪的计算器 Description [故事背景] JYY有个奇怪的计算器,有一天这个计算器坏了,JYY希望你能帮助他写 一个程序来模 ...
- 2018.07.25 bzoj3878: [Ahoi2014&Jsoi2014]奇怪的计算器(线段树)
传送门 线段树综合. 让我想起一道叫做siano" role="presentation" style="position: relative;"&g ...
- [暑假的bzoj刷水记录]
(这篇我就不信有网站来扣) 这个暑假打算刷刷题啥的 但是写博客好累啊 堆一起算了 隔一段更新一下. 7月27号之前刷的的就不写了 , 写的累 代码不贴了,可以找我要啊.. 2017.8.27upd ...
随机推荐
- config spec
config_spec Rules for selecting versions of elements to appear in a view APPLICABILITY Product Comma ...
- 九度OJ 1348 数组中的逆序对 -- 归并排序
题目地址:http://ac.jobdu.com/problem.php?pid=1348 题目描述: 在数组中的两个数字,如果前面一个数字大于后面的数字,则这两个数字组成一个逆序对.输入一个数组,求 ...
- 【HeadFirst设计模式】8.模板方法模式
模板方法 定义: 在一个方法中定义一个算法的骨架,而将一些步骤延迟到子类中.模板方法使用得子类可以在不改变算法结构的情况下,重新定义算法中的某些步骤. 策略模式: 定义一个算法家族,并让这些算法可以互 ...
- Nginx 域名转发
例如访问www.b.cn直接跳到www.a.cn上去,又不想多域名捆绑一个目录. server { listen 80; server_name www.b.cn; rewrite ^/(.*)$ h ...
- Oracle配置
1.安装Oracle11g--->通过Database Configuration Assistant创建新数据库 建数据库注意记住数据库名和SID,安装最后一步解锁scott[密码填tiger ...
- LED字符设备驱动实例及测试代码
驱动代码如下: #include <linux/kernel.h>//内核头文件 #include <linux/init.h>//__init等 #include <l ...
- building hadoop2.4.1 on centos7[在centos7上面构建hadoop2.4.1]
本文介绍在centos7上面通过hadoop2.4.1源码构建hadoop distribution 版本,即hadoop的运行版本. 为何要自己building,而不用Apache的distribu ...
- TIBCO ActiveMatrix BPM 生成daa包脚本
Ant 配置: <?xml version="1.0" encoding="UTF-8" ?> <project name="pro ...
- JavaScript: top对象
一般的JS书里都会在讲框架集的时候讲top,这会让人误解,认为top对象只是代表框架集,其实top的含义应该是说浏览器直接包含的那一个页面对象,也就是说如果你有一个页面被其他页面以iframe的方式包 ...
- js二级下拉菜单
看似简单的一个菜单,确需要不少的知识点 1. getByClass getElementsByClassName 已经有大部分现代浏览器支持了,只有ie6,ie7,ie8是不支持的.所以对ie6,7, ...