To stay woke and attentive during classes, Karen needs some coffee! Karen, a coffee aficionado, wants to know the optimal temperature for brewing the perfect cup of coffee. Indeed, she has spent some time reading several recipe books, including the u…
LINK 题意:给出n个[l,r],q个询问a,b,问被包含于[a,b]且这样的区间数大于k个的方案数有多少 思路:预处理所有的区间,对于一个区间我们标记其(左边界)++,(右边界+1)--这样就能通过前缀和维护小于某边界的区间个数了 这题也可以用线段树解,但显然不太合算 /** @Date : 2017-07-01 10:02:30 * @FileName: 816B 前缀和 线段树 二分.cpp * @Platform: Windows * @Author : Lweleth (SoungE…
题目链接 816B Karen and Coffee 题目分析 题意:有个人在学泡咖啡,因此看了很多关于泡咖啡温度的书,得到了n种推荐的泡咖啡温度范围[L1,R1] ,此人将有k种做法推荐的温度记为可用温度(个人翻译),然后给出q次询问,问区间[L2,R2]内的温度,有多少个温度是可用温度(每个整数代表一个温度) 思路:一开始用的是线段树写的,不过姿势不对,TLE了,然后改过来后,发现时间比较长,就考虑一下优化的方法. 比线段树某些功能更优的算法:差分思想,在对某一区间每个位置上的数加上一个值x…
CodeForces 816B Karen and Coffee(前缀和,大量查询) Description Karen, a coffee aficionado, wants to know the optimal temperature for brewing the perfect cup of coffee. Indeed, she has spent some time reading several recipe books, including the universally ac…
题目链接:http://codeforces.com/contest/816/problem/B 题目意思:给出 n 个recipes,第 i 个(1<= i <=n)recipes 表明 coffee 调制的推荐温度范围是 [li, ri] 之间.现在有 q 个问题,每个问题需要回答 coffee 在范围 [a, b] 之间,共有多少个数满足至少有 k 个推荐. 题目解析:这题主要是考我们对于大范围(最大200000),如何处理数据.方法是很容易想到的,但要考虑优化,即离线处理.20w *…
To stay woke and attentive during classes, Karen needs some coffee! Karen, a coffee aficionado, wants to know the optimal temperature for brewing the perfect cup of coffee. Indeed, she has spent some time reading several recipe books, including the u…
Description To stay woke and attentive(专注的) during classes, Karen needs some coffee! Karen, a coffee aficionado, wants to know the optimal temperature for brewing the perfect cup of coffee. Indeed, she has spent some time reading several recipe books…
http://codeforces.com/contest/816/problem/B To stay woke and attentive during classes, Karen needs some coffee! Karen, a coffee aficionado, wants to know the optimal temperature for brewing the perfect cup of coffee. Indeed, she has spent some time r…
To stay woke and attentive during classes, Karen needs some coffee! Karen, a coffee aficionado, wants to know the optimal temperature for brewing the perfect cup of coffee. Indeed, she has spent some time reading several recipe books, including the u…
B. Karen and Coffee time limit per test 2.5 seconds memory limit per test 512 megabytes input standard input output standard output To stay woke and attentive during classes, Karen needs some coffee! Karen, a coffee aficionado, wants to know the opti…
To stay woke and attentive during classes, Karen needs some coffee! Karen, a coffee aficionado, wants to know the optimal temperature for brewing the perfect cup of coffee. Indeed, she has spent some time reading several recipe books, including the u…
B. Karen and Coffee time limit per test 2.5 seconds memory limit per test 512 megabytes input standard input output standard output To stay woke and attentive during classes, Karen needs some coffee! Karen, a coffee aficionado, wants to know the opti…
To stay woke and attentive during classes, Karen needs some coffee! Karen, a coffee aficionado, wants to know the optimal temperature for brewing the perfect cup of coffee. Indeed, she has spent some time reading several recipe books, including the u…
题目链接:http://codeforces.com/problemset/problem/479/E 题意: 有一栋n层的房子. 还有一个无聊的人在玩电梯,每次玩电梯都会从某一层坐到另外一层. 他初始在a层,然后要玩k次电梯. 这栋楼里还有一个神秘实验室,在b层. 这让他每次坐电梯受到了限制: 当前在x层,然后要坐到y层,则必须满足|x-y|<|x-b| 问你共有多少种坐电梯的方案. 题解: 表示状态: dp[i][j] = numbers 表示当前在第i层,已经坐了j次电梯,此时的方案数.…
转载自https://blog.csdn.net/weixin_37517391/article/details/83821752 题解 其实这题不难,只要想到了前缀和差分就基本OK了. 我们要求的是第$i$项的式子: $F(i)=(a_1+a_2+...+a_i)^k+(a_2+...+a_i)^k+...+a_i^k$ 记$S_i = a_1 + a_2 +...+a_i,S_0=0$ $F(i) = (S_i-S_0)^k+(S_i-S_1)^k+...+(S_i-S_{i-1})^k$…
题目描述 $Cab$有两行石子,每个石子上有一个字母,为$'C''A''B'$中的一个.一开始,在每行第一个石子上站着一只$lucky$,$Cab$每次可以选择一个字母,使得所站石子上字母为该字母的$lucky$向前走一步,如果此时$lucky$已经到了一行石子的结尾就会掉出去,$Cab$显然不会这么做.一个数对$(x,y)$是$lucky$的,当且仅当在$lucky$不掉出去的前提下,通过一些操作能使第一行的$lucky$处于第$x$个石子的同时第二只$lucky$处于第$y$个石子.请求出有…
http://acm.hdu.edu.cn/showproblem.php?pid=6514 Problem Description Xiaoteng has a large area of land for growing crops, and the land can be seen as a rectangle of n×m. But recently Xiaoteng found that his crops were often stolen by a group of people,…
[题目链接]:http://codeforces.com/contest/816/problem/B [题意] 给你很多个区间[l,r]; 1<=l<=r<=2e5 一个数字如果被k个以上的区间覆盖到; 则称之为特殊数字; 给你q个询问区间; 问你这q个区间里面 每个区间里面有多少个特殊数字; [题解] 对于覆盖的区间l,r add[l]++,sub[r+1]++, 然后顺序枚举 now+=add[i]; now-=sub[i]; 如果now>=k则i是一个特殊数字; 写个前缀和O…
题目链接 :http://codeforces.com/contest/816/problem/B 题意 :给出 n 表示区间个数,限定值 k 以及问询次数 q,当一个数被大于或等于 k 个区间重复覆盖时才算有效数,每一次问询都是以区间方式给出,例如(L, R)问你在这个L~R的范围内有多少个数是有效数(即包含这些数的区间个数>=k). 分析 : 这题可以预先统计哪些数被大于或者等于 k 个原始区间重复覆盖,只要提前将这些满足条件的数递增地编上权值构成前缀和序列,然后对于每段问询只要将前缀和序列…
给定一个n×n的WB矩阵,给定一个k∗k的能把B变成W的橡皮擦,求橡皮擦作用一次后,全为W的行.列总数最大值 连接:http://codeforces.com/contest/1200/problem/D #include<bits/stdc++.h> using namespace std; int A[2004][2004]; char C[2004][2004]; int B[2004][2004]; int E[2004][2004]; int F[2004][2004]; int n…
要求一段最大的区间里每个能力的增长值是一样的. 我们首先求一遍前缀和,发现,如果区间内[l,r]每个能力的增长值是一样的话,那么前缀和[r]和[l-1]的差分也应该是一样的. 那么我们把前缀和的差分hash一下,排个序,求出hash值相同的且跨越最远的两个端点,就是答案了. # include <cstdio> # include <cstring> # include <cstdlib> # include <iostream> # include <…
一:差分数组概念  一.差分数组的定义及用途 1.定义:对于已知有n个元素的数列d,建立记录它每项与前一项差值的差分数组f:显然,f[1]=d[1]-0=d[1];对于整数i∈[2,n],我们让f[i]=d[i]-d[i-1].//f[i]数组为差分数组,d[i]数组为原数组 2.简单性质:(1)计算数列各项的值:观察d[2]=f[1]+f[2]=d[1]+d[2]-d[1]=d[2]可知,d[i]=f[i]的前缀和.(2)计算数列每一项的前缀和:第i项的前缀和即为数列前i项的和,那么推导可知…
题意:RT,给你四个数\(a,b,c,d\),求\(x+y+z=k\)的方案数. 题解:我们可以先枚举\(x\)的值,然后\(x+y\)能取到的范围一定是\([x,x+b]\),也就是说这个区间内每个数都有一个贡献,所以我们可以通过枚举\(a\)并且利用差分来求出\(x+y\)的贡献,然后再复原前缀和,同理再枚举\(x+y\),即枚举\(a+b\)并加上\(c\),来求出\(x+y+z\)的贡献,再复原前缀和,最后枚举\(d\)将每个点的方案数加给答案即可. 代码: ll a,b,c,d; ll…
F. Shovels Shop time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output There are nn shovels in the nearby shop. The ii -th shovel costs aiai bourles. Misha has to buy exactly kk shovels. Each sho…
http://www.lydsy.com/JudgeOnline/problem.php?id=1637 很神思想.. 前缀和应用到了极点... 我们可以发现当数量一定时,这个区间最前边的牛的前边一个牛的前缀和等于这个区间最后边的牛的前缀和..(将0的牛变成-1,然后维护前缀和) 然后扫过去就行了... orz #include <cstdio> #include <cstring> #include <cmath> #include <string> #i…
http://www.lydsy.com/JudgeOnline/problem.php?id=1651 很奇妙.. 我们发现,每一时刻的重叠数选最大的就是答案.... orz 那么我们可以线段树维护每个点的次数... 然后就ok了.. 第二种做法:用前缀和来维护即可... 线段树: #include <cstdio> #include <cstring> #include <cmath> #include <string> #include <ios…
题意: 给出n项的数列A[ ], q个询问, 询问 [ l, r ] 之间项的和. 求A的全排列中该和的最大值. 思路: 记录所有询问, 利用差分数列qd[ ], 标记第 i 项被询问的次数( 每次区间增1 ). 最后对qd, A 进行升序排序, 对应项相乘, 求和. 理由是: 越大的数被询问覆盖的次数越多那么总和就越大. 差分数列简单易用. #include <cstdio> #include <cstring> #include <algorithm> using…
题面: 传送门 思路: 看完题目以后,首先有一个结论:每个人都是先去到首都,等待开会,开会结束以后再一个个走掉 而且这道题只有去首都和离开首都的机场 因此考虑计算去首都的飞机的前缀最小花费,以及离开首都的飞机的最小后缀花费 都计算出来以后,对于每一个开始开会的时间t,用pre[t-1]+suf[t+k]来更新答案即可 Code: 到处都要用long long...... 最后我只好ctrl+R,替换int为longlong了...... #include<iostream> #include&…
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1637 题意: Farmer John 决定给他的奶牛们照一张合影,他让 N (1 ≤ N ≤ 50,000) 头奶牛站成一条直线,每头牛都有它的坐标x(0 <= x <= 10^9)和种族(0或1). 他只给一部分牛照相,并且这一组牛的阵容必须是“平衡的”. 平衡的阵容,指的是在一组牛中,种族0和种族1的牛的数量相等. 区间的大小为区间内最右边的牛的坐标减去最做边的牛的坐标. 请算出最…
题目链接:http://codeforces.com/contest/816/problem/B 题意:给出n个范围,q个查询问查询区间出现多少点在给出的n个范围中至少占了k次 题解:很显然的一道题目,可能会想到用莫队,或者分块来写,但是这样会超时.这题有个技巧,可以考虑用前缀和来求. 首先在n个范围中给出了l,r,用一个数组a[],a[l]++,a[r+1]--,然后求前缀表示前i个有多少个超过k的.然后就简单了,具体看一下代码. 总而言之想法很重要. #include <iostream>…