Submission #801557

# Submission time Handle Problem Language Result Execution time Memory
801557 2023-08-02T06:36:02 Z gun_gan Fancy Fence (CEOI20_fancyfence) C++17
0 / 100
13 ms 4232 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

const int MX = 1e5, mod = 1e9 + 7, inv = 500000004;

int N;
ll h[MX], w[MX];
ll L[MX], R[MX], sum[MX];

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);
	
	cin >> N;
	
	for(int i = 1; i <= N; i++) cin >> h[i];
	for(int i = 1; i <= N; i++) cin >> w[i];
	
	vector<pair<ll,ll>> v;
	
	for(int i = 1; i <= N; i++) {
		while(!v.empty() && v.back() > make_pair(h[i], (ll)i)) v.pop_back();
		if(!v.empty()) L[i] = v.back().second;
		v.push_back({h[i], i});
	}
	
	v.clear();
	
	for(int i = N; i >= 1; i--) {
		while(!v.empty() && v.back() > make_pair(h[i], (ll)i)) v.pop_back();
		if(!v.empty()) R[i] = v.back().second;
		else R[i] = N + 1;
		v.push_back({h[i], i});
	}
	
	v.clear();
	
	for(int i = 1; i <= N; i++) sum[i] = sum[i - 1] + w[i];
	
	// for(int i = 1; i <= N; i++) {
	// 	cout << L[i] << " " << R[i] << '\n';
	// }
	
	ll ans = 0;
	for(int i = 1; i <= N; i++) {
		ll x = sum[i] - sum[L[i]];
		ll y = sum[R[i] - 1] - sum[i];
		x %= mod, y %= mod;
		
		ans += 1ll * h[i] * (h[i] - 1) % mod * x % mod * y % mod * inv % mod;
		ans += 1ll * h[i] * x % mod * y % mod;
		ans %= mod;
	
		
		x = sum[i - 1] - sum[L[i]];
		y = sum[R[i] - 1] - sum[i - 1];
		x %= mod, y %= mod;
		
		ans += 1ll * h[i] * (h[i] - 1) % mod * x % mod * y % mod * inv % mod;
		ans += 1ll * h[i] * x % mod * y % mod;
		ans %= mod;
		
		ans += 1ll * w[i] * (w[i] - 1) % mod * inv % mod * h[i] % mod * (h[i] - 1) % mod * inv % mod;
		ans += 1ll * w[i] * h[i] % mod * (h[i] - 1) % mod * inv % mod;
		ans += 1ll * h[i] * w[i] % mod * (w[i] - 1) % mod * inv % mod;
		ans += 1ll * w[i] * h[i] % mod;
		ans %= mod;
		
		// cout << ans << '\n';
	}
	
	cout << ans << '\n';
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Incorrect 1 ms 340 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Incorrect 1 ms 340 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 3 ms 1116 KB Output is correct
3 Correct 12 ms 4188 KB Output is correct
4 Runtime error 10 ms 3120 KB Execution killed with signal 11
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 3 ms 1112 KB Output is correct
4 Correct 13 ms 4232 KB Output is correct
5 Runtime error 9 ms 3172 KB Execution killed with signal 11
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Incorrect 1 ms 340 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Incorrect 1 ms 340 KB Output isn't correct
3 Halted 0 ms 0 KB -