题目大意:对于一个序列,定义它的价值是它的所有前缀的 $\gcd$ 中互不相同的数的个数.给定整数 $n$,问在 $1$ 到 $n$ 的排列中,有多少个排列的价值达到最大值.答案对 $10^9+7$ 取模. $2\le n\le 10^6$. 一道 Div. 2 的难度 2500 的题,真的不是吹的…… 首先考虑排列的第一个数 .假如分解质因子后为 $\prod p_i^{c_i}$,那么此时排列价值的最大值为 $\sum c_i$. 为什么?因为如果 $\gcd$ 变了,那么一定变成原来 $\…
做法 先来填第一个数,为了保证\(f(p)\)最大,第一个数分解一下为\(\prod\limits_{p_i}p_i^{k_i}\)使得\(\sum\limits_{k_i}\)最大 显然第一个数为\(2^x3^y\)且\(y≤1\),否则可以把\(3^2\)换成\(2^3\),故第一个数最多有两种选择 定义函数\(Cout(x,y)=\frac{n}{2^x3^y}\)为n以内含因子\(2^x3^y\)的个数 设\(f_{i,x,y}\)为填到第\(i\)个数后\(gcd_{j=1}^i a_…
https://codeforces.com/contest/1174/problem/E dp 好题 *(if 满足条件) 满足条件 *1 不满足条件 *0 ///这代码虽然写着方便,但是常数有点大 #include <cstdio> #include <cstdlib> #include <cmath> #include <cstring> #include <string> #include <algorithm> #inclu…
题目链接: http://codeforces.com/contest/1174/problem/D 题意: 构造一个序列,满足以下条件 他的所有子段的异或值不等于$x$ $1 \le a_i<2^n$ 输出一个最长的这样的序列 数据范围: $1 \le n \le 18$$1 \le x<2^{18}$ 分析: 比赛的时候搞混$subsegment$和$subsequence$,前者为子段一定要连续,后者为子序列可以不连续 赛后看的官方题解 假设构造的序列为$a_i$,它的前缀异或和为$b_…
题面 Given two integers \(n\) and \(x\), construct an array that satisfies the following conditions: ·for any element ai in the array, \(1≤ai<2^n\); ·there is no non-empty subsegment with bitwise XOR equal to \(0\) or \(x\), ·its length \(l\) should be…
思路: 使用前缀和技巧进行问题转化:原数组的任意子串的异或值不能等于0或x,可以转化成前缀异或数组的任意两个元素的异或值不能等于0或x. 实现: #include <bits/stdc++.h> using namespace std; << ]; int main() { int n, x; while (cin >> n >> x) { memset(vis, , sizeof vis); vector<int> v; << n)…
做法 求出答案序列的异或前缀和\(sum_i\),\([l,r]\)子段异或和可表示为\(sum_r\bigoplus sum_{l-1}\) 故转换问题为,填\(sum\)数组,数组内的元素不为\(0\)且互不相同,且两两异或不为\(x\) 预处理\(x\)为多对值,每对值异或起来为\(x\),显然是两两互不影响的,每对值选择任意一个填就行了 最后还得从\(sum_i=\bigoplus_{j=1}^i a_i\)转换为\(a_i\) code #include<bits/stdc++.h>…
题中只有两个条件:任意区间异或值不等于0或m. 如果只考虑区间异或值不等于 0,则任意两个前缀异或值不能相等. 而除了不能相等之外,还需保证不能出现任意两个前缀异或值不等于m. 即 $xor[i]$^$xor[j]!=m$, $\Rightarrow$ m^xor[j] 这个异或前缀就不可以再次出现了. 用一个数组标记一下就好了~ #include <bits/stdc++.h> #define N 1000000 #define setIO(s) freopen(s".in&quo…
题目链接:http://codeforces.com/problemset/problem/798/C 题意:给你n个数,a1,a2,....an.要使得gcd(a1,a2,....an)>1,可以执行一次操作使ai,ai+1变为ai - ai + 1, ai + ai + 1.求出使得gcd(a1,a2,....an)>1所需要的最小操作数. 解题思路:首先,要知道如果能够实现gcd(a1,a2,....an)>1,那么a1~an肯定都是偶数(0也是偶数),所以我们的目的就是用最少的操…
Ehab and a component choosing problem 如果有多个连接件那么这几个连接件一定是一样大的, 所以我们先找到值最大的连通块这个肯定是分数的答案. dp[ i ]表示对于 i 这棵子树包含 i 这个点的连通块的最大值, 就能求出答案, 然后知道最大值之后再就能求出几个连接件. #include<bits/stdc++.h> #define LL long long #define fi first #define se second #define mk make…