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…
题目传送门 题意: 给出 n 个数,q次区间查询,每次查询,让你选择任意个下标为 [ l , r ] 区间内的任意数,使这些数异或起来最大,输出最大值. 思路:离线加线性基. 线性基学习博客1 线性基学习博客2 对于此题,先把区间按照 r 从小到大排序,然后依次处理这些区间,每次插入线性基时,优先保留下标比较大的线性基.查询时,只异或上下标大于 l 的值. 记住异或的符号的优先级很低,所以 if( res^p[i] > res )这样的代码是会wa死的,要注意(这道题这么写,样例都过不了) #…
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…
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…
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…
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…
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…