Codeforces 220B】的更多相关文章

http://codeforces.com/contest/220/problem/B 题意:给出一个数组,给出m组询问,问区间中出现a[i] 次的有多少个. sl: 很显然的离线问题了. 大视野菜花的加强版. 可以这么搞,假设当前走到了a 看看之前是不是有a个a有的话就在a-k处 减1 同时补上上次的操作就行.具体键代码. http://codeforces.com/contest/220/submission/6948720…
传送门:https://codeforces.com/problemset/problem/220/B 题意: 给你n个数,m次询问,每次询问问你在区间l,r内有多少个数满足其值为其出现的次数 题解: 莫队算法 思路:每次区间向外扩的更新的过程中,检查该位置的数ai的出现次数是否已经达到ai或ai+1,以判断是否要更新结果.同理,区间收缩的时候判断ai出现次数是否达到ai或ai-1. 因为数据范围为1e9,所以需要离散化,方便记录每种数出现的次数 代码: /** * ┏┓ ┏┓ * ┏┛┗━━━…
This problem can be solve in simpler O(NsqrtN) solution, but I will describe O(NlogN) one. We will solve this problem in offline. For each x (0 ≤ x < n) we should keep all the queries that end in x. Iterate that x from 0 to n - 1. Also we need to kee…
给一段长为n的序列和m个关于区间的询问,求出每个询问的区间中有多少种数字是 该种数字出现的次数等于该数字 的. #include <iostream> #include <cstdio> #include <sstream> #include <cstring> #include <map> #include <set> #include <vector> #include <stack> #include &…
题意:N个数,M个查询,求[Li,Ri]区间内出现次数等于其数值大小的数的个数. 分析:用莫队处理离线问题是一种解决方案.但ai的范围可达到1e9,所以需要离散化预处理.每次区间向外扩的更新的过程中,检查该位置的数ai的出现次数是否已经达到ai或ai+1,以判断是否要更新结果.同理,区间收缩的时候判断ai出现次数是否达到ai或ai-1. 另一种更高效的方法是使用树状数组离线处理查询.用一个vector数组维护每个ai以此出现的位置.显然ai>N的数不会对结果做出贡献,所以数组开1e5就足够了.树…
题意: m次查询.每次查询范围[L,R]中出现次数等于该数字的数字个数. 题解: 由于分块,在每次询问中,同一块时l至多移动根号n,从一块到另一块也是最多2倍根号n.对于r,每个块中因为同一块是按y排序,所以最多移动根号n:一共根号n个块.注意l和r要分开考虑. 要注意的是这道题需要离散一下数据. #include <iostream> #include <cstdio> #include <cmath> #include <algorithm> #incl…
B. Little Elephant and Array time limit per test 4 seconds memory limit per test 256 megabytes input standard input output standard output The Little Elephant loves playing with arrays. He has array a, consisting of n positive integers, indexed from…
The Little Elephant loves playing with arrays. He has array a, consisting of npositive integers, indexed from 1 to n. Let's denote the number with index i as ai. Additionally the Little Elephant has m queries to the array, each query is characterised…
莫队算法链接:传送门 题意: 有n个数,m个区间.问区间内有多少个x,x满足x的个数等于x的值的个数(如果x是3,区间内要存在3个3). 题解: 因为a[i]太大,所以要离散化一下,但是不能用map容器,因为map容器多一个log 莫队就是离线问题+区间的移动.复杂度是O((N+M)*√N) 莫队代码还要分块要不然还会TLE,分块大小为sqrt(n) 未分块-TLE代码: 1 #include <cstdio> 2 #include <iostream> 3 #include &l…
上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题.. 今天,我们来扒一下cf的题面! PS:本代码不是我原创 1. 必要的分析 1.1 页面的获取 一般情况CF的每一个 contest 是这样的: 对应的URL是:http://codeforces.com/contest/xxx 还有一个Complete problemset页面,它是这样的:…