HDOJ 4747 Mex
非常好的线段树题。。。。此题必定会火。。。。。
Mex
Time Limit: 15000/5000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others)
Total Submission(s): 955 Accepted Submission(s): 320
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.
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.
0 1 3
5
1 0 2 0 10
24
For the first test case:mex(1,1)=1, mex(1,2)=2, mex(1,3)=2, mex(2,2)=0, mex(2,3)=0,mex(3,3)=0. 1 + 2 + 2 + 0 +0 +0 = 5.
#include <iostream>
#include <cstdio> #include <cstring> #include <map> #define lson l,m,rt<<1 using namespace std; const int maxn=200005; typedef long long int LL; int a[maxn],mex[maxn],next[maxn],mx[maxn<<2],sig[maxn<<2],cnt; void pushUP(int rt) void pushDOWN(int rt,int len) void build(int l,int r,int rt) LL query(int L,int R,int l,int r,int rt) int getID(int L,int R,int v,int l,int r,int rt) void update(int L,int R,int c,int l,int r,int rt) int main() |
* This source code was highlighted by YcdoiT. ( style: Codeblocks )
HDOJ 4747 Mex的更多相关文章
- HDU 4747 Mex 递推/线段树
题目链接: acm.hdu.edu.cn/showproblem.php?pid=4747 Mex Time Limit: 15000/5000 MS (Java/Others)Memory Limi ...
- 【HDU 4747 Mex】线段数
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4747 题意:有一组序列a[i](1<=i<=N), 让你求所有的mex(l,r), mex ...
- [HDU 4747] Mex (线段树)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4747 这道题是我去年刚入校队的时候参加网赛的题目. 一年过去了,我依然还是不会做.. 这是我难题计划的 ...
- HDU 4747 Mex(线段树)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4747 题意:给出一个数列A.计算所有的mex(i,j)之和.1<=i<=j<=n. ...
- hdu 4747 Mex (2013 ACM/ICPC Asia Regional Hangzhou Online)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4747 思路: 比赛打得太菜了,不想写....线段树莽一下 实现代码: #include<iost ...
- hdu 4747 mex 线段树+思维
http://acm.hdu.edu.cn/showproblem.php?pid=4747 题意: 我们定义mex(l,r)表示一个序列a[l]....a[r]中没有出现过得最小的非负整数, 然后我 ...
- hdu 4747 Mex
http://acm.hdu.edu.cn/showproblem.php?pid=4747 设我们输入的数组为 a[],我们需要从 1 到 n 遍历, 假设遍历到 i 时, 遍历的过程中用b[j]表 ...
- HDU 4747 Mex (2013杭州网络赛1010题,线段树)
Mex Time Limit: 15000/5000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others)Total Submis ...
- hdu 4747 Mex( 线段树? 不,区间处理就行(dp?))
Mex Time Limit: 15000/5000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others)Total Submis ...
随机推荐
- C#的参数修饰符out,params,ref
using System; namespace ParamsProgram { class TestParams { public static void Main(string[] args)//s ...
- Swift&Node 使用Alamofire进行Post
这篇博客主要实现Swift客户端和NodeJS后台的Post.Get请求实现. 我是一个略有点讨厌重复使用工具的人,比如这些基本功能完全可以用OC和PHP等替代,但是没办法,现在知识更新的太快啦,Sw ...
- SQL 命令
登录系统: mysql -u user_name -p 查看当前用户列表:select user; 查看数据库列表: show databases 进入某数据库: use db_name; 查看某数据 ...
- pycharm和输入法的冲突bug
Solution:Either upgrade IBus to version 1.5.11 or add "export IBUS_ENABLE_SYNC_MODE=1" to ...
- Linux DHCP通过OPTION43为H3C的AP下发AC地址(总结)
对于DHCP服务,可以在很多平台上进行设置.那么这里我们就主要讲解一下在Linux DHCP服务器上通过option 43实现H3C的AP自动联系AC注册的相关内容.原来的DHCP Server是放在 ...
- struts2文件目录结构
apps 文件夹包含了多个 example 示例应用的压缩包. docs 文件夹包含了 struts 官方的帮助文档. lib 文件夹包含了 struts 提供的类库 jar 包. src 文件夹包含 ...
- java编程思想-java中的并发(二)
二.共享受限资源 有了并发就可以同时做多件事情了.但是,两个或多个线程彼此互相干涉的问题也就出现了.如果不防范这种冲突,就可能发生两个线程同时试图访问同一个银行账户,或向同一个打印机打印,改变同一个值 ...
- Extjs GridPanel用法详解
Extjs GridPanel 提供了非常强大数据表格功能,在GridPanel可以展示数据列表,可以对数据列表进行选择.编辑等.在之前的Extjs MVC开发模式详解中,我们已经使用到了GridPa ...
- jQuery $.fn 方法扩展~
//以下代码紧跟在引进的jquery.js代码后面 <script type="Text/JavaScript"> $(function (){ //扩展myName方 ...
- bootstrap的学习-基础样式和排版一
一.列表去除样式和横排排列 classs="list-unstyled","list-inline" 二.[表格].table 类指定基本样式,.table-s ...