poj 3468(线段树)】的更多相关文章

http://poj.org/problem?id=3468 题意:给n个数字,从A1 …………An m次命令,Q是查询,查询a到b的区间和,c是更新,从a到b每个值都增加x.思路:这是一个很明显的线段树的题目,就是线段树的用区间更新就可以,我也是第一次用.. #include <stdio.h> #include <string.h> #define maxn 100050 long long arra[ maxn ]; struct note{ //要用long long 类型…
http://acm.hdu.edu.cn/showproblem.php?pid=1698 这个题意翻译起来有点猥琐啊,还是和谐一点吧 和涂颜色差不多,区间初始都为1,然后操作都是将x到y改为z,注意 是改为z,不是加或减,最后输出区间总值 也是线段树加lazy操作 #include<cstdio> using namespace std; struct point { int l,r; int val,sum; }; point tree[]; void build(int i,int l…
这些天一直在看线段树,因为临近期末,所以看得断断续续,弄得有些知识点没能理解得很透切,但我也知道不能钻牛角尖,所以配合着刷题来加深理解. 然后,这是线段树裸题,而且是最简单的区间增加与查询,我参考了ACdreamer的模板,在此基础上自己用宏定义来精简了一下代码: #include<cstdio> typedef long long LL; #define root int rt, int l, int r #define lson rt*2, l, mid #define rson rt*2…
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…
这题WA了好久,一直以为是lld和I64d的问题,后来发现是自己的pushdown函数写错了,说到底还是因为自己对线段树理解得不好. 因为是懒惰标记,所以只有在区间分开的时候才会将标记往下传递.更新和查询都要pushdown. #include <cstdio> typedef long long LL; + ; int n, m, qL, qR, v; LL sum[maxn << ], add[maxn << ]; inline void maintain(int…
参考qsc大佬的视频 太强惹 先膜一下 视频在b站 直接搜线段树即可 #include<cstdio> using namespace std; ; int n,a[maxn]; struct Node{ int l,r; long long sum,lazy; void update(long long x){//用于更新区间和 和懒标记 sum+=1ll*(r-l+)*x; lazy+=x; } }tree[maxn*]; void push_up(int x){//用于用子区间重新计算该…
题意:Q是询问区间和,C是在区间内每个节点加上一个值 Sample Input 10 51 2 3 4 5 6 7 8 9 10Q 4 4Q 1 10Q 2 4C 3 6 3Q 2 4Sample Output 455915 # include <iostream> # include <cstdio> # include <cstring> # include <algorithm> # include <cmath> # include &l…
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…
POJ 3468 (Java,c++实现) Java import java.io.*; import java.util.*; public class Main { static int n, m; static final int N = 100005; static int ls[] = new int[N << 2]; static int rs[] = new int[N << 2]; static long M[] = new long[N << 2];…
题意:给你n个数,有对区间的加减操作,问某个区间的和是多少. 思路:状压+线段树(要用lazy标记,否则会TLE) //By SiriusRen #include <cstdio> #include <cstring> #define N 100001 using namespace std; long long tree[N*4],lazy[N*4]; int xx,yy,zz,n,q; char jy; void push_down(int pos,int num){ lazy…