[CF 295A]Grag and Array[差分数列]】的更多相关文章

题意: 有数列a[ ]; 操作op[ ] = { l, r, d }; 询问q[ ] = { x, y }; 操作表示对a的[ l, r ] 区间上每个数增加d; 询问表示执行[ x, y ]之间的op. 打印最终数列. 思路: 用两次差分数列, 先处理出对于每个op调用了几次, 再对数列执行操作. #include <cstdio> #include <cstring> #include <algorithm> using namespace std; const i…
#include <iostream> #include <stdio.h> #include <string.h> #include <algorithm> #define lson rt<<1,L,mid #define rson rt<<1|1,mid+1,R /* 题意:给出原始序列a[1],a[2],...a[n] 给出m个操作方式 l r d,把a[l],...a[r]都加上d 然后给出k个操作 x y 执行第x到第y个操…
题意: 给出n项的数列A[ ], q个询问, 询问 [ l, r ] 之间项的和. 求A的全排列中该和的最大值. 思路: 记录所有询问, 利用差分数列qd[ ], 标记第 i 项被询问的次数( 每次区间增1 ). 最后对qd, A 进行升序排序, 对应项相乘, 求和. 理由是: 越大的数被询问覆盖的次数越多那么总和就越大. 差分数列简单易用. #include <cstdio> #include <cstring> #include <algorithm> using…
Codeforces Round #262 (Div. 2) C C - Present C. Present time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Little beaver is a beginner programmer, so informatics is his favorite subject. Soon…
2014多校9 1011 http://acm.hdu.edu.cn/showproblem.php?pid=4970 Killing Monsters Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 331    Accepted Submission(s): 198 Problem Description Kingdom Rush…
转载请注明出处: http://www.cnblogs.com/fraud/          ——by fraud Always an integer Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Combinatorics is a branch of mathematics chiefly concerned with counting discrete objects. For instanc…
传送门 A. Greg and Array time limit per test 1.5 seconds memory limit per test 256 megabytes input standard input output standard output Greg has an array a = a1, a2, ..., an and m operations. Each operation looks as: li, ri, di, (1 ≤ li ≤ ri ≤ n). To a…
You are given an array of integers. Vasya can permute (change order) its integers. He wants to do it so that as many as possible integers will become on a place where a smaller integer used to stand. Help Vasya find the maximal number of such integer…
题意: 给出一个形如(P)/D的多项式,其中P是n的整系数多项式,D为整数. 问是否对于所有的正整数n,该多项式的值都是整数. 分析: 可以用数学归纳法证明,若P(n)是k次多项式,则P(n+1) - P(n)为k-1次多项式. P是n的一次多项式时,P是一个等差数列,只要验证P(1)和P(2)是D的倍数即可. P是n的二次多项式时,只要验证第一项为D的倍数,且相邻两项的差值也是D的倍数即可.相邻两项的差值为一次多项式,所以要验证两项,加上前面验证的第一项,所以共验证P(1).P(2)和P(3)…
题目链接:http://codeforces.com/problemset/problem/295/A 我的做法,两次线段树 #include <cstdio> #include <cstring> const int N = 100005; long long sumv[N * 3]; long long add[N * 3]; long long a[N]; struct opera { int l, r; long long d; } op[N]; void pushdown…