好题,初看以为只要差分然后维护相同的段数目
但是请注意下面的情况
2 3 5 8 9
 1 2 3 4 这显然答案是3而不是4
因此我们还要再维护ld,rd表示左右单独的段长度
和s表示不包括左右单独的段,中间部分最少划分成几个等差数列
具体维护见程序,比较复杂,但其实不难
这题还有一个坑爹的地方,我一开始忘开int64本地测数据竟然全能过
但是交上去就WA……感人肺腑

 type node=record
l,r:int64;
ld,rd,s:longint;
end; var tree:array[..*] of node;
lazy:array[..*] of int64;
a:array[..] of longint;
n,m,i,x0,y0,x,y,p,q:longint;
z:int64;
ans:node;
ch:char; procedure update(var a:node;x,y:node);
begin
a.l:=x.l;
a.r:=y.r;
a.ld:=x.ld;
if x.s= then //x.s=说明左部分全是单独的(没有连续出现2个及以上的)
begin
if x.r<>y.l then inc(a.ld,y.ld)
else dec(a.ld);
end;
a.rd:=y.rd;
if y.s= then
begin
if x.r<>y.l then inc(a.rd,x.rd)
else dec(a.rd);
end;
a.s:=x.s+y.s;
if x.s= then //以下请自行理解
begin
if x.r=y.l then
begin
if y.s= then inc(a.s)
else if (y.ld>) then inc(a.s,(y.ld-) shr +);
end;
end
else if x.rd> then
begin
if x.r=y.l then
begin
inc(a.s,(x.rd-) shr );
if y.s= then inc(a.s)
else if (y.ld>) then inc(a.s,(y.ld-) shr +);
end
else if y.s> then
inc(a.s,(x.rd+y.ld) shr );
end
else begin
if x.r=y.l then
begin
if (y.s>) and (y.ld>) then inc(a.s,(y.ld-) shr );
if (y.s>) and (y.ld=) then dec(a.s);
end
else if (y.s>) and (y.ld>) then inc(a.s,y.ld shr );
end;
end; procedure push(i:longint);
begin
inc(lazy[i*],lazy[i]);
inc(tree[i*].l,lazy[i]);
inc(tree[i*].r,lazy[i]);
inc(lazy[i*+],lazy[i]);
inc(tree[i*+].l,lazy[i]);
inc(tree[i*+].r,lazy[i]);
lazy[i]:=;
end; procedure build(i,l,r:longint);
var m:longint;
begin
if l=r then
begin
tree[i].l:=a[l+]-a[l];
tree[i].r:=a[l+]-a[l];
tree[i].ld:=;
tree[i].rd:=;
end
else begin
m:=(l+r) shr ;
build(i*,l,m);
build(i*+,m+,r);
update(tree[i],tree[i*],tree[i*+]);
end;
end; procedure add(i,l,r:longint);
var m:longint;
begin
if (x<=l) and (y>=r) then
begin
inc(tree[i].l,z);
inc(tree[i].r,z);
lazy[i]:=lazy[i]+z;
end
else begin
if lazy[i]<> then push(i);
m:=(l+r) shr ;
if x<=m then add(i*,l,m);
if y>m then add(i*+,m+,r);
update(tree[i],tree[i*],tree[i*+]);
end;
end; function ask(i,l,r:longint):node;
var s,s1,s2:node;
m:longint;
begin
if (x<=l) and (y>=r) then exit(tree[i])
else begin
m:=(l+r) shr ;
if lazy[i]<> then push(i);
if y<=m then exit(ask(i*,l,m));
if x>m then exit(ask(i*+,m+,r));
s1:=ask(i*,l,m);
s2:=ask(i*+,m+,r);
update(s,s1,s2);
exit(s);
end;
end; begin
readln(n);
for i:= to n do
readln(a[i]);
dec(n);
build(,,n);
readln(m);
for i:= to m do
begin
read(ch);
if ch='A' then
begin
readln(x0,y0,p,q);
if x0> then //修改要分三种情况
begin
x:=x0-; y:=x0-; z:=p;
add(,,n);
end;
if y0<=n then
begin
x:=y0; y:=y0; z:=-int64(p)-int64(y0-x0)*int64(q);
add(,,n);
end;
if x0<y0 then
begin
x:=x0; y:=y0-; z:=q;
add(,,n);
end;
end
else begin
readln(x,y);
if y=x then writeln()
else begin
dec(y);
ans:=ask(,,n);
if ans.s= then writeln((y-x+) shr ) //全是单独的可以直接算出来
else writeln(ans.s+(ans.ld+) shr +(ans.rd+) shr );
end;
end;
end;
end.

bzoj1558的更多相关文章

  1. 【BZOJ1558】等差数列(线段树)

    [BZOJ1558]等差数列(线段树) 题面 BZOJ 题解 可以说这道题已经非常毒瘤了 怎么考虑询问操作? 如果直接将一段数分解为等差数列? 太麻烦了.... 考虑相邻的数做差, 这样等差数列变为了 ...

  2. BZOJ1558 [JSOI2009]等差数列 【线段树】

    题目链接 BZOJ1558 题解 等差数列,当然是差分一下 差分值相同的连续位置形成等差数列,我们所选的两个等差数列之间可以有一个位置舍弃 例如: \(1 \; 2 \; 3 \; 6 \; 8 \; ...

  3. [bzoj1558][JSOI2009]等差数列

    题目:给定n个数,m个操作,每次给一段区间加一个等差数列或者询问一段区间至少要用多少个等差数列来表示.$n,m\leqslant 10^{5}$ 题解:老套路,维护差分数组,修改操作变成了两个单点加和 ...

  4. 洛谷P4243/bzoj1558 [JSOI2009]等差数列(线段树维护差分+爆炸恶心的合并)

    题面 首先感谢这篇题解,是思路来源 看到等差数列,就会想到差分,又有区间加,很容易想到线段树维护差分.再注意点细节,\(A\)操作完美解决 然后就是爆炸恶心的\(B\)操作,之前看一堆题解的解释都不怎 ...

  5. BZOJ1558 等差数列

    题目链接:戳我 实话实话,看了几篇题解真的没看懂,我觉得讲的都有问题.这里对于线段树维护的s写了一点我自己的理解. 看到等差数列,我们考虑对数列做差,这样如果是等差数列,那么值应该相等.(比较容易维护 ...

  6. 线段树 by yyb

    线段树 by yyb Type1 维护特殊信息 1.[洛谷1438]无聊的数列 维护一个数列,两种操作 1.给一段区间加上一个等差数列 2.单点询问值 维护等差数列 不难发现,等差数列可以写成\(ad ...

  7. OI题目类型总结整理

    ## 本蒟蒻的小整理qwq--持续更新(咕咕咕) 数据结构 数据结构 知识点梳理 数据结构--线段树 推荐yyb dalao的总结--戳我 以后维护线段树还是把l,r写到struct里面吧,也别写le ...

随机推荐

  1. box-shadow 与 filter:drop-shadow 详解及奇技淫巧

    box-shadow 在前端的 CSS 编写工作想必十分常见.但是 box-shadow 除去它的常规用法,其实还存在许多不为人知的奇技淫巧. 喜欢 markdown 版本的可以戳这里. box-sh ...

  2. js的变量作用域

    js不支持块级变量作用域,而是包含它们的函数的作用域, 例如: function query() { ; ; i < ; i++) { var b = i; } return b + a; } ...

  3. Java_Web学习笔记_过滤器应用案例(解决全站字符乱码)

    解决全站字符乱码(POST和GET中文编码问题) servlet: l  POST:request.setCharacterEncoding(“utf-8”); l  GET: String user ...

  4. ios fixed属性bug解决方法

    在内容层外面包一个div 加上样式:position:fixed;top:0px; bottom:50px;overflow:scroll; 就可以完美解决

  5. ios专题 - 图片(UIImage)获取方法

    说到图片获取的方法,就得看API文档. UIImage生成实例的方法有: 1)imageNamed 从指定文件返回对象. 这个方法有个比较特殊的地方:该方法首先从系统缓存中寻找该图片,如果有,则从缓存 ...

  6. Linux的前世今生

    Linux的起源 说到Linux[/ˈlɪnəks/],想必大家也会自然而然地想到他的创始人——被称为“Linux之父”的林纳斯·托瓦兹(Linus Torvalds).其实,在Linux出现之前,还 ...

  7. CCPC网络赛,HDU_5842 Lweb and String

    Problem Description Lweb has a string $S$. Oneday, he decided to transform this string to a new sequ ...

  8. C++类继承内存布局(一)

    转自:http://blog.csdn.net/jiangyi711/article/details/4890889# 一 类布局 不同的继承方式将导致不同的内存布局 1)C结构 C++基于C,所以C ...

  9. leetcode problem 6 ZigZag Conversion

    The string "PAYPALISHIRING" is written in a zigzag pattern on a given number of rows like ...

  10. 使用sqlmap注入DVWA的SQL Injection菜单

    1 使用sqlmap注入DVWA的SQL Injection菜单 本教程中的登陆地址:http://192.168.0.112/dvwa/login.php 1.1 获取cookie信息 1) 使用a ...