| 记录编号 | 330346 | 评测结果 | AAAAAAAAAA | 
    
        | 题目名称 | 2514.艺术 | 最终得分 | 100 | 
    
        | 用户昵称 |  Magic_Sheep | 是否通过 | 通过 | 
    
        | 代码语言 | C++ | 运行时间 | 0.194 s | 
    
        | 提交时间 | 2016-10-26 15:33:57 | 内存使用 | 1.23 MiB | 
    
    
    
    		显示代码纯文本
		
		#include<cstdio>
#include<iostream>
using namespace std;
const int maxn=100110;
int n,a[maxn],op[maxn],f[maxn];
bool vis[maxn];
long long h[maxn],maxx,res[maxn];
inline int find(int x)
{
	if(f[x]==x) return x;
	else return f[x]=find(f[x]);
}
int MAIN()
{
	freopen("art.in","r",stdin);
	freopen("art.out","w",stdout);
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%d",&a[i]),f[i]=i,h[i]=a[i];
	for(int i=1;i<=n;i++) scanf("%d",&op[i]);
	for(int i=n;i>=1;i--)
	{
		int fa,fb,fc;
		int cur=op[i];
		vis[cur]=true;
		if(vis[cur-1])
		{
			fa=find(cur-1);
			fb=find(cur);
			f[fb]=fa;
			h[fa]+=h[fb];
		}
		if(vis[cur+1])
		{
			fb=find(cur);
			fc=find(cur+1);
			f[fc]=fb;
			h[fb]+=h[fc];
		}
		fb=find(cur);
		if(h[fb]>maxx) maxx=h[fb];
		res[i]=maxx;
		//cout<<h[fb]<<endl;
	}
	for(int i=2;i<=n+1;i++) printf("%lld\n",res[i]);
	//for(int i=1;i<=n;i++) cout<<h[i]<<" ";
	return 0;
} 
int EZOI=MAIN();
int main(){;}
/*
5
5 1 2 3 4
3 5 4 1 2
*/