题目链接: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…
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 arr…
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…
As you might remember from the previous round, Vova is currently playing a strategic game known as Rage of Empires. Vova managed to build a large army, but forgot about the main person in the army - the commander. So he tries to hire a commander, and…
题目链接:Perfect Security 题意:给出N个数代表密码,再给出N个数代表key.现在要将key组排序,使key组和密码组的亦或所形成的组字典序最小. 题解:要使密码组里面每个数都找到能使其亦或和最小的数可以将key建成一棵字典树(这里建树方式很关键,可以每个数都从2^31开始建树,这样可以使我们在遍历树查询更加方便).之后再遍历密码组每次在字典树里面找到一个能使它亦或和最小的数,再将这个数从字典树中删掉...  字典树太久不写,很多东西都忘记了! #include<bits/std…
题目链接: http://codeforces.com/contest/665/problem/E 题意: 求异或值大于给定K的区间个数. 分析: 首先我们可以得到区间前缀的异或值. 这样我们将这个前缀M和K一起走trie树,如果该位K的值为0,那么无论怎么走最后得到的答案都不会比K小,所以直接加上另一边的子树大小,然后继续沿着当前边走.如果该位K的值为1,那么想要大于等于K必须沿着另一边贪心的走. 代码: #include<cstdio> #include<iostream> u…
题目链接:282E Sausage Maximization 题目大意:给定一个序列A.要求从中选取一个前缀,一个后缀,能够为空,当时不能重叠.亦或和最大. 解题思路:预处理出前缀后缀亦或和,然后在字典树中维护.每次加入并查询.过程中维护ans. #include <cstdio> #include <cstring> #include <cmath> #include <algorithm> using namespace std; typedef lon…