求助
查看原帖
求助
1070754
lijunxi20231818楼主2024/3/15 20:28

求助大佬,第38个点Wa了QAQ

#include<bits/stdc++.h>
#define maxn 100005
#define mod (int)(1e9 + 7)
#define int long long
using namespace std;
int h[maxn], w[maxn], S[maxn], n, sum, ans, tot;
int c2(int x){
	return x * (x + 1) / 2 % mod;
}
signed main(){
	cin >> n;
	for(int i = 1; i <= n; i++) cin >> h[i];
	for(int i = 1; i <= n; i++) cin >> w[i];
	S[++tot] = 0;
	for(int i = 1; i <= n + 1; i++){
		sum = 0;
		while(h[S[tot]] > h[i]){
			sum = (sum + w[S[tot]]) % mod;
			ans = (ans + (c2(h[S[tot]]) - c2(max(h[i], h[S[--tot]]))) * c2(sum) % mod) % mod;
		}
		w[i] += sum;
		S[++tot] = i;
	}
	cout << ans;
	return 0;
}
2024/3/15 20:28
加载中...