http://codeforces.com/problemset/problem/242/E 题意:给出初始n个数,还有m个操作,操作一种是区间求和,一种是区间xor x. 思路:昨天比赛出的一道类似题目,对于一个数,把它变成二进制,那么做xor操作的时候,其实如果那一位xor 1,那么就是取反,否则不变.于是,可以对每一个二进制位开一棵线段树,由于数字最大有1e6,所以只需要开log(1e6) = 20棵线段树.对每一棵线段树统计区间内1的个数,那一位对答案的贡献就是那一位的权值*区间1的个数…
E. XOR on Segment time limit per test 4 seconds memory limit per test 256 megabytes input standard input output standard output You've got an array a, consisting of n integers a1, a2, ..., an. You are allowed to perform two operations on this array:…
传送门 •题意 给你一个包含 n 个数的序列 a,定义序列上的两个操作: (1)$1,l,r\ :\ ans=\sum_{i=l}^{r}a_i$; (2)$2,l,r,x\ :\ \forall\ i \in[l,r],a_i = a_i\ xor\ x$; 输出操作(1)对应的 ans 值: •题解 因为是异或操作,而异或设计的运算都是在二进制上进行的: 所以考虑按照二进制位建立线段树: 对于每个叶节点,将对应的数转化成二进制的每一位存入到节点信息中: 然后就是区间更新,区间查询操作: •C…
题目链接 给n个数, 两种操作, 一种是求区间内的数的和, 一种是将区间内的数异或x. 异或x没有什么思路, 单个异或肯定超时, 区间异或也没有办法做....后来才知道可以按位建线段树, 这样建20棵线段树就可以. 每一次异或, 对于给定的x, 如果x的第i位是1, 那么就将第i棵线段树在给定的区间内0,1翻转, 这是很基础的操作. 对于区间求和操作, 我们可以求出给定的区间, 从高位到低位, 每一位依次有多少个1, 然后就可以直接求出来, 感觉不好表达....具体看代码. #include<b…
今天练习赛的题....又是线段树的变换..拿到题我就敲了个点更新区间查询的..果断超时...然后想到了可以将每个数与合表示成不进位的二进制数..这样就可以区间进行更新了..比赛的时候写搓了..刚重写了一遍过~~ 为了表示每位的二进制数...线段树开成二维的...第一维老样子~记是树中哪个点..第二维记当前段之和的不进位二进制数...因为最多到10^5...也就是不会超过2^20...第二维开个20就够了.... 区间更新如:   3 3    这段全xor 3...3+3的不进位二进制数为(2,…
[Codeforces 464E] The Classic Problem(可持久化线段树) 题面 给出一个带权无向图,每条边的边权是\(2^{x_i}(x_i<10^5)\),求s到t的最短路\(\mathrm{mod} \ 10^9+7\)的值 分析 显然边权存不下,由于取模会影响大小关系,不能直接取模然后跑dijkstra 考虑用可持久化线段树维护每个点到起点的距离(二进制表示),即维护一个01序列,[1,n]从低位到高位存储. 修改的时候我们要把第i位+1,如果第i位是0,直接取反就可以…
题目链接: http://codeforces.com/problemset/problem/242/E E. XOR on Segment time limit per test 4 secondsmemory limit per test 256 megabytes 问题描述 You've got an array a, consisting of n integers a1, a2, ..., an. You are allowed to perform two operations on…
 FZU 2105  Digits Count Time Limit:10000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Practice Description Given N integers A={A[0],A[1],...,A[N-1]}. Here we have some operations: Operation 1: AND opn L R Here opn, L and R are intege…
D. The Bakery   Some time ago Slastyona the Sweetmaid decided to open her own bakery! She bought required ingredients and a wonder-oven which can bake several types of cakes, and opened the bakery. Soon the expenses started to overcome the income, so…
B. Prison Transfer Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/problemset/problem/427/B Description The prison of your city has n prisoners. As the prison can't accommodate all of them, the city mayor has decided to transfer c…