P1438 无聊的数列
P1438 无聊的数列
分析:
等差数列可加,首项相加,公差相加。
代码:
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cmath>
#include<cctype>
#include<set>
#include<queue>
#include<vector>
#include<map>
#include<bitset>
using namespace std;
typedef long long LL; inline int read() {
int x=,f=;char ch=getchar();for(;!isdigit(ch);ch=getchar())if(ch=='-')f=-;
for(;isdigit(ch);ch=getchar())x=x*+ch-'';return x*f;
} const int N = 1e5 + ;
int A[N << ], D[N << ], ori[N]; void pushdown(int rt,int l,int r) {
int mid = (l + r) >> ;
A[rt << ] += A[rt];
A[rt << | ] += A[rt] + (mid - l + ) * D[rt];
D[rt << ] += D[rt];
D[rt << | ] += D[rt];
A[rt] = D[rt] = ;
}
void update(int l,int r,int rt,int L,int R,int a,int d) {
if (L <= l && r <= R) {
A[rt] += a + (l - L) * d; D[rt] += d; return ;
}
if (A[rt] || D[rt]) pushdown(rt, l, r);
int mid = (l + r) >> ;
if (L <= mid) update(l, mid, rt << , L, R, a, d);
if (R > mid) update(mid + , r, rt << | , L, R, a, d);
}
int query(int l,int r,int rt,int p) {
if (l == r) return ori[l] + A[rt];
if (A[rt] || D[rt]) pushdown(rt, l, r);
int mid = (l + r) >> ;
if (p <= mid) return query(l, mid, rt << , p);
else return query(mid + , r, rt << | , p);
}
int main() {
int n = read(), m = read();
for (int i = ; i <= n; ++i) ori[i] = read();
while (m --) {
if (read() == ) {
int l = read(), r = read(), a = read(), d = read();
update(, n, , l, r, a, d);
}
else {
int x = read();
cout << query(, n, , x) << "\n";
}
}
return ;
}
P1438 无聊的数列的更多相关文章
- P1438 无聊的数列 (差分+线段树)
题目 P1438 无聊的数列 解析: 先考虑修改,用差分的基本思想,左端点加上首项\(k\),修改区间\((l,r]\)内每个数的差分数组都加上公差\(d\),最后的\(r+1\)再减去\(k+(r- ...
- [luogu P1438] 无聊的数列
[luogu P1438] 无聊的数列 题目背景 无聊的YYB总喜欢搞出一些正常人无法搞出的东西.有一天,无聊的YYB想出了一道无聊的题:无聊的数列...(K峰:这题不是傻X题吗) 题目描述 维护一个 ...
- Luogu P1438无聊的数列
洛谷 P1438无聊的数列 题目链接 点这里! 题目描述 维护一个数列\(a_i\),支持两种操作: 给出一个长度等于 \(r-l+1\)的等差数列,首项为\(k\) 公差为\(d\) 并将它对应加到 ...
- 洛谷P1438 无聊的数列 [zkw线段树]
题目传送门 无聊的数列 题目背景 无聊的YYB总喜欢搞出一些正常人无法搞出的东西.有一天,无聊的YYB想出了一道无聊的题:无聊的数列...(K峰:这题不是傻X题吗) 题目描述 维护一个数列{a[i]} ...
- 洛谷 P1438 无聊的数列
题目背景 无聊的YYB总喜欢搞出一些正常人无法搞出的东西.有一天,无聊的YYB想出了一道无聊的题:无聊的数列...(K峰:这题不是傻X题吗) 题目描述 维护一个数列{a[i]},支持两种操作: 1.1 ...
- [洛谷P1438] 无聊的数列
题目类型:差分,线段树 传送门:>Here< 题意:给出一个数列,每次给一个区间对应的加上一个等差数列,并询问某一个元素目前的值. 解题思路 所谓差分,我个人的理解就是用\(O(1)\)的 ...
- LUOGU P1438 无聊的数列 (差分+线段树)
传送门 解题思路 区间加等差数列+单点询问,用差分+线段树解决,线段树里维护的就是差分数组,区间加等差数列相当于在差分序列中l位置处+首项的值,r+1位置处-末项的值,中间加公差的值,然后单点询问就相 ...
- 洛谷 P1438 无聊的数列 题解
原题链接 首先,我们考虑用差分解决问题. 用 \(x_i\) 表示原数列,\(a_i = x_i - x_{i-1}\) 那么,先普及一下差分: 如果我们只需要维护区间加值,单点求值的话,你会发现两个 ...
- P1438 无聊的数列 (线段树)
题目链接 Solution 直接维护一个差分的线段树就好了. 其中线段树的节点代表 \(r\) 比 \(l\) 多多少. Code #include<bits/stdc++.h> #def ...
随机推荐
- Android 动态渐变按钮
先上个图 看着特别炫酷吧 其实就是自定义颜色两秒轮播动画 AnimationDrawable animationDrawable = (AnimationDrawable) button.getBac ...
- IDEA报错: Injection of autowired dependencies failed; nested exception is java.lang.IllegalArgumentException: Could not resolve placeholder 'spring.datasource.url' in value "${spring.datasource.url}"
运行审核流模块: 在ActivitiServiceApplication模块日志报错: Error starting ApplicationContext. To display the auto-c ...
- 【Java入门提高篇】Day23 Java容器类详解(六)HashMap源码分析(中)
上一篇中对HashMap中的基本内容做了详细的介绍,解析了其中的get和put方法,想必大家对于HashMap也有了更好的认识,本篇将从了算法的角度,来分析HashMap中的那些函数. HashCod ...
- char/varchar/nvarchar的区别
原文:https://blog.csdn.net/w516162189/article/details/78914035 我们在设计数据库的时候,需要根据需求场景选择合适的字段类型,对数据的执行效率有 ...
- 利用Spring的AbstractRoutingDataSource解决多数据源的问题
多数据源问题很常见,例如读写分离数据库配置. 原来的项目出现了新需求,局方要求新增某服务器用以提供某代码,涉及到多数据源的问题. 解决方法如下: 1.首先配置多个datasource <bean ...
- 【PAT】B1065 单身狗(25 分)
#include<stdio.h> #include<algorithm> #include<math.h> using namespace std; int ca ...
- IntelliJ IDEA 创建Spring项目
第一步:点击file --> new --> project... 第二步: 在左侧选择Spring, 然后勾选Spring , 最后点击Next 第三步 : 填写项目名称和项目地址,点击 ...
- PyQt5--TextDrag
# -*- coding:utf-8 -*- ''' Created on Sep 21, 2018 @author: SaShuangYiBing Comment: ''' import sys f ...
- (转)postgresql+postgis空间数据库使用总结
转载地址:https://blog.csdn.net/qq_36588972/article/details/78902195 参考资料: pgrouting路径导航 https://www.cnbl ...
- python五十六课——正则表达式(常用函数之findall)
4).函数:findall(regex,string,[flags=0]): 参数: 和match.search一样理解 功能: 将所有匹配成功的子数据(子串),以列表的形式返回: 如果一个都没有匹配 ...