CodeForces 404C Ivan and Powers of Two】的更多相关文章

Ivan and Powers of Two Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Submit Status Practice CodeForces 404C Description Valera had an undirected connected graph without self-loops and multiple edges consisting of n ver…
Ivan and Powers of Two time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Ivan has got an array of n non-negative integers a1, a2, ..., an. Ivan knows that the array is sorted in the non-decre…
CodeForces题面 Time limit 3000 ms Memory limit 262144 kB Source Codeforces Round #532 (Div. 2) Tags data structures divide and conquer greedy math *2600 Editorial Announcement #1 (en) Announcement #2 (ru) Tutorial #1 (en) Tutorial #2 (ru) Tutorial #3 (…
题目传送门 题意: 给出 n 个数,q次区间查询,每次查询,让你选择任意个下标为 [ l , r ] 区间内的任意数,使这些数异或起来最大,输出最大值. 思路:离线加线性基. 线性基学习博客1 线性基学习博客2 对于此题,先把区间按照 r 从小到大排序,然后依次处理这些区间,每次插入线性基时,优先保留下标比较大的线性基.查询时,只异或上下标大于 l 的值. 记住异或的符号的优先级很低,所以  if( res^p[i] > res )这样的代码是会wa死的,要注意(这道题这么写,样例都过不了) #…
题意:让人构造一个图,满足每个结点边的数目不超过 k,然后给出每个结点到某个结点的最短距离. 析:很容易看出来如果可能的话,树是一定满足条件的,只要从头开始构造这棵树就好,中途超了int...找了好久. 代码如下: #pragma comment(linker, "/STACK:1024000000,1024000000") #include <cstdio> #include <string> #include <cstdlib> #include…
[链接] 我是链接,点我呀:) [题意] 每个节点的度数不超过k 让你重构一个图 使得这个图满足 从某个点开始到其他点的最短路满足输入的要求 [题解] 把点按照dep的值分类 显然只能由dep到dep+1连边 设cnt[dep]表示到起点的距离为dep的点的集合 如果cnt[dep].size>cnt[dep+1].size 那么只要把dep层的前cnt[dep+1].size个点和dep+1层的点连就好了 否则 只能让dep层的点每个多连几个dep+1层的点了 [代码] import java…
传送门 注意到连续两个格子如果有相同颜色那么一路过去的都可以确定 比如一开始染了这两个位置: 然后发现后面整片过去都可以确定: 对于横着的情况也是一样,然后就会发现不可能出现横着两个和竖着两个同时都有的情况,因为这样一定会冲突,就一定不合法了 (自己画一下就知道了) 那么现在只要对行列分别计算即可,直接设 $f[i][0/1][0/1]$ 表示前 $i$ 个位置,当前位置为 $0/1$ 上一个位置为 $0/1$ 时的方案数 那么转移十分显然,然后答案就是行任意放的方案 $\sum_{i=0}^{…
题目链接 题意 : 给出坐标轴上的 n 个点的横坐标,要你选出最多的点,使得这些点两两距离是二的幂 ( 特殊情况 : 选出的集合只有一个点也满足条件 ) 分析 : 官方题解已经说的很好了 最关键是是判断选出的集合元素数量肯定不可能大于 3 简单翻译一下题解就是 假设现有答案集合元素数量为 4 ,且令其为 a.b.c.d ( a < b < c < d ) 令 a.b 间距为 dist(a, b) = 2^k 令 b.c 间距为 dist(b, c) = 2^l 则可得出 dist(a,…
题意 一个n*m的网格图,每个格子可以染黑色.白色,问你每个格子最多有一个相邻颜色相同的方案数 n,m<=1e5 思路 我们先处理\(1 \times m\)的情况 设\(f[i][j]\)为前\(i\)个格子,最后一个为\(j\)的方案数 可以得到递推式\(f[i][j]=f[i-1][j\bigoplus 1]+f[i-2][j\bigoplus 1]\) 那么\(1\times m\)的答案为\(f[m][0]+f[m][1]\) 引理 这题中的合法的染色图相邻两行要么完全相同,要么完全相…
A. Strange Addition (目前的做法好像做烦了) 统计数的\(mask\),表示个.十.百位上是否是0,共8种数. 枚举8种数组成的所有情况\(2^8\),记录最大数量. B. Continued Fractions 大数.分数运算. C. Ivan and Powers of Two \(map\)模拟即可. D. Olya and Graph \(i\)和\(i+1\)必然连边. \(i\)要连第二条边的话,只能连向\(i+k+1\),并且对于\(j\ge i+k+1\)不能…
C. Ivan and Powers of Two time limit per test 0.5 seconds memory limit per test 256 megabytes input standard input output standard output Ivan has got an array of n non-negative integers a1, a2, ..., an. Ivan knows that the array is sorted in the non…
ICPC官网题面假的,要下载PDF,点了提交还找不到结果在哪看(我没找到),用VJ交还直接return 0;也能AC 计蒜客题面 这个好 Time limit 3000 ms OS Linux 题目来源 ACM-ICPC 2017 Asia Xi'an VJ爬到的英文题面什么鬼啊,除了标题,哪里有xor字样啊?\((A[i_1], A[i_2], . . . , A[i_t])\)意思是gcd啊?简直了. 计蒜客的题面 2000ms 是不是计蒜客评测姬快一点,时限少了1s 262144K Con…
Codeforces Round #486 (Div. 3) D. Points and Powers of Two 题目连接: http://codeforces.com/group/T0ITBvoeEx/contest/988/problem/D Description There are n distinct points on a coordinate line, the coordinate of i-th point equals to xi. Choose a subset of…
\(>Codeforces \space 622\ F. The\ Sum\ of\ the\ k-th\ Powers<\) 题目大意 : 给出 \(n, k\),求 \(\sum_{i=1}^{n} i^k\) 对 \(10^9 +7\) 取模的值 \(1 \leq n \leq 10^9, 0 \leq k \leq 10^6\) 解题思路 : 考虑 \(k\) 比较大,且模数不太好 \(NTT\),于是考虑插值做法, 学习了一波插值之后,发现就是个板子题 (雾) 拉格朗日插值: 对于…
F. Ivan and Burgers 题目链接:https://codeforces.com/contest/1100/problem/F 题意: 给出n个数,然后有多个询问,每次回答询问所给出的区间的异或和最大值. 题解: 考虑离线做法,先把所有的询问区间按照右端点进行排序,然后从1开始逐个将ai插入,插入线性基的同时记录一下位置,最后扫一下,看看哪些的位置是不小于li的即可加入答案. 这种做法在时间复杂度上面是可行的,但是需要注意的是,如果在i这个位置插入最高位为x的线性基,同时在j这个位…
F. The Sum of the k-th Powers 题目连接: http://www.codeforces.com/contest/622/problem/F Description There are well-known formulas: , , . Also mathematicians found similar formulas for higher degrees. Find the value of the sum modulo 109 + 7 (so you shoul…
题目描述: The Sum of the k-th Powers time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output There are well-known formulas: , , . Also mathematicians found similar formulas for higher degrees. Find th…
Codeforces 955C Sad powers 题意 q组询问,每次询问给定L,R,求[L,R]区间内有多少个数可以写成ap的形式,其中a>0,p>1,1 ≤ L ≤ R ≤ 1e18. 思路 对于p>2的情况,由于随着指数p的增大,小于1e18的p次幂的数量会急剧减小,总数量的级别在1e6多左右,因此可预处理.L,R不超过1e18,可以直接枚举数字1-1e6,将每个数字不超过1e18的且不是平方数的p次幂推入数组中,排序去重.以便回答询问时可二分求数量. 对于p=2的情况,对上界…
Relatively Prime Powers CodeForces - 1036F Consider some positive integer xx. Its prime factorization will be of form x=2k1⋅3k2⋅5k3⋅-x=2k1⋅3k2⋅5k3⋅- Let's call xx elegant if the greatest common divisor of the sequence k1,k2,-k1,k2,- is equal to 11. F…
Powers of Two 题意: 让求ai+aj=2的x次幂的数有几对,且i < j. 题解: 首先要知道,排完序对答案是没有影响的,比如样例7 1一对,和1 7一对是样的,所以就可以排序之后二分找2的x次幂相减的那个数就好了,注意:打表时2的x次幂不能只小于1e9,因为有可能是2个5e8相加,之后就超出了1e9,但是你打表的时候又没有超出1e9的那个2的x次幂,所以答案总是会少几个.所以尽量就开ll 能多打表就多打. 代码: #include <bits/stdc++.h> usin…
The Sum of the k-th Powers There are well-known formulas: , , . Also mathematicians found similar formulas for higher degrees. Find the value of the sum modulo 109 + 7 (so you should find the remainder after dividing the answer by the value 109 + 7).…
B. Powers of Two time limit per test 3 seconds memory limit per test 256 megabytes input standard input output standard output You are given n integers a1, a2, ..., an. Find the number of pairs of indexes i, j (i < j) that ai + aj is a power of 2 (i.…
F - Ivan and Burgers 思路:线性基+贪心,保存线性基中每一位的最后一个 代码: #pragma GCC optimize(2) #pragma GCC optimize(3) #pragma GCC optimize(4) #include<bits/stdc++.h> using namespace std; #define fi first #define se second #define pi acos(-1.0) #define LL long long //#d…
题目链接:Sad powers 题意:给出n个l和r,求出每个给出的[l,r]之间的可以使是另外一个数的k次方的数.(k>=2) 题解:题目给出的数据范围最大是1E18所以如果要直接把所有的从1-1E18的满足条件的数存下来的话一定会超时,但是我们可以注意到1e6^3 = 1e18,所以我们可以先把指数大于3的满足条件的数存下来,指数为2的分开来算(这里要把是别的数平方的数去掉,为了在后面算指数为2的数的时候更方便).在算指数为2的数的时候要注意不可以用floor(sqrt(x))这种方法来取整…
链接: http://codeforces.com/problemset/problem/955/C 题意: Q次询问(1≤Q≤1e5),每次询问给出两个整数L, R(1≤L≤R≤1e18),求所有符合条件的整数x的个数.条件为:L≤x≤R,x = a的p次方(a, p为整数且a>0, p>1). 分析: 一.当指数p=3时,底数a最多有1e6个,由于指数增加时底数收敛得很快,所以我们可以将p>=3时的所有x放进vector里排序去重(预处理),求x的个数的时候二分查找即可.二.对于p=…
http://codeforces.com/contest/1095/problem/C 题意:给n找出k个2的幂,加起来正好等于n.例如 9,4:9 = 1 + 2 + 2 + 4 思路:首先任何数都能表示成2的次幂的和,其次很容易发现,n和k都是二的次幂的情况是最基础的,因为可以分成k个n/k,而n/k一定是二的次幂. 所以,可以得出结论,只要n是2的次幂,且k<=n,一定有解.因为k一定能分成二的次幂的和.假如是 8,3就可以分成 4,1,.4,2这两种基础情况. 如果n不是2的次幂,那n…
B. Powers of Two   You are given n integers a1, a2, ..., an. Find the number of pairs of indexes i, j (i < j) that ai + aj is a power of 2 (i. e. some integer xexists so that ai + aj = 2x). Input The first line contains the single positive integer n …
题目链接 The Sum of the k-th Powers 其实我也不懂为什么这么做的……看了无数题解觉得好厉害哇…… #include <bits/stdc++.h> using namespace std; #define rep(i, a, b) for (int i(a); i <= (b); ++i) #define dec(i, a, b) for (int i(a); i >= (b); --i) ; ; int v[N], p[N], f[N], r[N], b…
题目链接: B. Powers of Two time limit per test 3 seconds memory limit per test 256 megabytes input standard input output standard output You are given n integers a1, a2, ..., an. Find the number of pairs of indexes i, j (i < j) that ai + aj is a power of…
传送门:http://codeforces.com/contest/679/problem/E 题目意思很清晰,给你一个序列,要求你完成以下三个操作: 1.输出A[i] 2.将[a,b]区间的所有数字变成c 3.将[a,b]区间的每个数加上c,若此时区间内有42的整次幂(1,42,422,423,424...),则一直进行此操作,直到区间内没有这类数: 正解: 线段树拓展题目: 先不考虑操作2,只考虑操作3: 我可以给每个数字设置一个等级,即处在(1,42)的数1级,(42,422)的数2级,以…