https://www.luogu.org/problemnew/show/P4243#sub

自己的思路错了

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring> using namespace std;
const int N = 1e5 + ; #define gc getchar() int F[N << ], tot[N << ], l_col[N << ], r_col[N << ];
int n, Ty, Answer;
int my[N], data[N]; inline int read() {
int x = , f = ; char c = gc;
while(c < '' || c > '') {if(c == '-') f = -; c = gc;}
while(c >= '' && c <= '') x = x * + c - '', c = gc;
return x * f;
} #define lson jd << 1
#define rson jd << 1 | 1 void Push_up(int jd) {
l_col[jd] = l_col[lson]; r_col[jd] = r_col[rson];
tot[jd] = tot[lson] + tot[rson];
if(r_col[lson] == l_col[rson]) tot[jd] --;
return ;
} void Build_tree(int l, int r, int jd) {
if(l == r) {l_col[jd] = r_col[jd] = data[l]; tot[jd] = ; return ;}
int mid = (l + r) >> ;
Build_tree(l, mid, lson);
Build_tree(mid + , r, rson);
Push_up(jd);
} void Push_down(int jd) {
F[lson] += F[jd]; F[rson] += F[jd];
l_col[lson] += F[jd]; r_col[lson] += F[jd];
l_col[rson] += F[jd]; r_col[rson] += F[jd];
F[jd] = ;
return ;
} void Poi_G(int l, int r, int jd, int x, int num) {
if(l == r) {l_col[jd] += num; r_col[jd] += num; return ;}
if(F[jd]) Push_down(jd);
int mid = (l + r) >> ;
if(x <= mid) Poi_G(l, mid, lson, x, num);
else Poi_G(mid + , r, rson, x, num);
Push_up(jd);
} void Sec_G(int l, int r, int jd, int x, int y, int num) {
if(x <= l && r <= y) {F[jd] += num; l_col[jd] += num; r_col[jd] += num; return ;}
if(F[jd]) Push_down(jd);
int mid = (l + r) >> ;
if(x <= mid) Sec_G(l, mid, lson, x, y, num);
if(y > mid) Sec_G(mid + , r, rson, x, y, num);
Push_up(jd);
} void Sec_A(int l, int r, int jd, int x, int y) {
if(x <= l && r <= y) {Answer += tot[jd]; return ;}
if(F[jd]) Push_down(jd);
int mid = (l + r) >> ;
if(x <= mid) Sec_A(l, mid, lson, x, y);
if(y > mid) Sec_A(mid + , r, rson, x, y);
if(x <= mid && y > mid && r_col[lson] == l_col[rson]) Answer --;
} int main() {
n = read();
for(int i = ; i <= n; i ++) my[i] = read();
for(int i = ; i <= n; i ++) data[i] = my[i] - my[i - ];
Build_tree(, n, );
Ty = read();
while(Ty --) {
string s; cin >> s;
if(s[] == 'A') {
int l = read(), r = read(), a = read(), b = read();
int imp = a + (r - l) * b;
if(l != ) Poi_G(, n, , l, a);
Sec_G(, n, , l + , r, b);
Poi_G(, n, , r + , - imp);
} else {
Answer = ;
int l = read(), r = read();
if(l == r) {cout << "" << endl; continue ;}
Sec_A(, n, , l, r);
cout << Answer << endl;
}
}
return ;
}

https://www.cnblogs.com/zbtrs/p/8424737.html

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm> using namespace std; typedef long long ll; const ll maxn = ;
ll n,a[maxn],b[maxn],q; struct node {
ll ls,rs,lsize,rsize,sum,tag,sizee;
void init() {
ls = rs = lsize = rsize = sum = tag = sizee = ;
}
} e[maxn]; void pushdown(ll o) {
if (e[o].tag) {
e[o * ].tag += e[o].tag;
e[o * + ].tag += e[o].tag;
e[o * ].ls += e[o].tag;
e[o * + ].ls += e[o].tag;
e[o * ].rs += e[o].tag;
e[o * + ].rs += e[o].tag;
e[o].tag = ;
}
} node pushup(node a,node b) {
bool flag = (a.rs == b.ls);
node c;
c.init();
c.ls = a.ls;
c.rs = b.rs;
c.sizee = a.sizee + b.sizee;
c.sum = a.sum + b.sum;
if (a.sum == && b.sum == ) {
if (!flag) {
c.lsize = a.sizee + b.sizee;
c.rsize = a.sizee + b.sizee;
} else {
c.lsize = a.lsize - ;
c.rsize = b.rsize - ;
++c.sum;
}
return c;
}
if (a.sum == ) {
c.rsize = b.rsize;
if (!flag)
c.lsize = a.sizee + b.lsize;
else {
c.lsize = a.lsize - ;
if (b.lsize > )
c.sum += (b.lsize - ) / + ;
}
return c;
}
if (b.sum == ) {
c.lsize = a.lsize;
if (!flag)
c.rsize = b.sizee + a.rsize;
else {
c.rsize = b.rsize - ;
if (a.rsize > )
c.sum += (a.rsize - ) / + ;
}
return c;
}
c.lsize = a.lsize;
c.rsize = b.rsize;
if (a.rsize == && b.lsize == ) {
if (flag)
c.sum--;
return c;
}
if (a.rsize == ) {
if (flag)
c.sum += (b.lsize - ) / ;
else
c.sum += b.lsize / ;
return c;
}
if (b.lsize == ) {
if (flag)
c.sum += (a.rsize - ) / ;
else
c.sum += a.rsize / ;
return c;
}
ll minn = (a.rsize + b.lsize) / ;
if (flag)
minn = min(minn, + (a.rsize - ) / + (b.lsize - ) / );
c.sum += minn;
return c;
} void build(ll o,ll l,ll r) {
if (l == r) {
e[o].init();
e[o].ls = e[o].rs = b[l];
e[o].lsize = e[o].rsize = ;
e[o].sizee = ;
return;
}
ll mid = (l + r) >> ;
build(o * ,l,mid);
build(o * + ,mid + ,r);
e[o] = pushup(e[o * ],e[o * + ]);
} void update1(ll o,ll l,ll r,ll pos,ll v) {
if (l == r) {
e[o].ls += v;
e[o].rs += v;
return;
}
pushdown(o);
ll mid = (l + r) >> ;
if (pos <= mid)
update1(o * ,l,mid,pos,v);
else
update1(o * + ,mid + ,r,pos,v);
e[o] = pushup(e[o * ],e[o * + ]);
} void update2(ll o,ll l,ll r,ll x,ll y,ll v) {
if (x <= l && r <= y) {
e[o].ls += v;
e[o].rs += v;
e[o].tag += v;
return;
}
pushdown(o);
ll mid = (l + r) >> ;
if (x <= mid)
update2(o * ,l,mid,x,y,v);
if (y > mid)
update2(o * + ,mid + ,r,x,y,v);
e[o] = pushup(e[o * ],e[o * + ]);
} node query(ll o,ll l,ll r,ll x,ll y) {
if (x <= l && r <= y)
return e[o];
pushdown(o);
ll mid = (l + r) >> ;
if (y <= mid)
return query(o * ,l,mid,x,y);
else if (x > mid)
return query(o * + ,mid + ,r,x,y);
else
return pushup(query(o * ,l,mid,x,mid),query(o * + ,mid + ,r,mid + ,y));
} int main() {
scanf("%lld",&n);
for (ll i = ; i <= n; i++)
scanf("%lld",&a[i]);
for (ll i = ; i < n; i++)
b[i] = a[i + ] - a[i];
n--;
build(,,n);
scanf("%lld",&q);
while (q--) {
char ch[];
ll s,t,a,b;
scanf("%s",ch);
if (ch[] == 'A') {
scanf("%lld%lld%lld%lld",&s,&t,&a,&b);
if (s != )
update1(,,n,s - ,a);
if (t != n + )
update1(,,n,t,- * ((t - s) * b + a));
if (s <= t - )
update2(,,n,s,t - ,b);
} else {
scanf("%lld%lld",&s,&t);
if (s == t) {
printf("1\n");
continue;
}
node temp = query(,,n,s,t - );
ll res = (t - s + ) / ;
if (temp.sum == )
printf("%lld\n",res);
else {
res = min(res,temp.sum + (temp.lsize + ) / + (temp.rsize + ) / );
printf("%lld\n",res);
}
}
} return ;
}

[Luogu] 等差数列的更多相关文章

  1. luogu P1214 [USACO1.4]等差数列 Arithmetic Progressions

    题目描述 一个等差数列是一个能表示成a, a+b, a+2b,..., a+nb (n=0,1,2,3,...)的数列. 在这个问题中a是一个非负的整数,b是正整数.写一个程序来找出在双平方数集合(双 ...

  2. luogu P4243 [JSOI2009]等差数列 题解

    前言: 这题真ex... 强烈谴责在题解里面放毒瘤题链接的屑出题人! 吐 ️ 解析: 这题分成两步走. 首先,既然题目中的修改操作是区间加等差数列,那么就容易想到在差分数组上进行操作. 然后就是相当恶 ...

  3. 【题解】Luogu P5313 僕たちはひとつの光([Ynoi2012]D2T2)

    原题传送门 lovelive好评 比赛时只拿到了60pts,还是自己太菜了 这题的思想实际有点像Luogu P3674 小清新人渣的本愿与Luogu P5071 [Ynoi2015]此时此刻的光辉 这 ...

  4. luogu P4156 [WC2016]论战捆竹竿

    传送门 官方题解(证明都在这) 神仙题鸭qwq 转化模型,发现这题本质就是一个集合,每次可以加上集合里的数,问可以拼出多少不同的数 首先暴力需要膜意义下的最短路,例题戳这 然后这个暴力可以优化成N^2 ...

  5. [luogu P1438] 无聊的数列

    [luogu P1438] 无聊的数列 题目背景 无聊的YYB总喜欢搞出一些正常人无法搞出的东西.有一天,无聊的YYB想出了一道无聊的题:无聊的数列...(K峰:这题不是傻X题吗) 题目描述 维护一个 ...

  6. [luogu P4230]连环病原体

    [luogu P4230] 连环病原体 题意 给定一个长度为 \(n\) 的边序列, 当这个序列的一个子区间内的边都加入图中时产生了环则称其为"加强区间", 求序列中的每条边在多少 ...

  7. 洛谷 P1214 等差数列

    https://www.luogu.org/problemnew/show/P1214 首先暴力枚举可以凑出来的数,对于每个数进行标记. 对于每一个等差数列,当我们知道前两个数后即可以得出整个序列,那 ...

  8. 「Luogu 3792」由乃与大母神原型和偶像崇拜

    更好的阅读体验 Portal Portal1: Luogu Description 给你一个序列\(a\) 每次两个操作: 修改\(x\)位置的值为\(y\): 查询区间\([l, r]\)是否可以重 ...

  9. [Luogu P1829] [国家集训队]Crash的数字表格 / JZPTAB (莫比乌斯反演)

    题面 传送门:洛咕 Solution 调到自闭,我好菜啊 为了方便讨论,以下式子\(m>=n\) 为了方便书写,以下式子中的除号均为向下取整 我们来颓柿子吧qwq 显然,题目让我们求: \(\l ...

随机推荐

  1. 关于Linux fontconfig 字体库的坑

    01.安装字体软件 yum -y install fontconfig 然后把字体拷过去就行了 cd /usr/share/fonts fc-list 这是查看 02.拷贝字体到指定目录 cp sim ...

  2. S02_CH13_ AXI_PWM 实验

    S02_CH13_ AXI_PWM 实验 当学习了上一章的协议介绍内容后,开发基于这些协议的方案已经不是什么难事了,关键的一点就是从零到有的突破了.本章就以AXI-Lite总线实现8路LED自定义IP ...

  3. dl in image process

    deep learning目前为止无论在分类还是检测上,都是整体的处理,而不会出现像sift这样的局部特征,这个问题或许如果能克服掉,能让检测效果更进一大步.

  4. Cache的一些总结

    输出缓存 这是最简单的缓存类型,它保存发送到客户端的页面副本,当下一个客户端发送相同的页面请求时,此页面不会重新生成(在缓存有限期内),而是从缓存中获取该页面:当然由于缓存过期或被回收,这时页面会重新 ...

  5. layer,备受青睐的web弹层组件

    //http://layer.layui.com/ 特别说明:事件需自己绑定,以下只展现调用代码. //初体验 layer.alert('内容') //第三方扩展皮肤 layer.alert('内容' ...

  6. 2、wepy安装后提示Cannot read property 'addDeps' 参考自https://www.cnblogs.com/yuanchaoyong/p/11614400.html

    摘抄自https://www.cnblogs.com/yuanchaoyong/p/11614400.html wepy安装步骤 $ npm install @wepy/cli -g # 全局安装 W ...

  7. YoloV3 训练崩溃

    经过排查  发现是这里出了问题 然后发现是标注文件里有 x=0 y=0  这样的数据,46_Jockey_Jockey_46_576.txt ,  那么肯定是标注文件出了问题!! 删除该标注文件即可. ...

  8. element之table自定义表头

    1.实现效果 2.使用render-header可以自定义表头 <el-table-column prop="date" label="日期" sorta ...

  9. centos 6.4系统双网卡绑定配置详解

    Linux双网卡绑定实现就是使用两块网卡虚拟成为一块网卡(需要交换机支持),这个聚合起来的设备看起来是一个单独的以太网接口设备,通俗点讲就是两块网卡具有相同的IP地址而并行链接聚合成一个逻辑链路工作. ...

  10. Windows下Pycharm安装Tensorflow:ERROR: Could not find a version that satisfies the requirement tensorflow

    今天在Windows下通过Pycharm安装Tensorflow时遇到两个问题: 使用pip安装其实原理都相同,只不过Pycharm是图形化的过程! 1.由于使用国外源总是导致Timeout 解决方法 ...