[题目链接] 点击打开链接 [算法] 本题用线段树很容易写,但是,笔者为了练习树状数组,就用树状数组的方法做了一遍 我们不妨引入差分数组c, 则sum(n) = c[1] + (c[1] + c[2]) + (c[1] + c[2] + c[3]) + ... + (c[1] + c[2] + c[3] + ... + c[n]) = n * c[1] + (n - 1) * c[2] + (n - 2) * c[3] + ... + c[n] = n * (c[1] + c[2] + c[3]…
1548:[例 2]A Simple Problem with Integers 题目描述 这是一道模板题. 给定数列 a[1],a[2],…,a[n],你需要依次进行 q 个操作,操作有两类: 1 l r x:给定 l,r,x,对于所有 i∈[l,r],将 a[i] 加上 x(换言之,将 a[l],a[l+1],…,a[r] 分别加上 x): 2 l r:给定 l,r,求 a[i]∑i=[l,r].​a[i] 的值(换言之,求 a[l]+a[l+1]+⋯+a[r] 的值). 输入格式 第一行包…
A Simple Problem with Integers Time Limit: 5000MS   Memory Limit: 131072K Total Submissions: 141093   Accepted: 43762 Case Time Limit: 2000MS Description You have N integers, A1, A2, ... , AN. You need to deal with two kinds of operations. One type o…
Description You have N integers, A1, A2, ... , AN. You need to deal with two kinds of operations. One type of operation is to add some given number to each number in a given interval. The other is to ask for the sum of numbers in a given interval. In…
A Simple Problem with Integers Case Time Limit: 2000MS Description You have N integers, A1, A2, ... , AN. You need to deal with two kinds of operations. One type of operation is to add some given number to each number in a given interval. The other i…
http://poj.org/problem?id=3468 _(:зゝ∠)_我又活着回来啦,前段时间太忙了写的题没时间扔上来,以后再说. [问题描述] 成段加某一个值,然后询问区间和. [思路] 讲一下pushdown和pushup出现的几个位置. pushup: (1)build的结尾,当叶子节点分别有对应的值后,它的父亲们就等于它们求和. (2)update的结尾,因为此时当前根的左右孩子已经更新了,故它也需要更新. pushdown(延迟标记): *pushdown会出现在一切要从当前结…
[题目链接] http://poj.org/problem?id=2891 [算法] exgcd [代码] #include <algorithm> #include <bitset> #include <cctype> #include <cerrno> #include <clocale> #include <cmath> #include <complex> #include <cstdio> #incl…
http://poj.org/problem?id=3468 (题目链接) 题意 给出一个序列,要求维护区间修改与区间求和操作. Solution 多年以前学习的树状数组区间修改又忘记了→_→. 其实就是用树状数组维护一个差分序列${delta[i]}$,${delta[x]}$记录${[i,n]}$中每一个数的增量,每次修改${[l,r]}$就转化为了${delta[l]+=d,delta[r+1]-=d}$. 对于求和操作${[l,r]}$,其实就是${sum(x)-sum(y)}$,我们这…
Description You have N integers, A1, A2, ... , AN. You need to deal with two kinds of operations. One type of operation is to add some given number to each number in a given interval. The other is to ask for the sum of numbers in a given interval. In…
Time Limit: 5000MS   Memory Limit: 131072K Total Submissions: 97008   Accepted: 30285 Case Time Limit: 2000MS Description You have N integers, A1, A2, ... , AN. You need to deal with two kinds of operations. One type of operation is to add some given…
Description You have N integers, A1, A2, ... , AN. You need to deal with two kinds of operations. One type of operation is to add some given number to each number in a given interval. The other is to ask for the sum of numbers in a given interval. In…
两个木条装雨水能装多少. 两线段相交,且不遮盖的情况下才可能装到水. 求出交点,再取两线段的较高端点的较小值h,(h-交点的y)为三角形的高. 三角形的宽即为(h带入两条线段所在直线得到的横坐标的差值). 三角形的面积即为雨水的量. 坑点:如果用G++提交,ans要加上eps才能过,c++提交则没问题. #include <iostream> #include <cmath> #include <cstdio> #define MAX 1<<31 #defi…
题意 求$ \sum_{i=1}^n gcd(i,n) $ 给定 $n(1\le n\le 2^{32}) $. 链接 题解 欧拉函数 $φ(x)$ :1到x-1有几个和x互质的数. gcd(i,n)必定是n的一个约数. 若p是n的约数,那么gcd(i,n)==p的有$φ(n/p)$个数,因为要使gcd(i,n)==p,i/p和n/p必须是互质的. 那么就是求i/p和n/p互质的i在[1,n]里有几个,就等价于 1/p,2/p,...,n/p 里面有几个和n/p互质,即φ(n/p). 求和的话,…
Description Elina is reading a book written by Rujia Liu, which introduces a strange way to express non-negative integers. The way is described as following: Choose k different positive integers a1, a2, -, ak. For some non-negative m, divide it by ev…
题意:Elina看一本刘汝佳的书(O_O*),里面介绍了一种奇怪的方法表示一个非负整数 m .也就是有 k 对 ( ai , ri ) 可以这样表示--m%ai=ri.问 m 的最小值. 解法:拓展欧几里德求解同余方程组的最小非负整数解.(感觉挺不容易的......+_+@) 先看前2个关系式:                       m%a1=r1 和 m%a2=r2 →                                                           …
A Simple Problem with Integers [题目链接]A Simple Problem with Integers [题目类型]线段树 成段增减+区间求和 &题解: 线段树 成段增减+区间求和 模板题 这种题真的应该理解并且可以流畅的独立码出来了 [时间复杂度]\(O(nlogn)\) &代码: #include <iostream> #include <cstdio> #include <cstring> using namespa…
题目:id=3468" target="_blank">poj 3468 A Simple Problem with Integers 题意:给出n个数.两种操作 1:l -- r 上的全部值加一个值val 2:求l---r 区间上的和 分析:线段树成段更新,成段求和 树中的每一个点设两个变量sum 和 num ,分别保存区间 l--r 的和 和l---r 每一个值要加的值 对于更新操作:对于要更新到的区间上面的区间,直接进行操作 加上 (r - l +1)* val…
A Simple Problem with Integers Time Limit: 5000MS   Memory Limit: 131072K Total Submissions: 86780   Accepted: 26950 Case Time Limit: 2000MS Description You have N integers, A1, A2, ... , AN. You need to deal with two kinds of operations. One type of…
A Simple Problem with Integers Time Limit: 5000MS   Memory Limit: 131072K Total Submissions: 79137   Accepted: 24395 Case Time Limit: 2000MS Description You have N integers, A1, A2, ... , AN. You need to deal with two kinds of operations. One type of…
A Simple Problem with Integers Time Limit:5000MS   Memory Limit:131072K Case Time Limit:2000MS Description You have N integers, A1, A2, ... , AN. You need to deal with two kinds of operations. One type of operation is to add some given number to each…
题目链接:id=3468http://">http://poj.org/problem? id=3468 A Simple Problem with Integers Time Limit: 5000MS   Memory Limit: 131072K Total Submissions: 83959   Accepted: 25989 Case Time Limit: 2000MS Description You have N integers, A1, A2, ... , AN. Yo…
题目链接:http://poj.org/problem?id=3468 A Simple Problem with Integers Time Limit: 5000MS   Memory Limit: 131072K Total Submissions: 144616   Accepted: 44933 Case Time Limit: 2000MS Description You have N integers, A1, A2, ... , AN. You need to deal with…
POJ.3468 A Simple Problem with Integers(线段树 区间更新 区间查询) 题意分析 注意一下懒惰标记,数据部分和更新时的数字都要是long long ,别的没什么大坑. 代码总览 #include <cstdio> #include <cstring> #include <algorithm> #define nmax 200000 using namespace std; struct Tree{ int l,r; long lon…
A Simple Problem with Integers Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://poj.org/problem?id=3468 Description You have N integers, A1, A2, ... , AN. You need to deal with two kinds of operations. One type of operation is to add some given nu…
题目链接:http://poj.org/problem?id=3468 A Simple Problem with Integers Time Limit: 5000MS   Memory Limit: 131072K Total Submissions: 56005   Accepted: 16903 Case Time Limit: 2000MS Description You have N integers, A1, A2, ... , AN. You need to deal with…
A Simple Problem with Integers Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://poj.org/problem?id=3468 Description You have N integers, A1, A2, ... , AN. You need to deal with two kinds of operations. One type of operation is to add some given nu…
题目传送门 /* 线段树-成段更新:裸题,成段增减,区间求和 注意:开long long:) */ #include <cstdio> #include <iostream> #include <algorithm> #include <cstring> #include <cmath> using namespace std; #define lson l, mid, rt << 1 #define rson mid + 1, r,…
A Simple Problem with Integers Time Limit: 5000MS   Memory Limit: 131072K Total Submissions: 58269   Accepted: 17753 Case Time Limit: 2000MS Description You have N integers, A1, A2, ... , AN. You need to deal with two kinds of operations. One type of…
A Simple Problem with Integers Description You have N integers, A1, A2, ... , AN. You need to deal with two kinds of operations. One type of operation is to add some given number to each number in a given interval. The other is to ask for the sum of…
A Simple Problem with Integers Time Limit: 5000MS   Memory Limit: 131072K Total Submissions: 69589   Accepted: 21437 Case Time Limit: 2000MS Description You have N integers, A1, A2, ... , AN. You need to deal with two kinds of operations. One type of…