随笔分类 - 数据结构-前后缀维护&差分标记
摘要:上图一共有5个区间,分别是[0,2]、[2,4]、[8,11]、[7,11]、[15,18]。如果要求这些区间合并后区间的大小,有两种简单的方法。 方法一:比较每两个区间的范围,如果两个区间有交集,则合并它们。最后所有区间会合并成几个离散的大区间,结果为这些区间大小之和。这种方法的时间复杂度是O(n
阅读全文
摘要:"题目链接" 所有元素初始值为0才能这么做: ①l r全加1 a[l]++; a[r+1] ; 求一遍前缀和为元素本身。 求两遍前缀和为元素前缀和。 include include include include include include include include include inc
阅读全文
摘要:给你一个n个初始元素都为1的序列和m个询问q。 询问格式为:l r x(x为2or3) 最后求1~n所有数的GCD GCD:把每个数分别分解质因数,再把各数中的全部 公有质因数 提取出来连乘,所得的积就是这几个数的最大公约数。 include include include include incl
阅读全文
摘要:【前后缀枚举】
阅读全文
摘要:B. The Festive Evening time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard output It's the end of July –
阅读全文
摘要:C. Little Girl and Maximum Sum time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard output The little gi
阅读全文
摘要:【题意】:给你n个可重叠区间和一个参考值k,然后进行q次询问,每次询问也是一个区间,问你该区间中有多少个整数在n个区间中出现次数 =k include include include include include include include include include include in
阅读全文
摘要:差分有:一维差分、多维差分、树上差分 差分标记一般求离线区间问题!(修改完后不再修改,然后修改结束后查询) 对于带有“将一段区间内的每个数全部加上某个值”这种操作的题目,通常考虑差分原数列以简化情况,将对一段区间的操作转化为对某两个特定数的操作。 我们可以用树状数组来维护一个差分序列。差分序列的本质
阅读全文
摘要:题目背景 此题约为NOIP提高组Day2T1难度。 题目描述 在n\ n的格子上有m个地毯。 给出这些地毯的信息,问每个点被多少个地毯覆盖。 输入输出格式 输入格式: 第一行,两个正整数n、m。意义如题所述。 接下来m行,每行两个坐标(x1,y1)和(x2,y2),代表一块地毯,左上角是(x1,y1
阅读全文
摘要:N个气球排成一排,从左到右依次编号为1,2,3....N.每次给定2个整数a b(a using namespace std; define ll long long const int maxn = 2e5 + 10; int n; int a,b; int x[maxn],p[maxn]; in
阅读全文
摘要:这里的关键就是区间加的时候是整个区间 同时 加某个数,所以这个 区间内的公差 还是不变的
阅读全文
摘要:You are given an array d1,d2,…,dn consisting of n integer numbers. Your task is to split this array into three parts (some of which may be empty) in s
阅读全文
摘要:``` The heat during the last few days has been really intense. Scientists from all over the Berland study how the temperatures and weather change, and
阅读全文
摘要:【链接】: "CF" 【分析】: 设上车前人数 x ,中途最大人数为 x+max ,最小人数为 x+min (max≥0,min≤0) 可得不等式组 x+max≤w, x+min≥0 整数解个数 为 max(0,w max+min+1) 求出 max,min 即可,有求和~记得long long 【
阅读全文
摘要:【链接】: " CF978C " 【分析】:在前缀和数组种二分找到 =询问数的位置,根据位置就好操作了 【代码】: include using namespace std; const int INF = 0x3f3f3f3f; define ll long long define ms(a,b)
阅读全文
摘要:什么是前缀和、前缀积? 前缀和、前缀积也称前缀和数组,前缀积数组。 给一数组A, 前缀和:新建一数组B,数组中每一项B[i]保存A中[0…i]的和; 后缀和:新建一数组B,数组中每一项B[i]保存A中[i…n-1]的和; 前缀积:新建一数组B,数组中每一项B[i]保存A中[0…i]的积; 后缀积:新
阅读全文
摘要:I - Gcd HYSBZ - 2818 给定整数N,求1<=x,y<=N且Gcd(x,y)为素数的数对(x,y)有多少对. Input 一个整数N Output 如题 Sample Input4 I - Gcd HYSBZ - 2818 给定整数N,求1<=x,y<=N且Gcd(x,y)为素数的数
阅读全文
摘要:题目描述 区间质数个数 输入输出格式 输入格式: 一行两个整数 询问次数n,范围m 接下来n行,每行两个整数 l,r 表示区间 输出格式: 对于每次询问输出个数 t,如l或r∉[1,m]输出 Crossing the line 输入输出样例 输入样例#1: 复制 2 5 1 3 2 6 输出样例#1
阅读全文
摘要:D - 2017-like Number Time limit : 2sec / Memory limit : 256MB Score : 400 points Problem Statement We say that a odd number N is similar to 2017 when
阅读全文
摘要:今天做牛客网西南民大的题遇到了二维前缀和的题目,是个比较经典出过很多次的题目了, 看来光掌握一维前缀和还是远远不够的,二维前缀和也必须很熟练。 前缀和 前缀和可以理解为数学上的数列的前n项和(对于一个一维数组的前缀和)。 我们定义一个数组a的前缀和数组sum[i]=a[1]+a[2]+...+a[i
阅读全文