cf这个女cf新角色狐影叫什么,感觉好beautiful

One day, ZS the Coder wrote down an array of integers a with elements a1,
A subarray of the array a is a sequence al,
ar for some integers (l,
r) such that 1
n. ZS the Coder thinks that a subarray of a is beautiful if the bitwise xor of all the elements in the subarray is at least k.
Help ZS the Coder find the number of beautiful subarrays of a!
求异或值大于给定K的区间个数。
xor运算 有 a xor a=0的性质
所以我们可以考虑求区间前缀和。问题转化为对于 <span class="MathJax" id="MathJax-Element-1-Frame" tabindex="0" data-mathml="s[1]..s[n]" role="presentation" style="position:">s[1]..s[n]s[1]..s[n] 有多少组 <span class="MathJax" id="MathJax-Element-2-Frame" tabindex="0" data-mathml="(i,j),i&j" role="presentation" style="position:">(i,j),i&j(i,j),i&j 满足 <span class="MathJax" id="MathJax-Element-3-Frame" tabindex="0" data-mathml="s[j]" role="presentation" style="position:">s[j]s[j] <span class="MathJax" id="MathJax-Element-4-Frame" tabindex="0" data-mathml="xor" role="presentation" style="position:">xorxor <span class="MathJax" id="MathJax-Element-5-Frame" tabindex="0" data-mathml="s[i]&=k" role="presentation" style="position:">s[i]&=ks[i]&=k.
xor问题可考虑01trie树。。
每个节点存,在这个节点下面有多少数。
每插入一个数在trie树查询一下答案,分类讨论计算答案。
const int MAXN=1e6+5;
const int N=1&&25;
int n,k,v[MAXN],sum[MAXN],d[35];
struct trie{
int c[N][2],w[N],
void insert(int pos,int val,int dep){
if(dep==30)return;
int which=((val&(d[dep+1]))&0)?1:0;
if(!c[pos][which])c[pos][which]=++
w[c[pos][which]]++;
insert(c[pos][which],val,dep+1);
ll query(int pos,int val,int dep){
if(!pos)return 0;
if(dep==30)return w[pos];
if(((val&(d[dep+1]))&0)?1:0){
if(k&d[dep+1])ans+=query(c[pos][0],val,dep+1);
else ans+=w[c[pos][0]]+query(c[pos][1],val,dep+1);
if(k&d[dep+1])ans+=query(c[pos][1],val,dep+1);
else ans+=w[c[pos][1]]+query(c[pos][0],val,dep+1);
int main(){
freopen("1.out","w",stdout);
for(int i=29;i&=0;i--)d[i]=d[i+1]&&1;
scanf("%d%d",&n,&k);
for(int i=1;i&=n;i++){
scanf("%d",&v[i]);
sum[i]=sum[i-1]^v[i];
for(int i=1;i&=n;i++){
T.insert(1,sum[i-1],0);
ans+=T.query(1,sum[i],0);
for(int i=1;i&=50;i++)cout&&T.w[i];
printf("%I64d\n",ans);
题意: 给定n个数A[1..n](1
题目链接:点这里!!!
枚举区间的右端点,从左往右一次将前缀异或和插入到trie树(二进制)当中。
至于大于k-1的话,我们把k-1拆成二进制的形...
题意:问你有多少个区间,异或起来大于等于k
思路:显然求个前缀和之后,就等于有多少对数异或起来大于等于k了,每次暴力爬字典树就好了,当k这一位等于0的时候,我们可以直接加上另外一边1的子树大小,因为...
题意:n个元素a[i],问有多少个区间[l,r] 满足a[l]^a[l+1]..a[r] &=k.
枚举区间结尾r,如何快速找到有多少个前缀si满足si^sj&=k?
num[u]:记录有多...
题意:找出异或和&=k的连续子序列个数。
官方题解:http://codeforces.com/blog/entry/44466
using na...
题意:给出一个序列,问有多少个子序列的异或的值大于等于k。
思路:首先预处理出一个异或的前缀值,对于一个位置j,我们的目标是找到所有的I=k
如果一个一个的求异或值,复杂度为O(n^2),现在考虑...
题目链接:http://codeforces.com/contest/665/problem/E题意:求异或值大于给定K的区间个数。分析:首先我们可以得到区间前缀的异或值。
这样我们将这个前缀M和K...
题目传送门:http://codeforces.com/contest/665/problem/E
给你长度n的数组,然后问你有多少个区间,区间异或和大于等于k
区间异或和,一看就是01字典树,然...
求1-n中,能被所有组成他的非0数整除的数的个数
题意很简单,但是考虑到数位dp的状态转移,dfs(pos,pre,status,limit)如果要记录除以他所有数那么势必要用数...
http://codeforces.com/problemset/problem/55/D
Beautiful Numbers : 这个数能整除它的所有位上非零整数。问[l,r]之间的Bea...
没有更多推荐了,题意:n个数,现在以任意的顺序排列,使a[i]+1&a[i],这样的对数最多。
方法一:先排序。对每一个数,向后扫描比它大的那个数,
方法二 :如果n个数都不相同,则必有n-1对符合要求,一旦有最大重复数字个数为m,则有n-1-m对。符合要求。
/*method ——1*/
int a[1005],vis[1005];
int main()
while(~scanf("%d",&n))
for(int i=0;i&n;i++)
scanf("%d",a+i);
sort(a,a+n);
memset(vis,0,sizeof(vis));
int flag,num=0;
for(int i=0;i&n;i++)
flag=a[i];
for(int j=i+1;j&n;j++)
if(a[j]&flag&&(!vis[j]))
printf("%d\n",num);
#include&bits/stdc++.h&
using namespace std;
int a[1002],xx=0;
int main()
for(int i=0;i&n;i++)
cin&&x,xx=max(xx,a[x]++);
printf("%d\n",n-xx-1);
【CodeForces】651B - Beautiful Paintings(暴力)
题目链接:点击打开题目
B. Beautiful Paintings
time limit per test
memory limit per t...
Beautiful Paintings
B. Beautiful Paintings
time limit per test
memory limit per test
256 megabytes
...
题目:http://codeforces.com/problemset/problem/651/B
using namespace ...
Description
给一长度为n的序列,对其重排,使得满足a[i+1]&a[i]的i最多
第一行一整数n表示序列长度,之后n个数a[i]表示该序列(1...
http://codeforces.com/problemset/problem/651/B
B. Beautiful Paintings
time limit per tes...
http://codeforces.com/problemset/problem/651/B
There are n pictures delivered for the new exhibitio...
刚开始以为是简单的排序
后来发现是重新排列后
a[i+1]&a[i]变使cnt++
所以最优排列方法可以是
类似于33这种...
B. Beautiful Paintings
time limit per test
memory limit per test
256 megabytes
standard input
codeforces 651B Beautiful Paintings
B. Beautiful Paintings
time limit per test
memory limit per test
256 megabytes
...
CodeForces 651B Beautiful Paintings
CodeForces 651B Beautiful Paintings
没有更多推荐了,题目链接:
这道题的意思是从以上的几个“美丽数”里找出最大的约数,明白这一点就特别好做,接下来唯一的难点就是把范围内的“美丽数”找出来。有两种方法,第一种用计算器算,第二种代码如下:
#include&stdio.h&
#include&math.h&
int main()
int i,a[100],mls,js=0;
for(i=1;i&100;i++)
mls=(pow(2,i)-1)*(pow(2,(i-1)));
printf("%d\n",mls);
if(mls&1e4)
printf("%d\n",js);
这只是用来求有多少个“美丽数”,最终代码略。
893B Beautiful Divisors
预处理+读题细心先用数组存二进制从一个1开始的到10个1的二进制换算成十进制的大小。用题目中给的公式。10个1九个0,0000000十进制大小是50多万,题目中n10万。随便过...
Beautiful Divisors
Beautiful Divisors
CodeForces - 893B
Recently Luba learned about a special kind of number...
171127 #codeforces# Beautiful Divisors
1 问题描述有一种数字,叫做beautiful numbers,当且仅当它的二进制表示是先由 k+1k+1 个1,再由 kk 个0组成的。比如:而在十进制表示时,有一种更方便的检验方法。如果 n 是一...
CodeForces 893B Beautiful Divisors (打表)
题目大意:最近,Luba了解了一种特殊的数字,他称之为“漂亮的数字”。这个数被称为漂亮是因为它的二进制表示包括k+1个连续的,然后是k个连续的0。
Some examples of beauti...
Counting Divisors
题目链接;点我In mathematics, the function d(n) denotes the number of divisors of positive integer n.For ex...
POJ2992 Divisors【因子个数】
题目大意:
求解出组合数C(n,k)的约数个数。
数据中的n和k值都比较大,直接求解显然不可以。求约数个数,要先进行素因子分解。
C(n,k) = n!/(k!*(n-k)!)。n范围小于等...
Divisors POJ - 2992
题目链接Your task in this problem is to determine the number of divisors of Cnk. Just for fun -- or do y...
Codeforces-182D:Common Divisors(KMP)
Codeforces-182D:Common Divisors(KMP)Vasya has recently learned at school what a number's divisor is ...
CF 27E Number With The Given Amount Of Divisors
A - Number With The Given Amount Of Divisors
Time Limit:2000MS
Memory Limit:262144KB
64bit I...
没有更多推荐了,[CF55D]Beautiful numbers(数位dp,状态压缩)
时间: 12:55:14
&&&& 阅读:248
&&&& 评论:
&&&& 收藏:0
标签:&&&&&&&&&&&&&&&&&&&&&&&&&&&题目链接:http://codeforces.com/problemset/problem/55/D
题意:给定区间,求区间内某数的所有数位能整除这个数本身的数的个数。
起初思路:dp(l,s,sum)表示这个数到l位,并且0~9出现的状态s,和为sum的时候的数字个数。发现这个sum不好处理,因为数字越来越大无法保证这个界限。用到一个性质:一个数能被一堆数整除,当且仅当这个数能被这堆数的最小公倍数整除。换句话说,我们统计这个数对1~9的最小公倍数取模,就能判断这个sum是否可以被各位数整除了。
结果MLE了,因为s这个状态统计了0~9 10个数的状态,所以占用空间是1024,因为0不用考虑,1一定能整除这个sum,所以删掉这两位。
1 #include &bits/stdc++.h&
2 using namespace
3 #define fr first
4 #define sc second
5 #define cl clear
6 #define BUG puts("here!!!")
7 #define W(a) while(a--)
8 #define pb(a) push_back(a)
9 #define Rint(a) scanf("%d", &a)
10 #define Rll(a) scanf("%I64d", &a)
11 #define Rs(a) scanf("%s", a)
12 #define Cin(a) cin && a
13 #define FRead() freopen("in", "r", stdin)
14 #define FWrite() freopen("out", "w", stdout)
15 #define Rep(i, len) for(int i = 0; i & (len); i++)
16 #define For(i, a, len) for(int i = (a); i & (len); i++)
17 #define Cls(a) memset((a), 0, sizeof(a))
18 #define Clr(a, x) memset((a), (x), sizeof(a))
19 #define Full(a) memset((a), 0x7f7f7f, sizeof(a))
20 #define lrt rt && 1
21 #define rrt rt && 1 | 1
22 #define pi 3.
23 #define RT return
24 #define lowbit(x) x & (-x)
25 #define onecnt(x) __builtin_popcount(x)
26 typedef long long LL;
27 typedef long double LD;
28 typedef unsigned long long ULL;
29 typedef pair&int, int&
30 typedef pair&string, int&
31 typedef pair&LL, LL&
32 typedef map&string, int&
33 typedef vector&int&
34 typedef vector&LL&
35 typedef vector&vl&
36 typedef vector&bool&
38 const int maxn = 25;
39 const LL mod = 2520;
40 LL dp[maxn][1&&8][mod];
41 int digit[maxn];
43 LL lcm(LL x, LL y) {
return x / __gcd(x, y) *
47 int get(int i, int s) {
if(i & 2) return
return s | (1 && (i-2));
52 LL dfs(int l, int s, int sum, bool flag) {
if(l == 0) {
For(i, 2, 10) {
if(((1 && (i-2))& s) && (sum % i) != 0) return 0;
if(!flag && ~dp[l][s][sum]) return dp[l][s][sum];
LL ret = 0;
int pos = !flag ? 9 : digit[l];
Rep(i, pos+1) {
ret += dfs(l-1, get(i, s), (sum*10+i)%mod, flag&&(i==pos));
if(!flag) dp[l][s][sum] =
71 LL f(LL x) {
int pos = 0;
while(x) {
digit[++pos] = x % 10;
return dfs(pos, 0, 0, true);
80 signed main() {
//FRead();
Clr(dp, -1);
cin && l &&
cout && f(r) - f(l-1) &&
&标签:&&&&&&&&&&&&&&&&&&&&&&&&&&&原文:http://www.cnblogs.com/vincentX/p/5892087.html
教程昨日排行
&&国之画&&&& &&&&&&
&& &&&&&&&&&&&&&&
鲁ICP备号-4
打开技术之扣,分享程序人生!

我要回帖

更多关于 cf新角色狐影 的文章

 

随机推荐