题目链接: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|1
#define mid ll m = (l + r) >> 1
#define ll long long
const ll M = 3e5+;
ll sum[M<<],maxx[M<<],lazy[M<<],a[M],mex[M],n,Next[M];
map<ll,ll>mp;
void pushup(ll rt){
sum[rt] = sum[rt<<] + sum[rt<<|];
maxx[rt] = max(maxx[rt<<] , maxx[rt<<|]);
} void pushdown(ll rt,ll m){
if(lazy[rt]!=-){
lazy[rt<<] = lazy[rt];
lazy[rt<<|] = lazy[rt];
sum[rt<<] = lazy[rt]*(m-(m>>));
sum[rt<<|] = lazy[rt]*(m>>);
maxx[rt<<] = lazy[rt];
maxx[rt<<|] = lazy[rt];
lazy[rt] = -;
}
} void build(ll l,ll r,ll rt){
sum[rt] =; maxx[rt] = ;
lazy[rt] = -;
if(l == r){
sum[rt] = mex[l];
maxx[rt] = mex[l];
return ;
}
mid;
build(lson); build(rson);
pushup(rt);
} /*void ct(ll l,ll r,ll rt){
if(l == r){
cout << maxx[rt]<<" ";
return ;
}
mid;
ct(lson);
ct(rson);
}*/ void update(ll L,ll R,ll c,ll l,ll r,ll rt){
if(L <= l&&R >= r){
lazy[rt] = c;
maxx[rt] = c;
sum[rt] = c*(r-l+);
return ;
}
pushdown(rt,r-l+);
mid;
//cout<<l<<" "<<r<<" "<<sum[1]<<endl;
if(L <= m) update(L,R,c,lson);
if(R > m) update(L,R,c,rson);
pushup(rt);
} ll query(ll p,ll l,ll r,ll rt){
if(l == r) return l;
pushdown(rt,r-l+);
mid;
//cout<<maxx[rt<<1]<<" "<<p<<endl;
if(maxx[rt<<] > p) return query(p,lson);
else return query(p,rson);
} int main()
{
while(scanf("%I64d",&n)&&n){
ll tmp = ;
mp.clear();
for(ll i = ;i <= n;i ++){
scanf("%I64d",&a[i]);
mp[a[i]] = ;
while(mp.find(tmp) != mp.end()) tmp++;
mex[i] = tmp;
}
mp.clear();
for(ll i = n;i >= ;i --){
if(mp.find(a[i]) == mp.end()) Next[i] = n + ;
else Next[i] = mp[a[i]];
mp[a[i]] = i;
}
build(,n,);
ll ans = ;
for(ll i = ;i <= n;i ++){
ans += sum[];
if(maxx[] > a[i]){
ll l = query(a[i],,n,);
ll r = Next[i];
//cout<<l<<" "<<r<<endl;
if(l < r)
update(l,r-,a[i],,n,);
}
update(i,i,,,n,);
}
printf("%I64d\n",ans);
}
return ;
}

hdu 4747 Mex (2013 ACM/ICPC Asia Regional Hangzhou Online)的更多相关文章

  1. HDU 4747 Mex(线段树)(2013 ACM/ICPC Asia Regional Hangzhou Online)

    Problem Description Mex is a function on a set of integers, which is universally used for impartial ...

  2. HDU 4745 Two Rabbits(最长回文子序列)(2013 ACM/ICPC Asia Regional Hangzhou Online)

    Description Long long ago, there lived two rabbits Tom and Jerry in the forest. On a sunny afternoon ...

  3. HDU 4744 Starloop System(最小费用最大流)(2013 ACM/ICPC Asia Regional Hangzhou Online)

    Description At the end of the 200013 th year of the Galaxy era, the war between Carbon-based lives a ...

  4. (并查集)Travel -- hdu -- 5441(2015 ACM/ICPC Asia Regional Changchun Online )

    http://acm.hdu.edu.cn/showproblem.php?pid=5441 Travel Time Limit: 1500/1000 MS (Java/Others)    Memo ...

  5. (二叉树)Elven Postman -- HDU -- 54444(2015 ACM/ICPC Asia Regional Changchun Online)

    http://acm.hdu.edu.cn/showproblem.php?pid=5444 Elven Postman Time Limit: 1500/1000 MS (Java/Others)  ...

  6. [2013 ACM/ICPC Asia Regional Hangzhou Online J/1010]hdu 4747 Mex (线段树)

    题意: + ;];;;], seg[rt <<  | ]);)) * fa.setv;) * fa.setv;;], seg[rt <<  | ], r - l + );;,  ...

  7. HDU 4757 Tree(可持久化字典树)(2013 ACM/ICPC Asia Regional Nanjing Online)

    Problem Description   Zero and One are good friends who always have fun with each other. This time, ...

  8. HDU 4729 An Easy Problem for Elfness(主席树)(2013 ACM/ICPC Asia Regional Chengdu Online)

    Problem Description Pfctgeorge is totally a tall rich and handsome guy. He plans to build a huge wat ...

  9. HDU 4735 Little Wish~ lyrical step~(DLX搜索)(2013 ACM/ICPC Asia Regional Chengdu Online)

    Description N children are living in a tree with exactly N nodes, on each node there lies either a b ...

随机推荐

  1. 大页内存(HugePages)

    原文转载自:http://blog.csdn.net/yutianzuijin/article/details/41912871 今天给大家介绍一种比较新奇的程序性能优化方法—大页内存(HugePag ...

  2. Docker的Mysql数据库:把数据存储在本地目录

    Docker mysql 把数据存储在本地目录,很简单,只需要映射本地目录到容器即可 1.加上-v参数 $ docker run -d -e MYSQL_ROOT_PASSWORD=admin --n ...

  3. 【webstorm】project目录树显示不出

    问题原因:webstorm自动生成的配置文件 .idea/modules.xml损坏. 解决: 1.关掉webstorm: 2.删除该项目下的.idea文件夹(如果隐藏,请设置显示隐藏文件夹): 3. ...

  4. 【stylus】stylus在webstrom中的识别

    <style lang="stylus" rel="stylesheet/stylus"> @import './common/stylus/mix ...

  5. 1.3《想成为黑客,不知道这些命令行可不行》(Learn Enough Command Line to Be Dangerous)——手册页

    我们运行的命令行程序,通常在技术上称作shell, 它包含了一个非常强大(也很神秘)的工具,我们将用它来学习更多可用的命令.这个工具本身就是个称作'man'的命令('manual'的简写).它的参数是 ...

  6. redis系列--redis4.0深入持久化

    前言 在之前的博文中已经详细的介绍了redis4.0基础部分,并且在memcache和redis对比中提及redis提供可靠的数据持久化方案,而memcache没有数据持久化方案,本篇博文将详细介绍r ...

  7. 20155218《网络对抗》Exp2 后门原理与实践

    20155218<网络对抗>Exp2 后门原理与实践 常用后门工具实践 1.Windows获得Linux Shell: 在Windows下,先使用ipconfig指令查看本机IP,使用nc ...

  8. WPF解决按钮上被透明控件遮盖时无法点击问题

    原文:WPF解决按钮上被透明控件遮盖时无法点击问题 IsHitTestVisible="False" 在控件上设置如上属性即可,即可让透明控件不触发点击效果

  9. LeetCode Letter Combinations of a Phone Number (DFS)

    题意 Given a digit string, return all possible letter combinations that the number could represent. A ...

  10. 华为云对Kubernetes在Serverless Container产品落地中的实践经验

    华为云容器实例服务,它基于 Kubernetes 打造,对最终用户直接提供 K8S 的 API.正如前面所说,它最大的优点是用户可以围绕 K8S 直接定义运行应用. 这里值得一提是,我们采用了全物理机 ...