草稿和一些题解而已

因为指针太恶心了

所以query决定还是要试试自己yy一下

#include<cstdio>
#include<cstring>
#include<iostream>
#define ll long long
using namespace std;
int maxx[4000101],poss[4000101],n;
struct node{
int a,posl;
};
void pushup(int rt){
if (maxx[rt<<1]>maxx[rt<<1|1])maxx[rt]=maxx[rt<<1],poss[rt]=poss[rt<<1];
else maxx[rt]=maxx[rt<<1|1],poss[rt]=poss[rt<<1|1];
}
void build(int l, int r, int rt) {
if (l == r){
maxx[rt]=0;
poss[rt]=l;return ;
}
int m = (l + r) >> 1;
build(l,m,rt<<1);
build(m+1,r,(rt<<1)|1);
pushup(rt);
}
void update(int p,int c, int l,int r,int rt) {
if (l == r){
maxx[rt]=c;return ;
}
int m=(l+r)>>1;
if(p<=m)update(p,c,l,m,rt<<1);
else update(p,c,m+1,r,(rt<<1)|1);
pushup(rt);
}
node query(int L, int R, int l, int r, int rt){
if (L <= l&&r<= R){
node x;
x.a=maxx[rt];x.posl=poss[rt];
return x;
}
int m =(l+r)>>1;
node ans;ans.a=0;
if(L<=m){
node kk=query(L,R,l, m,rt<<1);if(kk.a>ans.a)ans=kk;
}
if(R>m){
node kk=query(L,R,m+1,r,(rt<<1)|1);if(kk.a>ans.a)ans=kk;
}
return ans;
}
ll a[101000],dp[101000];
int main(){
scanf("%d",&n);
memset(dp,0,sizeof(dp));
ll ans=0;
build(1,n,1);
for(int i=1;i<=n-1;i++)scanf("%lld",&a[i]);
update(n,n,1,n,1);
for(int i=n-1; i>=1;i--){
node temp=query(i+1,a[i],1,n,1);
dp[i]=dp[temp.posl]+(n-i)-(a[i]-temp.posl);
ans+=dp[i];
update(i,a[i],1,n,1);
}
printf("%lld",ans);
return 0;
}

yy完毕,写了个傻逼结构体

最新文章

  1. NancyFX 简介
  2. css毛玻璃效果
  3. C#基础系列——再也不用担心面试官问我“事件”了
  4. selenium 右键下载图片,结合sikuli
  5. sublime文档
  6. jQueryEasyUI Messager基本使用
  7. EF Core &#187; 关系
  8. 修复iPhone的safari浏览器上submit按钮圆角bug
  9. ZOJ 1115 Digital Roots(简单,字符串与数)
  10. AIZU 0005
  11. Python的文件与文件夹操作
  12. URAL 2025. Line Fighting (math)
  13. Eclipse开启Mybatis-config.xml配置文件智能提示
  14. java获取当前日期时间代码总结
  15. oracle sql model从句demo
  16. C7.cpp
  17. map/reduce/filter/lambda
  18. 首次使用Vue开发
  19. JavaScript内置对象——Math对象
  20. BMP文件格式实例分析

热门文章

  1. Apache HttpComponents中的cookie匹配策略
  2. Java实现Package编译和访问
  3. CUDA和OpenGL互操作经典博文赏析和学习
  4. sqoop执行job报错(org/json/JSONObject)
  5. 对cordova打包的apk文件进行签名
  6. HDU 1025 LIS二分优化
  7. [iOS]拾遗补阙
  8. 大数据入门:Maven项目的创建及相关配置
  9. SAP RANG语法
  10. ALV-TREE -转