[CodeForces-259C] Little Elephant and Bits】的更多相关文章

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…
C. Little Elephant and Bits time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output The Little Elephant has an integer a, written in the binary notation. He wants to write this number on a piece o…
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,…
 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…
Little Elephant and Broken Sorting 怎么感觉这个状态好难想到啊.. dp[ i ][ j ]表示第 i 个数字比第 j 个数字大的概率.转移好像比较显然. #include<bits/stdc++.h> #define LL long long #define LD long double #define ull unsigned long long #define fi first #define se second #define mk make_pair…
Little Elephant and LCM #include<bits/stdc++.h> #define LL long long #define fi first #define se second #define mk make_pair #define PLL pair<LL, LL> #define PLI pair<LL, int> #define PII pair<int, int> #define SZ(x) ((int)x.size()…
[题目链接] https://codeforces.com/contest/204/problem/E [算法] 首先构建广义后缀自动机 对于自动机上的每个节点 , 维护一棵平衡树存储所有它所匹配的字符串编号 可以通过启发式合并得到 计算答案时 , 我们枚举每个右端点 , 当当前集合大小 < K时 , 不断走向link节点 时间复杂度 : O(NlogN) [代码] #include<bits/stdc++.h> using namespace std; typedef long lon…
Discription The Little Elephant loves permutations of integers from 1 to n very much. But most of all he loves sorting them. To sort a permutation, the Little Elephant repeatedly swaps some elements. As a result, he must receive a permutation 1, 2, 3…
CF258D Little Elephant and Broken Sorting 题意 题意翻译 有一个\(1\sim n\)的排列,会进行\(m\)次操作,操作为交换\(a,b\).每次操作都有\(50\%\)的概率进行. 求进行\(m\)次操作以后的期望逆序对个数. \(n,m\le 1000\) 输入输出格式 输入格式: The first line contains two integers \(n\) and \(m\) \((1\leq n,m\leq 1000,n>1)\) -…
ACM思维题训练集合 The Little Elephant has two permutations a and b of length n, consisting of numbers from 1 to n, inclusive. Let's denote the i-th (1 ≤ i ≤ n) element of the permutation a as ai, the j-th (1 ≤ j ≤ n) element of the permutation b - as bj. Th…
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…
Codeforces 题目传送门 & 洛谷题目传送门 yyq:"hot tea 不常有,做过了就不能再错过了" 似乎这是半年前某场 hb 模拟赛的 T2?当时 ycx.ymx.yxh 都去打了,可我似乎那时候还在旅游? 不难发现,对于操作 \(i\) 实际上是将 \(a_i\) 与 \(b_i\) 子树的并集内的点的答案集合并上 \(a_i\) 与 \(b_i\) 子树的并集.于是我们考虑将询问离线下来并在树上进行一遍 DFS,动态地维护一个可重集 \(S\).当我们第一次访问…
http://codeforces.com/problemset/problem/204/A 题意:给定一个[L,R]区间,求这个区间里面首位和末尾相同的数字有多少个 思路:考虑这个问题满足区间加减,我们只考虑[1,n],考虑位数小于n的位数的时候,我们枚举头尾的数是多少,然后乘上10的某幂次,再考虑位数相等时,从高位往低位走,先考虑头尾数字小于最高位的情况,也像刚才那个随便取,当头尾数字等于最高位时,从高往低走,先算不与这位相等的,走下一步就代表与这位相等.最后要记得判断一下如果原数字头等于尾…
先上题目: 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…
传送门:https://codeforces.com/problemset/problem/220/B 题意: 给你n个数,m次询问,每次询问问你在区间l,r内有多少个数满足其值为其出现的次数 题解: 莫队算法 思路:每次区间向外扩的更新的过程中,检查该位置的数ai的出现次数是否已经达到ai或ai+1,以判断是否要更新结果.同理,区间收缩的时候判断ai出现次数是否达到ai或ai-1. 因为数据范围为1e9,所以需要离散化,方便记录每种数出现的次数 代码: /** * ┏┓ ┏┓ * ┏┛┗━━━…
题意: input : n a1,a2,...,an 1 <= n <= 10^5 1 <= ai <= 10^5 求b数组的方案数,b数组满足: 1. 1 <= bi <= ai 2. lcm(bi) = max(bi) solution: 2说明了b数组的每一个元素都是max(bi)的约数 则: 1.sort a数组,ma  = a[n] 2.预处理2个数组,vector<int> dive[MAXN],int pos[MAXN] dive[i]保存i的…
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个查询,求[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…
传送门在这里. 大意: 给一堆字符串,询问每个字符串有多少子串在所有字符串中出现K次以上. 解题思路: 这种子串问题一定要见后缀自动机Parent树Dfs序统计出现次数都是套路了吧. 这道题统计子串个数,那么可以发现,若一个节点所对应的子串出现了K次,那么其贡献就是len,不需要考虑重复. 因为即使出现重复也是在两个位置. 那么只需统计以每个点结束的子串就好了. 之前的Dfs序就很套路了. 只需再跑一遍字符串,更新答案就好了. 代码: #include<cstdio> #include<…
A. Little Elephant and Chess 模拟. B. Little Elephant and Magic Square 枚举左上角,计算其余两个位置的值,在\(3\times 3\)判断是否符合题意. C. Little Elephant and Bits 去掉最前面的0,可以使后面的1往前移. D. Little Elephant and Elections 对于选中的数,我们只关心其中的lucky number个数,容易想到用数位dp来求,结果用\(c_i\)表示有\(i\…
codeforces 535A-水题: #include <bits/stdc++.h> using namespace std; typedef long long LL; char s2[15][20]={"eleven","twelve","thirteen","fourteen","fifteen","sixteen","seventeen",&q…
Little Elephant and Magic Square CodeForces - 259B Little Elephant loves magic squares very much. A magic square is a 3 × 3 table, each cell contains some positive integer. At that the sums of integers in all rows, columns and diagonals of the table…
Codeforces 371C : Hamburgers #include<bits/stdc++.h> using namespace std; char B='B',S='S',C='C'; string t; int nb,ns,nc,pb,ps,pc,len; long long r1; map<char,int> m; bool check(long long m1) { ; if(m1*m[B]>nb) need+=(m1*m[B]-nb)*pb; if(m1*m…
2018/5/6 Codeforces Round #478 (Div. 2) C http://codeforces.com/contest/975/problem/C Valhalla Siege 题意:n的士兵,每个士兵有一些生命值,有q次询问,每次询问从前向后造成ki点贯穿伤害(生命值归零的士兵死去,后续士兵承受溢出伤害),问每次询问有几个士兵还活着.当所有士兵死去时,不继续造成溢出伤害并且所有士兵复活. 思路:二分搜索,对士兵生命值求前缀和,每次询问造成的伤害累计,记为s,用upper…
bryce1010模板 http://codeforces.com/gym/101810 #include <bits/stdc++.h> using namespace std; #define ll long long const int MAXN=1010; int a[MAXN<<1]; int main() { int t; cin>>t; int n; while(t--) { cin>>n; for(int i=1;i<=2*n;i++)…
bryce1010模板 http://codeforces.com/gym/101810 #include<bits/stdc++.h> using namespace std; #define ll long long ll a[1000005]; int main() { int t,n,temp; ll ans,maxn,minl,x; scanf("%d",&t); while(t--) { scanf("%I64d",&n);…
bryce1010模板 http://codeforces.com/gym/101810 #include<bits/stdc++.h> using namespace std; #define ll long long const ll maxn = 1e5 + 5; const ll mod = 1e9+7; ll n; ll p[maxn]; ll vis[maxn]; int main() { ll t; scanf("%lld",&t); ll pre;…
bryce1010模板 http://codeforces.com/gym/101810 #include <bits/stdc++.h> using namespace std; #define ll long long int main() { int t; scanf("%d",&t); ll n,m; while(t--) { scanf("%lld%lld",&n,&m); ll cnt=0; if(m>n)swa…