hdu 4747 mex 线段树+思维】的更多相关文章

http://acm.hdu.edu.cn/showproblem.php?pid=4747 题意: 我们定义mex(l,r)表示一个序列a[l]....a[r]中没有出现过得最小的非负整数, 然后我们给出一个长度为n的序列,求他所有的连续的子序列的mex(l,r)的和. 思路: 首先因为n的最大值就是2*10^5 所有我们字需要考虑200000之内的数就好了,然后O(2*n)可以求出(1,1),(1,2), (1,3),(1,4) ... (1,n)来 mex是不减的. 然后我们考虑将第一个数…
Mex Time Limit: 15000/5000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others)Total Submission(s): 3056    Accepted Submission(s): 1006 Problem Description Mex is a function on a set of integers, which is universally used for impartial game…
参考:http://www.cnblogs.com/oyking/p/3323306.html 相当不错的思路,膜拜之~ 个人理解改日补充. #include <cstdio> #include <cstring> #include <cstdlib> #include <algorithm> #define lson l, m, rt << 1 #define rson m + 1, r, rt << 1 | 1 #define l…
题意: 给出一个有n个数的数列,并定义mex(l, r)表示数列中第l个元素到第r个元素中第一个没有出现的最小非负整数. 求出这个数列中所有mex的值. 思路: 可以看出对于一个数列,mex(r, r~l)是一个递增序列 mex(0, 0~n-1)是很好求的,只需要遍历找出第一个没有出现的最小非负整数就好了.这里有一个小技巧: tmp = ; ; i <= n; ++i) { mp[arr[i]] = ; while (mp.find(tmp) != mp.end()) tmp++; mex[i…
#include<iostream> #include<cstdio> #include<string> #include<cmath> #include<cstring> #include<bits/stdc++.h> using namespace std; typedef long long ll; + ; ll a[ + ]; struct tree { ll l , r; ll val; }t[maxn << ]…
Attack Time Limit: 5000/3000 MS (Java/Others)    Memory Limit: 65768/65768 K (Java/Others)Total Submission(s): 2496    Accepted Submission(s): 788 Problem Description Today is the 10th Annual of “September 11 attacks”, the Al Qaeda is about to attack…
Coder Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 4838    Accepted Submission(s): 1853 Problem Description In mathematics and computer science, an algorithm describes a set of procedures…
Man Down Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 2030    Accepted Submission(s): 743 Problem Description The Game “Man Down 100 floors” is an famous and interesting game.You can enjoy t…
题目链接: acm.hdu.edu.cn/showproblem.php?pid=4747 Mex Time Limit: 15000/5000 MS (Java/Others)Memory Limit: 65535/65535 K (Java/Others) 问题描述 Mex is a function on a set of integers, which is universally used for impartial game theorem. For a non-negative i…
Mex Time Limit: 15000/5000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others)Total Submission(s): 623    Accepted Submission(s): 209 Problem Description Mex is a function on a set of integers, which is universally used for impartial game t…
Problem Description Mex is a function on a set of integers, which is universally used for impartial game theorem. For a non-negative integer set S, mex(S) is defined as the least non-negative integer which is not appeared in S. Now our problem is abo…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4747 题意:有一组序列a[i](1<=i<=N), 让你求所有的mex(l,r), mex(l,r)表示区间[l,r]中最小的未在序列中出现的非负整数. 思路:冥思苦想半天无想法,白做了那么多线段树. 很明显的维护区间问题,容易想到线段树,比较难想到操作. 枚举一个序列的所mex(1,i),mex(2,i)……可以发现序列mex(x,i)是一个单调递增序列,我们需要求得就是所有以x开头的序列和,m…
[题意概述] 一个区间的Mex为这个区间没有出现过的最小自然数,现在给你一个序列,要求求出所有区间的Mex的和. [题解] 扫描线+线段树. 我们在线段树上维护从当前左端点开始的前缀Mex,显然从左到右Mex单调上升. 然后我们把区间左端点逐渐向右边移动,也就是扫描线是左端点. 我们可以发现每次移动的影响就是 [这个数的位置, 这个数下一次出现的位置) 这个区间内大于这个数的Mex全部变为这个数. 那么我们在线段树上二分出第一个大于等于Mex的位置,然后区间修改即可. #include<cstd…
题意:数量为N的序列a和b,a初始全为0,b为给定的1-N的排列.有两种操作:1.将a序列区间[L,R]中的数全部+1:2.查询区间[L,R]中的 ∑⌊ai/bi⌋(向下取整) 分析:对于一个位置i,如果ai<bi,那么该位置不能对结果做出贡献:而当某一次操作后,ai>=bi了,就对结果的贡献值+1.那么可以用在线段树的结点中维护每个区间的最大a和最小b,和已经产生的贡献cnt.如果一个区间中最大的a超过了b,那么就说明此次更新操作使该区间的结果产生了变化,那么就要向下找到那个产生贡献的位置.…
题目链接: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…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4747 思路: 比赛打得太菜了,不想写....线段树莽一下 实现代码: #include<iostream> #include<cstdio> #include<map> #include<cmath> using namespace std; #define lson l,m,rt<<1 #define rson m+1,r,rt<<1|…
http://acm.hdu.edu.cn/showproblem.php?pid=4747 设我们输入的数组为 a[],我们需要从 1 到 n 遍历, 假设遍历到 i 时, 遍历的过程中用b[j]表示从 i 到 j 没出现的最小自然数 先从 n 到 1 扫一遍求出从 1 到各个点的b[j]值 然后遍历a[] 实际上就是不断的把当前a[i] 去掉,比如说去掉a[3]时,剩下的b[4]---b[n] 就表示从4到其他后续点形成的区间中没出现的最小自然数 要知道从 i 到 n ,b[]的值始终是单调…
1.HDU 5877  Weak Pair 2.总结:有多种做法,这里写了dfs+线段树(或+树状树组),还可用主席树或平衡树,但还不会这两个 3.思路:利用dfs遍历子节点,同时对于每个子节点au,查询它有多少个祖先av满足av<=k/au. (1)dfs+线段树 #include<iostream> #include<cstring> #include<cmath> #include<queue> #include<algorithm>…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3308 题目很好懂,就是单点更新,然后求区间的最长上升子序列. 线段树区间合并问题,注意合并的条件是a[mid + 1] > a[mid],写的细心点就好了. #include <iostream> #include <cstring> #include <cstdio> using namespace std; ; struct SegTree { int l , r…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2795 题目大意:有一块h*w的矩形广告板,要往上面贴广告;   然后给n个1*wi的广告,要求把广告贴上去: 而且要求广告要尽量往上贴并且尽量靠左;  求每个广告的所在的位置,不能贴则为-1. 用线段树模拟,要是左子树的最大值比当前广告大,就查询更新左子树,否则就右子树. #include <iostream> #include <cstdio> #include <cstrin…
Conturbatio Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5480 Description There are many rook on a chessboard, a rook can attack the row and column it belongs, including its own place. There are also many quer…
http://acm.hdu.edu.cn/showproblem.php?pid=1828 Picture Time Limit: 6000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 2135    Accepted Submission(s): 1134 Problem Description A number of rectangular posters,…
题意:给你一个序列,让你求出对于所有区间<i, j>的mex和,mex表示该区间没有出现过的最小的整数. 思路:从时限和点数就可以看出是线段树,并且我们可以枚举左端点i, 然后求出所有左端点为i的区间内mex值的和. 先把数插满,然后先询问后删除当前最左边的断点i.而且显然线段树里面保存的是mex值,而且这个序列是非递减的. 分析:我们先预处理出对于右端点为i的所有<1,i>的mex,分别插入线段树的i位置.然后每次删除最左边的左端点i ,假如当前我们要删除a[i] ,我们找到它之…
可耻的看了题解 巧妙的思维 逆序插入,pos 代表的意义为前面要有pos个空格才OK: 证明:仔细思考一下就觉得是正确的,但是要想到这种方式还是要很聪明,空格是前面的几个数字所形成的,所以要特地留出来,因为这几个空格是既定的事实 线段树实现 线段的意义:当前线段留的空格数,满足区间和性质 代码如下: #include <cstdio> #include <cstdlib> #include <cmath> #include <cstring> #includ…
题目链接 题意:多次求区间\(mex\). 考虑\([1,i]\)的\(mex[i]\),显然是单调的 而对于\([l,r]\)与\([l+1,r]\),如果\(nxt[a[l]]>r\),那么\([l+1,r]\)中所有\(>a[l]\)的数显然要改成\(a[l]\) 把询问按左端点排序:离散化,预处理下\(nxt[]\),处理出\([1,i]\)的\(mex[i]\).剩下就是线段树的区间更新.单点查询了 /* 离散化的时候>=n的全部看做n就好了 查询时是只需查r点的(l之前能更新…
题目http://acm.hdu.edu.cn/showproblem.php?pid=5692 题目说每个点至多经过一次,那么就是只能一条路线走到底的意思,看到这题的格式, 多个询问多个更新, 自然而然的就会想到线段树或者树状数组,在建树前先做处理, 用DFS将从起点0出发到任一点的距离求出, 然后将这些节点按照一条一条完整的路线的顺序建到树中, 比如样例是1---2---3 | 6 ---4----5 所以建树的其中一种顺序是1 4 5 6 2 3 .当查询的时候的区间应该是从现在这个点开始…
http://acm.hdu.edu.cn/showproblem.php?pid=1754 数据比较大,暴力会超时,所以明显是线段树,普通的线段树,结构体中多开一个值sum储存每个子区间的最大成绩,借此更新和查找就行,差不多就是裸的线段树模板 这种基础的要思考透,多按自己的思想修改修改尝试,不然后面的线段树学习会很吃力 code #include<cstdio> using namespace std; struct point { int l,r,sum; }; point tree[*]…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1542 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Problem Description There are several ancient Greek texts that contain descriptions of the fabled island Atlantis. So…
题目链接: http://acm.split.hdu.edu.cn/showproblem.php?pid=5861 Road Time Limit: 12000/6000 MS (Java/Others)Memory Limit: 65536/65536 K (Java/Others) 问题描述 There are n villages along a high way, and divided the high way into n-1 segments. Each segment woul…
Billboard Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=2795 Description At the entrance to the university, there is a huge rectangular billboard of size h*w (h is its height and w is its width). The board is…