线段树!!1A 代码如下: #include<iostream> #include<cstdio> #define lson i<<1 #define rson i<<1|1 #define MAX 140000 #define ll __int64 using namespace std; ll a[MAX],s; struct tree { int l,r; ll res; bool flag; }T[*MAX]; //奇数OR,偶数XOR void b…
转载请注明出处: http://www.cnblogs.com/fraud/          ——by fraud Xenia and Bit Operations Xenia the beginner programmer has a sequence a, consisting of 2n non-negative integers: a1, a2, ..., a2n. Xenia is currently studying bit operations. To better unders…
题意:给定 2的 n 次方个数,对这些数两个两个的进行或运算,然后会减少一半的数,然后再进行异或运算,又少了一半,然后再进行或运算,再进行异或,不断重复,到最后只剩下一个数,要输出这个数,然后有 m 个询问, 每个询问有 p 和 b,要求把第 p 个数改成 b,再这样运算,输出结果. 析:这个题是不是很像线段树,不过这个题不是随机询问哪个区间,区间是固定的,这样也就简单了很多,就省下了一个query函数,再就是线段树是从上到下的,所以我们要分好到底是异或还是或,然后就很简单了, 其实这个题也可以…
题目链接:CF - R296 - d2 - D 题目大意 一个特殊的图,一些数轴上的点,每个点有一个坐标 X,有一个权值 W,两点 (i, j) 之间有边当且仅当 |Xi - Xj| >= Wi + Wj. 求这个图的最大团. 图的点数 n <= 10^5. 题目分析 两点之间右边满足 Xj - Xi >= Wi + Wj (Xi < Xj)       ==>     Xj  - Wj >= Xi + Wi (Xi < Xj) 按照坐标 x 从小到大将点排序.用…
题目链接:http://codeforces.com/contest/1154/problem/E 题意:两个人轮流取最大值与旁边k个数,问最后这所有的数分别被谁给取走了 分析:看这道题一点思路都没有,想不到模拟链表也该能想到线段树的啊 大部分AC代码是模拟链表的,写起来也更快,但我线段树很不熟,线段树的代码也写一份吧 另外,以后要养成一种习惯,除了主函数定义int main里有int外,其他地方统一用ll了,不要自己给自己挖坑..... 线段树: 意识到是线段树后我建树部分就拿不准怎么做,事实…
Problem DescriptionIn a galaxy far, far away, there are two integer sequence a and b of length n.b is a static permutation of 1 to n. Initially a is filled with zeroes.There are two kind of operations:1. add l r: add one for al,al+1...ar2. query l r:…
题目大意 题目链接Naive Operations 题目大意: 区间加1(在a数组中) 区间求ai/bi的和 ai初值全部为0,bi给出,且为n的排列,多组数据(<=5),n,q<=1e5 axmorz 思路 因为是整除,所以一次加法可以对ans 没有影响 当ai是bi的倍数,对ans会有贡献 所以我们维护一个sum,初值为bi(只对于线段树的叶子节点有用) 当区间+1的时候 我们对sum-1 当sum=0的时候(倍数) ans++,sum=bi 然后再维护一个区间最小值 当区间内的mi>…
Naive Operations Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 502768/502768 K (Java/Others)Total Submission(s): 2114    Accepted Submission(s): 915 Problem Description In a galaxy far, far away, there are two integer sequence a and b of le…
CF 666E Forensic Examination 题意: 给出一个串\(s\)和\(n\)个串\(t_i\),\(q\)次询问,每次询问串\(s\)的子串\(s[p_l:p_r]\)在串\(t_l\)到\(t_r\)中哪个串中出现次数最多,以及出现次数最多的哪个串的下标 题解: 考虑把\(n\)个\(t\)串建出广义后缀自动机,然后后缀自动机上每个节点用动态开点线段树来维护每个\(t\)串能匹配到的数量,把每个\(t\)串的每个后缀能匹配的最长的串对应的后缀自动机上的点以当前\(t\)串…
A. Glass Carving time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Leonid wants to become a glass carver (the person who creates beautiful artworks by cutting the glass). He already has a re…