题目链接: http://codeforces.com/contest/665/problem/E 题意: 求异或值大于给定K的区间个数. 分析: 首先我们可以得到区间前缀的异或值. 这样我们将这个前缀M和K一起走trie树,如果该位K的值为0,那么无论怎么走最后得到的答案都不会比K小,所以直接加上另一边的子树大小,然后继续沿着当前边走.如果该位K的值为1,那么想要大于等于K必须沿着另一边贪心的走. 代码: #include<cstdio> #include<iostream> u…
题目链接:http://codeforces.com/problemset/problem/665/E (http://www.fjutacm.com/Problem.jsp?pid=2255) 题意:找出有多少个连续的区间[l,r](1  ≤  l  ≤  r  ≤  n),该区间中所有的数的异或值大于等于k: 思路:首先,如果是单看题目的话,会发现暴力的话复杂度是O(n^3),但是我们先预处理异或前缀和,然后你会发现[l,r]区间的异或和等于s[l-1]^s[r],这样就可以O(n^2)的求…
E. Beautiful Subarrays 题目连接: http://www.codeforces.com/contest/665/problem/E Description One day, ZS the Coder wrote down an array of integers a with elements a1,  a2,  ...,  an. A subarray of the array a is a sequence al,  al  +  1,  ...,  ar for so…
题目链接: E. Beautiful Subarrays time limit per test 3 seconds memory limit per test 512 megabytes input standard input output standard output One day, ZS the Coder wrote down an array of integers a with elements a1,  a2,  ...,  an. A subarray of the arr…
http://codeforces.com/contest/665/problem/E 给定一个序列,问其中有多少个区间,所有数字异或起来 >= k 看到异或,就应该想到异或的性质,A^B^B = A,所以,用sum[i]表示1--i的异或值,那么i...j的异或值就是sum[j] ^ sum[i - 1] 所以原问题转化为在一个数组中,任选两个数,异或值 >= k 首先所有数字 <= 1e9 那么前缀异或值 <= 2^31 - 1 那么用int就够了,从30位开始插入字典树,(1…
题目链接 给一个数列, 让你找出异或结果大于等于k的子序列的个数. 因为任意一段序列的异或值都可以用前缀异或和来表示, 所以我们先求出前缀异或和. 我们考虑字典树, 对于每一个前缀sum, 我们先查询现有的字典树中有多少个数可以与它异或后大于等于k, 在将这个sum插入到字典树中. 这样就可以求出所有区间的异或情况. 具体操作看代码. #include <iostream> #include <vector> #include <cstdio> #include <…
E. Beautiful Subarrays time limit per test: 3 seconds memory limit per test: 512 megabytes input: standard input output: standard output One day, ZS the Coder wrote down an array of integers a with elements a1,  a2,  ...,  an. A subarray of the array…
E. Beautiful Subarrays   One day, ZS the Coder wrote down an array of integers a with elements a1,  a2,  ...,  an. A subarray of the array a is a sequence al,  al  +  1,  ...,  ar for some integers (l,  r) such that 1  ≤  l  ≤  r  ≤  n. ZS the Coder…
Beautiful Subarrays time limit per test 3 seconds memory limit per test 512 megabytes input standard input output standard output One day, ZS the Coder wrote down an array of integers a with elements a1,  a2,  ...,  an. A subarray of the array a is a…
Codeforces 55D Beautiful Number a positive integer number is beautiful if and only if it is divisible by each of its nonzero digits. Input The first line of the input contains the number of cases t (1 ≤ t ≤ 10). Each of the next t lines contains two…