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…
题目链接 816B Karen and Coffee 题目分析 题意:有个人在学泡咖啡,因此看了很多关于泡咖啡温度的书,得到了n种推荐的泡咖啡温度范围[L1,R1] ,此人将有k种做法推荐的温度记为可用温度(个人翻译),然后给出q次询问,问区间[L2,R2]内的温度,有多少个温度是可用温度(每个整数代表一个温度) 思路:一开始用的是线段树写的,不过姿势不对,TLE了,然后改过来后,发现时间比较长,就考虑一下优化的方法. 比线段树某些功能更优的算法:差分思想,在对某一区间每个位置上的数加上一个值x…
题目链接: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…
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…
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…
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/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…
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…
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…
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/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个范围,q个查询问查询区间出现多少点在给出的n个范围中至少占了k次 题解:很显然的一道题目,可能会想到用莫队,或者分块来写,但是这样会超时.这题有个技巧,可以考虑用前缀和来求. 首先在n个范围中给出了l,r,用一个数组a[],a[l]++,a[r+1]--,然后求前缀表示前i个有多少个超过k的.然后就简单了,具体看一下代码. 总而言之想法很重要. #include <iostream>…
题目链接:http://acm.hi-54.com/problem.php?pid=2098 2098 : Drink coffee 时间限制:1 Sec 内存限制:256 MiB 提交:32 答案正确:9 题目描述 为了在上课时保持清醒,凯伦需要一些咖啡.咖啡爱好者凯伦想知道最佳的温度来冲煮完美的咖啡.因此,她花了一些时间阅读几本食谱,其中包括广受好评的“咖啡的艺术”. 她知道有n个食谱,其中第i个食谱建议应当在li和ri度之间冲煮以达到最佳的味道.凯伦认为如果至少k个食谱推荐某个温度,那么那…
Guessing Game 题目连接: http://codeforces.com/gym/100015/attachments Description Jaehyun has two lists of integers, namely a1,...,aN and b1,...,bM.Je!rey wants to know what these numbers are, but Jaehyun won't tell him the numbers directly. So, Je!rey as…
https://codeforces.com/contest/1132/problem/C 枚举 + 差分前缀和 题意 有一段[1,n]的线段,有q个区间,选择其中q-2个区间,使得覆盖线段上的点最多为多少? 题解 一开始用贪心搞,搞到一半发现需要枚举的情况太多 只能用暴力搞,即枚举被去掉的两个区间,那么如何判断去掉哪两个区间比较好? 维护去掉后剩下的点数即答案 代码 #include<bits/stdc++.h> using namespace std; int n,q,i,j,l[5005…
题目传送门 这道题开始看起来会很晕...\(qwq\).首先我们要明确题目中的海拔&&温度.温度是受海拔影响的,每次改变的是海拔,我们求的是温度. 我们开始读入的时候便可以处理出开始\(N\)位置的温度以及各个位置的海拔差.每次读入影响的是一段区间,区间内的相对海拔是不变的因此温度也不会变.只有区间的边界可能受到影响.因此我们只要处理边界就行了:这便是差分的思想. 比如有\([l,r]\)区间需要处理,那么我们把\(l\)位置的原答案减去,把\(l\)位置的海拔改变,并加上新答案.再对\(…
https://codeforces.com/contest/1119/problem/D 题意 有n个数组,每个数组大小为\(10^{18}+1\)且为等差数列,给出n个数组的\(s[i]\),q次询问,每次询问一个区间[l,r],问所有数组的[l,r]区间一共有多少不同的数 题解 结果只与选择的区间长度len有关,还有和两个数组s[i]的差cha有关 若len<=cha,则没有重复,即\(2*len\) 若len>cha,则前面一个数组可以取满len个,后面的数组只能cha个,即\(cha…
On the way home, Karen decided to stop by the supermarket to buy some groceries. She needs to buy a lot of goods, but since she is a student her budget is still quite limited. In fact, she can only spend up to b dollars. The supermarket sells n goods…
Karen and Supermarket 感觉就是很普通的树形dp. dp[ i ][ 0 ][ u ]表示在 i 这棵子树中选择 u 个且 i 不用优惠券的最小花费. dp[ i ][ 1 ][ u ]表示在 i 这棵子树中选择 u 个且 i 用优惠券的最小花费. 注意这个转移总的合起来是O(n ^ 2)的. #include<bits/stdc++.h> #define LL long long #define fi first #define se second #define mk…
You've got an array consisting of n integers: a[1], a[2], ..., a[n]. Moreover, there are m queries, each query can be described by three integers li, ri, ki. Query li, ri, ki means that we should add  to each element a[j], where li ≤ j ≤ ri. Record  …
题目链接  BZOJ4326 这个程序在洛谷上TLE了……惨遭卡常 在NOIP赛场上估计只能拿到95分吧= = 把边权转化成点权 首先求出每一条路径的长度 考虑二分答案,$check(now)$ 对于当前那些长度大于$now$的路径,用差分求出这些路径经过的点的次数 设这些路径条数为l, 长度最大的路径减去$now$的值为$mx$ (点$x1$经过$y1$次,点$x2$经过$y2$次,..., 点$xm$经过$ym$次) 如果我们能找到一条边(一个点),满足$xk = l$ 且 $yk >= m…
Problem Description On the way to school, Karen became fixated on the puzzle game on her phone! The game is played as follows. In each level, you have a grid with n rows and m columns. Each cell originally contains the number 0. One move consists of…
题意 https://vjudge.net/problem/CodeForces-1260D 有m个士兵,t秒,你要带尽可能多的士兵从0去n+1,且他们不能被杀死.路上有一些陷阱,陷阱d[i]会杀死能力比它小的士兵,陷阱位置在l[i],当你走到r[i]时可以拆除它.每次你可以向左或者向右移动.自己不会被陷阱杀死,可以先去把陷阱拆除再回来带兵. 思路 首先,贪心的选最强的一些士兵,即对士兵按能力从大到小排序,然后二分选的士兵数量x,如果花的时间小于等于t,那么就可以满足. 然后,考虑如何check…
题目链接 :http://codeforces.com/contest/816/problem/B 题意 :给出 n 表示区间个数,限定值 k 以及问询次数 q,当一个数被大于或等于 k 个区间重复覆盖时才算有效数,每一次问询都是以区间方式给出,例如(L, R)问你在这个L~R的范围内有多少个数是有效数(即包含这些数的区间个数>=k). 分析 : 这题可以预先统计哪些数被大于或者等于 k 个原始区间重复覆盖,只要提前将这些满足条件的数递增地编上权值构成前缀和序列,然后对于每段问询只要将前缀和序列…
题意:n个塔,第i个塔由$h_i$个cube组成,每次可以切去某高度h以上的最多k个cube,问你最少切多少次,可以让所有塔高度相等 k>=n, n<=2e5 思路:差分统计每个高度i有的方块数nh[i],然后从高到低贪心的切就行了 代码: #include<iostream> #include<cstdio> #include<algorithm> #include<cmath> #include<cstring> #include…
就是每两项相减,肯定能被模数整除. #include <iostream> #include <cstring> #include <cstdio> #include <algorithm> using namespace std; ; int f[Maxn],n,Ans; ) return a; return Gcd(b,a%b);} inline ?x:-x;} int main() { while (true) { n=; scanf("%d…