跳到正文

闲话

关于我写签到题忘开LONGLONG

tiger201303约 1 分钟
原文
文章信息与版本

文章信息

发布
2026年8月12日
收录
2026年10月25日
更新
2026年11月22日
篇幅
约 1 分钟

版本

  1. v1当前

https://vjudge.net/problem/Gym-106589K

就这题,不开LONGLONG见祖宗

C++
#include<bits/stdc++.h>
using namespace std;
namespace alldef{
	#define int long long//已逝
	#define N 200005
}
using namespace alldef;
namespace strc{
	struct NODE{
		int x,id;
	};
}
using namespace strc;
namespace init{
	int n;
	int d[N],ans[N];
	stack<NODE> st;
}
using namespace init;
signed main(){
	cin>>n;
	for(int i=1;i<=n;i++) cin>>d[i];
	for(int i=n;i>=1;i--){
		while(!st.empty() and d[i]+i>=st.top().x) st.pop();
		if(st.empty()) ans[i]=d[i]*d[i];
		else{
			int tmp=st.top().id;
			ans[i]=ans[tmp]+(2*d[i]-tmp+i)*(tmp-i);
		}
		st.push({d[i]+i,i});
	}
	for(int i=1;i<=n;i++) cout<<ans[i]<<'\n';
	return 0;
}
原文