hdu4747(线段树区间更新)
来源:互联网 发布:led走字屏改字软件 编辑:程序博客网 时间:2024/06/06 02:15
Mex
Time Limit: 15000/5000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others)Total Submission(s): 1892 Accepted Submission(s): 625
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 about mex function on a sequence.
Consider a sequence of non-negative integers {ai}, we define mex(L,R) as the least non-negative integer which is not appeared in the continuous subsequence from aL to aR, inclusive. Now we want to calculate the sum of mex(L,R) for all 1 <= L <= R <= n.
Consider a sequence of non-negative integers {ai}, we define mex(L,R) as the least non-negative integer which is not appeared in the continuous subsequence from aL to aR, inclusive. Now we want to calculate the sum of mex(L,R) for all 1 <= L <= R <= n.
Input
The input contains at most 20 test cases.
For each test case, the first line contains one integer n, denoting the length of sequence.
The next line contains n non-integers separated by space, denoting the sequence.
(1 <= n <= 200000, 0 <= ai <= 10^9)
The input ends with n = 0.
For each test case, the first line contains one integer n, denoting the length of sequence.
The next line contains n non-integers separated by space, denoting the sequence.
(1 <= n <= 200000, 0 <= ai <= 10^9)
The input ends with n = 0.
Output
For each test case, output one line containing a integer denoting the answer.
Sample Input
30 1 351 0 2 0 10
Sample Output
524
题意:求所有区间mex的总和,定义mex[i,j]为区间[i,j]没有出现过的最小的数
思路:比较好的线段树题
先预处理出mex[1,i] (1=<i<=n)
然后预处理出每个位置 i 的下一个位置 next[i] ,假设现在位置的数为x,那么规定它的下一个位置为它后面离它最近的x的位置
然后 i 从1-n开始搞,每次删除i位置的数,然后在[ i+1,next[i]-1 ]这些位置找到满足位置p,且p位置的mex[i,p]值>value[i]
那么后面到next[i]-1的所有区间的mex都是大于value[i]的,因为mex满足单调性
然后就将mex[ p,next[i]-1 ]区间的值修改为value[i]
最后区间[i+1,n]求和就是以i+1为左端点,i+2~n为右端点的所有区间的mex和
涉及到的操作,区间更新,区间求和,区间求最大
0 0
- hdu4747(线段树区间更新)
- hdu4747 线段树
- hdu4747 mex 线段树
- hdu4747 Mex 线段树 (2013网络赛)
- 线段树(单点更新+区间更新)
- 线段树区间更新
- 线段树区间更新
- 线段树 区间更新
- 线段树区间更新
- 线段树-区间更新
- 线段树区间更新
- 线段树区间更新
- 线段树区间更新
- 区间更新线段树
- 线段树区间更新
- 线段树 区间更新
- 线段树区间更新
- hdu4747 Mex (线段树 好题)
- Google hacking语法总结
- 用pil产生验证码出现:ImportError: The _imagingft C module is not installed
- 【解决】centos6.2 spark cluster问题(持续追加)
- Spark1.0.0 history server 配置
- Brackets Sequence(记搜)
- hdu4747(线段树区间更新)
- 程序中的keywords的缩写记录
- 019写程序在一棵二叉树中找到两个结点的最近共同祖先(keep it up)
- 软件系统开发中的数据交换协议
- 单例模式
- MinGW安装
- Spark1.0.0 运行架构基本概念
- spark比较好的博客
- search.c