bzoj4397[Usaco2015 dec]Breed Counting 题意: 给定一个长度为N的序列,每个位置上的数只可能是1,2,3中的一种.有Q次询问,每次给定两个数a,b,请分别输出区间[a,b]里数字1,2,3的个数.n≤100000,q≤100000. 题解: 裸前缀和. 代码: #include <cstdio> #include <cstring> #include <algorithm> #define inc(i,j,k) for(int i=j…
4397: [Usaco2015 dec]Breed Counting Time Limit: 10 Sec  Memory Limit: 128 MB Description Farmer John's N cows, conveniently numbered 1…N, are all standing in a row (they seem to do so often that it now takes very little prompting from Farmer John to…
HDU 5862 Counting Intersections(离散化+树状数组) 题目链接http://acm.split.hdu.edu.cn/showproblem.php?pid=5862 Description Given some segments which are paralleled to the coordinate axis. You need to count the number of their intersection. The input data guarant…
Counting Intersections 题目链接: http://acm.split.hdu.edu.cn/showproblem.php?pid=5862 Description Given some segments which are paralleled to the coordinate axis. You need to count the number of their intersection. The input data guarantee that no two se…
转载请注明出处: http://www.cnblogs.com/fraud/          ——by fraud 2224: Boring Counting Time Limit: 3 Sec  Memory Limit: 128 MB Description In this problem you are given a number sequence P consisting of N integer and Pi is the ith element in the sequence.…
题目链接: http://acm.split.hdu.edu.cn/showproblem.php?pid=5862 Counting Intersections Time Limit: 12000/6000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) 问题描述 Given some segments which are paralleled to the coordinate axis. You need to coun…
4105.   Lines Counting Time Limit: 2.0 Seconds   Memory Limit: 150000K Total Runs: 152   Accepted Runs: 47 On the number axis, there are N lines. The two endpoints L and R of each line are integer. Give you M queries, each query contains two interval…
BZOJ-2743 LUOGU:https://www.luogu.org/problemnew/show/P4113 题意: 给一个n长度的序列,m次询问区间,问区间中出现两次及以上的数字的个数.n,m,c为2e6. 思路: 一开始用莫队写,但是tle了,莫队的复杂度是n的1.5次这道题n是2e6,复杂度逼近1e9.所以要用更加巧妙的方法,利用前缀和和树状数组维护即可.这道题不是简单的维护前缀和.因为题意说区间中要满足这个种类的物品大于两个的时候,才能加一.所以这一次离开区间的物品,影响的是最…
题意:有一个序列,一开始所有的元素都是ai,你可以选择两个长度相等的区间,如果某个元素被一个区间覆盖,那么变为bi,如果被两个区间都覆盖,那么变为ci.问所有区间的选择方法中产生的第k小的元素总和. 首先很容易想到的是二分答案,枚举一个区间,然后用线段树或树状数组查询另一个区间使得元素总和小于等于答案的数量. 为了方便计算,我们把b和c数组中的元素都减掉a,即bi=bi-ai,ci=ci-ai,这样只要查询两区间中元素之和小于等于答案的数量就行了,最后再把答案加上a中元素的和. 由于序列是静态的…
题目传送门(内部题37) 输入格式 第一行一个整数$n$,表示区间的长度. 第二行一个长度为$n$的只包含$0,1,2$的字符串,表示给出的序列. 输出格式 一行一个整数,表示革命的区间的数量. 样例 样例输入: 100000111011 样例输出: 数据范围与提示 第$1$个测试点,$n=100$ 第$2,3$个测试点,$n=1,000$ 第$4$个测试点,$n=50,000$ 第$5,6$个测试点,$n={10}^5$ 第$7,8,9,10$个测试点,$n=5\times {10}^6$ 第…