HDU4747:Mex(线段树区间修改)】的更多相关文章

题意: 给出一个具有N个点的树,现在给出两种操作: 1.get x,表示询问以x作为根的子树中,1的个数. 2.pow x,表示将以x作为根的子树全部翻转(0变1,1变0). 思路:dfs序加上一个线段树区间修改查询. AC代码: #include<iostream>#include<vector>#include<string.h>using namespace std;const int maxn=2e5+5;int sum[maxn<<2],lazy[…
Problem Description In the game of DotA, Pudge’s meat hook is actually the most horrible thing for most of the heroes. The hook is made up of several consecutive metallic sticks which are of the same length.Now Pudge wants to do some operations on th…
Mayor's posters POJ 2528 传送门 线段树区间修改加离散化 #include <cstdio> #include <iostream> #include <queue> #include <cmath> #include <algorithm> #include <cstring> using namespace std; #define ll long long #define P pair<int,in…
题意  给出一段初始化全为1的区间  后面可以一段一段更改成 1 或 2 或3 问最后整段区间的和是多少 思路:标准线段树区间和模版题 #include<cstdio> #include<algorithm> #include<set> #include<vector> #include<cstring> #include<iostream> using namespace std; ; struct Node{ int l,r,su…
描述 A lot of battleships of evil are arranged in a line before the battle. Our commander decides to use our secret weapon to eliminate the battleships. Each of the battleships can be marked a value of endurance. For every attack of our secret weapon,…
Description The citizens of Bytetown, AB, could not stand that the candidates in the mayoral election campaign have been placing their electoral posters at all places at their whim. The city council has finally decided to build an electoral wall for…
传送门 题意: 给出\(n\)个数,然后求\(\sum_{i=1}^n\sum_{j=i}^nmex(i,j)\).\(mex(i,j)\)表示区间\([i,j]\)的\(mex\). 思路: 考虑枚举左右端点的其中一个,然后快速统计答案. 观察发现对于一个\(a_i\),如果区间左端点从包含它到了不包含的状态,那么其会影响\([i+1,next[a_i]-1]\)这个区间中的\(mex\)值. 那么尝试枚举左端点,根据左端点数值快速统计答案.(一开始想的右端点半天出不来啊= ,=) 怎么统计呢…
题目 给定一组数,要求进行若干次操作,这些操作可以分为两种类型: (1) CMD 1 beg end value 将数组中下标在[beg, end] 区间内数字都变为value (2) CMD 2 beg end 求出数组中下标在[beg ,end]区间中的所有数字的和 分析 树状数组在区间查询和单点修改情况下效率较线段树高一些,而无法像线段树一样在O(logN)的时间内完成区间修改.因此使用线段树解决.使用线段树主要的是定义好线段树节点的状态.(如代码中注释所说,状态一定要明确,且容易计算!)…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4747 题意:求一个数列中,所有mex(L,R)的和. 注意到mex是单调不降的,那么首先预处理出mex(1,j)的值,复杂度O(n),因为mex最大为n.同时预处理出每个数a[i]的右边第一次出现a[i]的位置,用next[i]表示.然后依次从1开始枚举起点 i,则就是求 i 到n的所有mex的和了.i从i+1变化,j>next[i]的mex值都不会变化,因为还是存在a[i].那么只要考虑i+1到n…
题意:给你一个序列,让你求出对于所有区间<i, j>的mex和,mex表示该区间没有出现过的最小的整数. 思路:从时限和点数就可以看出是线段树,并且我们可以枚举左端点i, 然后求出所有左端点为i的区间内mex值的和. 先把数插满,然后先询问后删除当前最左边的断点i.而且显然线段树里面保存的是mex值,而且这个序列是非递减的. 分析:我们先预处理出对于右端点为i的所有<1,i>的mex,分别插入线段树的i位置.然后每次删除最左边的左端点i ,假如当前我们要删除a[i] ,我们找到它之…