CodeForces 221D Little Elephant and Array】的更多相关文章

Little Elephant and Array Time Limit: 4000ms Memory Limit: 262144KB This problem will be judged on CodeForces. Original ID: 221D64-bit integer IO format: %I64d      Java class name: (Any) The Little Elephant loves playing with arrays. He has array a,…
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…
传送门:https://codeforces.com/problemset/problem/220/B 题意: 给你n个数,m次询问,每次询问问你在区间l,r内有多少个数满足其值为其出现的次数 题解: 莫队算法 思路:每次区间向外扩的更新的过程中,检查该位置的数ai的出现次数是否已经达到ai或ai+1,以判断是否要更新结果.同理,区间收缩的时候判断ai出现次数是否达到ai或ai-1. 因为数据范围为1e9,所以需要离散化,方便记录每种数出现的次数 代码: /** * ┏┓ ┏┓ * ┏┛┗━━━…
题意: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…
221D - Little Elephant and Array 思路: 莫队: 代码: #include <cmath> #include <cstdio> #include <cstring> #include <iostream> #include <algorithm> using namespace std; #define maxn 100005 struct QueryType { int l,r,id; }; struct Que…
vjudge上莫队专题 真的是要吐槽自己(自己的莫队手残写了2个bug) s=sqrt(n) 是元素的个数而不是询问的个数(之所以是sqrt(n)使得左端点每个块左端点的范围嘴都是sqrt(n)) 在重载<是将q[i].l/s<q2[i].l/s 写成q1[i].l<s<q2[i].l<s 导致一下午都在调bug疯了 Sona 比小Z的袜子简单,直接维护区间频度的^3 需要离散化(离散化化的标号应提前准备好,如果用时在二分查找会增加复杂度) 还有比较坑的一点是多case,但样…
二次联通门 : Codeforces 221d D. Little Elephant and Array /* Codeforces 221d D. Little Elephant and Array 题意 : 询问一段区间中出现次数等于自身的数的个数 正解是dp 莫队水过, 作为我莫队的入门题 myj的思路 66 把所有需查询的区间排序 当前查询区间的答案为上一个区间的答案通过多次的区间移动得出 */ #include <algorithm> #include <cstdio>…
D. 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…
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…
[codeforces 360]A. Levko and Array Recovery 试题描述 Levko loves array a1, a2, ... , an, consisting of integers, very much. That is why Levko is playing with array a, performing all sorts of operations with it. Each operation Levko performs is of one of…
CodeForces - 204C Little Elephant and Furik and Rubik 个人感觉是很好的一道题 这道题乍一看我们无从下手,那我们就先想想怎么打暴力 暴力还不简单?枚举所有字串,再枚举所有位置,算出所有答案不就行了 我们自然不能无脑暴力,但是暴力可以给我们启发 我们知道所有对答案做出贡献的字符一定是相同的(废话) 所以我们可以O(n^2)首先枚举两个字符串中相同的字符然后再考虑如何贡献 然后计算出所有的方案下的值,再除以n*(n+1)*(2*n+1)/6 [不知…
题目描述: Little Elephant and Interval time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output The Little Elephant very much loves sums on intervals. This time he has a pair of integers l and r (l ≤ r…
[Codeforces 266E]More Queries to Array...(线段树+二项式定理) 题面 维护一个长度为\(n\)的序列\(a\),\(m\)个操作 区间赋值为\(x\) 查询\(\sum_{i=l}^r a_i(i-l+1)^k \mod 10^9+7\) \(n,m \leq 10^5,k \leq 5\) 分析 根据二项式定理 \[(i-l+1)^k=\sum_{j=0}^k (-1)^{k-j} C_{k}^j i^j(l-1)^{k-j}\] 那么 \(\begi…
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…
http://codeforces.com/contest/220/problem/B 题意:给出一个数组,给出m组询问,问区间中出现a[i] 次的有多少个. sl: 很显然的离线问题了. 大视野菜花的加强版. 可以这么搞,假设当前走到了a 看看之前是不是有a个a有的话就在a-k处 减1 同时补上上次的操作就行.具体键代码. http://codeforces.com/contest/220/submission/6948720…
给一段长为n的序列和m个关于区间的询问,求出每个询问的区间中有多少种数字是 该种数字出现的次数等于该数字 的. #include <iostream> #include <cstdio> #include <sstream> #include <cstring> #include <map> #include <set> #include <vector> #include <stack> #include &…
更好的阅读体验 Portal Portal1: Codeforces Portal2: Luogu Description The Little Elephant loves playing with arrays. He has array \(a\), consisting of \(n\) positive integers, indexed from \(1\) to \(n\). Let's denote the number with index \(i\) as \(a_i\).…
 Little Elephant and Chess Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Submit Status Practice CodeForces 259A Description The Little Elephant loves chess very much. One day the Little Elephant and his friend decided…
A. Co-prime Array 题目连接: http://www.codeforces.com/contest/660/problem/A Description You are given an array of n elements, you must make it a co-prime array in as few moves as possible. In each move you can insert any positive integral number you want…
D. Array Restoration 题目链接:https://codeforces.com/contest/1023/problem/D 题意: 给出一个序列,现在要求对一个全为0的序列执行q次操作,每次操作都要选定一段区间然后将区间上面的值变为i(i为操作的次数).最终使得0序列变为之前给出的序列. 原序列中如果存在0,那么说明这个值是任意的. 最后要求输出经过q次操作之后的序列. 题解: 我们首先可以想到不可行的情况:在原序列中若存在一个数a,假设其出现次数大于1,那么两端为a的中间区…
先上题目: Little Elephant and Sorting time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output The Little Elephant loves sortings. He has an array a consisting of n integers. Let's number the array elem…
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard output Recently Maxim has found an array of n integers, needed by no one. He immediately come up with idea of changing it: he invented positive integer…
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard output One spring day on his way to university Lesha found an array A. Lesha likes to split arrays into several parts. This time Lesha decided to split…
Educational Codeforces Round 63 (Rated for Div. 2) D. Beautiful Array time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output You are given an array aa consisting of nn integers. Beauty of array i…
ACM思维题训练集合 The Little Elephant has got a problem - somebody has been touching his sorted by non-decreasing array a of length n and possibly swapped some elements of the array. The Little Elephant doesn't want to call the police until he understands i…
题目链接: C. Artem and Array time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Artem has an array of n positive integers. Artem decided to play with it. The game consists of n moves. Each move g…
题目链接: E. Sasha and Array time limit per test 5 seconds memory limit per test 256 megabytes input standard input output standard output Sasha has an array of integers a1, a2, ..., an. You have to perform m queries. There might be queries of two types:…
题目链接:http://codeforces.com/contest/451/problem/B 解题报告:给出一个序列,要你判断这个序列能不能通过将其中某个子序列翻转使其成为升序的序列. 我的做法有点不一样,我是将原来的序列先按照升序排好序,然后分别从头和尾开始扫,找到跟原来的数组不一样的子序列的区间,然后判断这个区间是不是原来的区间翻转而来. #include<cstdio> #include<cstring> #include<iostream> #include…
题目链接:http://codeforces.com/contest/719/problem/E 题意:操作1将[l, r] + x; 操作2求f[l] + ... + f[r]; 题解:注意矩阵可以是a*(b + c) = a*b + a*c ,还有update的时候传入矩阵 //#pragma comment(linker, "/STACK:102400000, 102400000") #include <algorithm> #include <iostream…