Submission #759012

# Submission time Handle Problem Language Result Execution time Memory
759012 2023-06-15T16:43:38 Z ymm Fancy Fence (CEOI20_fancyfence) C++17
100 / 100
24 ms 10704 KB
#include <bits/stdc++.h>
#define Loop(x,l,r) for (ll x = (l); x < (ll)(r); ++x)
#define LoopR(x,l,r) for (ll x = (r)-1; x >= (ll)(l); --x)
typedef long long ll;
typedef std::pair<int, int> pii;
typedef std::pair<ll , ll > pll;
using namespace std;

const int mod = 1e9+7;
const int N = 100'010;
int lft[N], rgt[N];
ll h[N], w[N], ps[N];
int n;

ll solve(int l, int r, int i, ll hx)
{
	if (l >= r)
		return 0;
	ll x = h[i] - hx;
	ll y = ps[r] - ps[l];
	ll yy = (y%mod) * ((y+1)%mod) % mod * ((mod+1)/2) % mod;
	ll ans = 0;
	ans += (x*(x+1)/2 % mod) * yy;
	ans += (x * hx % mod) * yy;
	ans += solve(l, i, lft[i], h[i]);
	ans += solve(i+1, r, rgt[i], h[i]);
	ans %= mod;
	return ans;
}

int main()
{
	cin.tie(0) -> sync_with_stdio(false);
	cin >> n;
	Loop (i,0,n)
		cin >> h[i];
	Loop (i,0,n) {
		cin >> w[i];
		ps[i+1] = ps[i] + w[i];
	}
	vector<int> vec;
	Loop (i,0,n) {
		int lst = -1;
		while (vec.size() && h[vec.back()] > h[i]) {
			lst = vec.back();
			vec.pop_back();
		}
		lft[i] = lst;
		if (vec.size())
			rgt[vec.back()] = i;
		vec.push_back(i);
	}
	cout << solve(0, n, vec[0], 0) << '\n';
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 8 ms 3540 KB Output is correct
4 Correct 17 ms 8744 KB Output is correct
5 Correct 16 ms 6756 KB Output is correct
6 Correct 14 ms 5076 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 3 ms 1364 KB Output is correct
3 Correct 10 ms 5480 KB Output is correct
4 Correct 20 ms 10572 KB Output is correct
5 Correct 20 ms 10684 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 2 ms 1364 KB Output is correct
4 Correct 11 ms 5480 KB Output is correct
5 Correct 21 ms 10492 KB Output is correct
6 Correct 21 ms 10704 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 2 ms 1372 KB Output is correct
9 Correct 10 ms 5584 KB Output is correct
10 Correct 20 ms 10464 KB Output is correct
11 Correct 20 ms 10500 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 0 ms 332 KB Output is correct
# 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 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 324 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 8 ms 3584 KB Output is correct
12 Correct 17 ms 8728 KB Output is correct
13 Correct 16 ms 6692 KB Output is correct
14 Correct 15 ms 5132 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 3 ms 1372 KB Output is correct
17 Correct 11 ms 5484 KB Output is correct
18 Correct 20 ms 10484 KB Output is correct
19 Correct 20 ms 10608 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 3 ms 1400 KB Output is correct
22 Correct 15 ms 5672 KB Output is correct
23 Correct 20 ms 10412 KB Output is correct
24 Correct 20 ms 10476 KB Output is correct
25 Correct 0 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 344 KB Output is correct
30 Correct 2 ms 852 KB Output is correct
31 Correct 2 ms 860 KB Output is correct
32 Correct 9 ms 2736 KB Output is correct
33 Correct 10 ms 2772 KB Output is correct
34 Correct 19 ms 5164 KB Output is correct
35 Correct 18 ms 5152 KB Output is correct
36 Correct 19 ms 5324 KB Output is correct
37 Correct 19 ms 5288 KB Output is correct
38 Correct 0 ms 340 KB Output is correct
39 Correct 18 ms 5336 KB Output is correct
40 Correct 18 ms 5312 KB Output is correct
41 Correct 24 ms 6300 KB Output is correct
42 Correct 20 ms 10168 KB Output is correct