poj3468 A Simple Problem with Integers 题意:O(-1) 思路:O(-1) 线段树功能:update:成段增减 query:区间求和 Sample Input 10 5 1 2 3 4 5 6 7 8 9 10 Q 4 4 Q 1 10 Q 2 4 C 3 6 3 Q 2 4 Sample Output 4 55 9 15 Hint The sums may exceed the range of 32-bit integers. 题目大意:   N个数 M…
A Simple Problem with Integers Time Limit: 10000MS Memory Limit: 65536K 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 interv…
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…
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…
参考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){//用于用子区间重新计算该…
思路:线段树,区间更新,区间查找 #include<iostream> #include<vector> #include<string> #include<cmath> #include<set> #include<algorithm> #include<cstdio> #include<map> #include<cstring> #include<list> #define MAX…
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. Input The firs…
题目链接:https://cn.vjudge.net/problem/POJ-3468 题目大意:区间加减+区间查询操作. 具体思路:本来是一个线段树裸题,为了学习分块就按照分块的方法做吧. 分块真的好暴力,,,(但是还是挺优美的). 说一下各个数组的作用. a数组,代表每一个点的值. sum数组,代表分块后每一段的值. add数组,相当于线段树中的lazy标记,记录的数当前这一整段添加的值. l数组,r数组,记录每一段的左端点和右端点. belong数组,记录每一个数属于哪一个分块中. AC代…
https://vjudge.net/contest/66989#problem/C #include<iostream> #include<cstdio> #include<cstring> #include<string> #include<algorithm> #include<cmath> #define lson (i<<1) #define rson (i<<1|1) typedef long lo…
//add,懒标记,给以当前节点为根的子树中的每一个点加上add(不包含根节点) // #include <cstdio> #include <cstring> #include <iostream> #include <algorithm> using namespace std; typedef long long LL; ; int n, m; int w[N]; struct Node { int l, r; //总和 //如果只考虑当前节点及子节点…