设读入的数组是a,树状数组用来维护a数组区间和sum,线段树用来维护一个另一个数组ssum的区间和,区间每个点a[i]*(n-i+1),那么l-r的答案是l-r的ssum-(n-r)*(sum[r]-sum[l-1]) (纸上画一下就知道了) #include<bits/stdc++.h> using namespace std; const int maxn=100010; int n,q,ql,qr,p; long long v,_sum; long long sum[maxn],ssum…
线段树,假设求(x1,y1)点的贡献,就找所有比该点出现时间晚,且x坐标大于x1的点中y最大的,贡献就是Y-y1,由于题目条件限制,不可能有x坐标大于(x1,y1)且y坐标大于y1的点,所以贡献肯定为正. 思路参考了这篇博客:https://blog.csdn.net/qq_39599067/article/details/82560005#accode. #include<bits/stdc++.h> using namespace std; ; struct node{ int x,y;…
题目链接:https://pintia.cn/problem-sets/1036903825309761536/problems/1041156323504345088 题意:小明从某一点出发,向右方前进,只有路口是绿灯(用1代表)的时候才可通行,红灯要等待,所有红绿灯每过一秒变化一次(红->绿,绿->红),问从任意一点到该点右边的任意一点的所花费的时间和. 题解:设t(1,n)是从点1到点n所花费的时间,我们可以经过特殊的判断t(1,n)拆分成t(1,a)+t(a,n)+c (c是1,-1,…
The best programmers of Embezzland compete to develop a part of the project called "e-Government" — the system of automated statistic collecting and press analysis. We know that any of the k citizens can become a member of the Embezzland governm…
H.Ryuji doesn't want to study 27.34% 1000ms 262144K   Ryuji is not a good student, and he doesn't want to study. But there are n books he should learn, each book has its knowledge a[i]a[i]. Unfortunately, the longer he learns, the fewer he gets. That…
https://nanti.jisuanke.com/t/31460 题意 两个操作.1:查询区间[l,r]的和,设长度为L=r-l+1, sum=a[l]*L+a[l+1]*(L-1)+...+a[r].2:将第a个位置修改为b. 分析 变形一下,sum=a[l]*(r-l+1)+a[l+1]*(r-(l+1)-1)+...+a[r](r-r+1)=(r+1)*a[l]-a[l]*l.因此,可维护两个树状数组计算.至于更新操作,实质就是看变化前后的差值,变大就相当与加上差值,否则就是减.注意用…
题意 给出一个有根树(根是1),有n个结点.初始的时候每个结点的值都是0.下面有q个操作,操作有两种,操作1.将深度为L的点的值全部增加X.操作2.查询以x为根的子树的结点值得和. 其中N,Q<=1e5 分析 一看这种没有办法直接用数据结构解决得问题就要考虑分块.这个题其实也不算是分块,应该是用了分块的思想进行分类而已.场上也一直在想分块但是可能是自己太菜了,赛后看了题解补的. 分块最重要的就是算时间复杂度啊.我们按照每一层的结点数进行分类.节点数>block的为第一类,节点数<=为第二…
题意:给你数组a,有两个操作 1 l r,计算l到r的答案:a[l]×L+a[l+1]×(L−1)+⋯+a[r−1]×2+a[r] (L is the length of [ l, r ] that equals to r - l + 1),或者 2 i b:把第i个换成b 思路:用一个树状数组存i的前缀和,再用一个树状数组存(n - i + 1)*a[ i ]的前缀和,这样算出后面那个的区间差减去前一个的区间差的某个倍数就会成为答案. 代码: #include<queue> #include…
Output For each question, output one line with one integer represent the answer. 样例输入 5 3 1 2 3 4 5 1 1 3 2 5 0 1 4 5 样例输出 10 8两个树状数组一个维护a[i]前缀合,一个维护(n-i+1)*a[i]前缀和. #include <iostream> #include <algorithm> #include <cstring> #include &l…
Trace There's a beach in the first quadrant. And from time to time, there are sea waves. A wave ( xxx , yyy ) means the wave is a rectangle whose vertexes are ( 000 , 000 ), ( xxx , 000 ), ( 000 , yyy ), ( xxx , yyy ). Every time the wave will wash o…