Submission #970644

# Submission time Handle Problem Language Result Execution time Memory
970644 2024-04-27T02:04:44 Z biximo Fancy Fence (CEOI20_fancyfence) C++17
100 / 100
36 ms 7512 KB
#include <bits/stdc++.h>
#define N 200005
using namespace std;
typedef long long ll;
ll wth[N], hgt[N], ans;
int p[N];
const int MOD = 1e9+7, DIV = (1e9+8)/4;
int get(int a) {
	if(p[a] != a) p[a]=get(p[a]);
	return p[a];
}
void join(int a, int b) {
	a = get(a); b = get(b);
	if(a == b) return;
	if(hgt[a] < hgt[b]) swap(a,b);
	ans += (1+wth[a])*(wth[a])%MOD*(hgt[a]+hgt[b]+1)%MOD*(hgt[a]-hgt[b])%MOD*DIV%MOD;
	ans %= MOD;
	wth[a] += wth[b];
	wth[a] %= MOD;
	hgt[a] = hgt[b];
	p[b] = a;
}
int H[N], W[N], order[N], n;
bool comp(int a, int b) {
	if(H[a] == H[b]) {
		return a > b;
	}
	return H[a] > H[b];
}
int main() {
    cin.tie(0)->sync_with_stdio(0);
    cin >> n;
    for(int i = 1; i <= n; i ++) {
    	cin >> H[i];
    }
    for(int i = 1; i <= n; i ++) {
    	cin >> W[i];
    	wth[i] = W[i];
    	hgt[i] = H[i];
    	order[i] = i;
    	p[i] = i;
    }
    sort(order+1, order+1+n,comp);
    for(int j = 1; j <= n; j ++) {
    	int i = order[j];
    	if(i-1>=1 && H[i-1] >= H[i]) {
    		join(i,i-1);
    	}
    	if(i+1<=n && H[i+1] >= H[i]) {
    		join(i,i+1);
    	}
    }
    join(0,1);
    if(ans < 0) ans += MOD;
    cout << ans;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 1 ms 4440 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4568 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 2 ms 4444 KB Output is correct
3 Correct 12 ms 5704 KB Output is correct
4 Correct 22 ms 6488 KB Output is correct
5 Correct 33 ms 6492 KB Output is correct
6 Correct 20 ms 6492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 3 ms 4444 KB Output is correct
3 Correct 11 ms 5076 KB Output is correct
4 Correct 21 ms 5468 KB Output is correct
5 Correct 26 ms 5468 KB Output is correct
6 Correct 1 ms 4440 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 3 ms 4444 KB Output is correct
4 Correct 11 ms 4956 KB Output is correct
5 Correct 21 ms 5468 KB Output is correct
6 Correct 21 ms 5536 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 3 ms 4700 KB Output is correct
9 Correct 11 ms 5980 KB Output is correct
10 Correct 20 ms 7260 KB Output is correct
11 Correct 20 ms 7288 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4440 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 2 ms 4444 KB Output is correct
13 Correct 1 ms 4440 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 1 ms 4444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4440 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 12 ms 5724 KB Output is correct
12 Correct 22 ms 6492 KB Output is correct
13 Correct 33 ms 6676 KB Output is correct
14 Correct 20 ms 6488 KB Output is correct
15 Correct 1 ms 4440 KB Output is correct
16 Correct 4 ms 4700 KB Output is correct
17 Correct 12 ms 6100 KB Output is correct
18 Correct 24 ms 7260 KB Output is correct
19 Correct 21 ms 7512 KB Output is correct
20 Correct 1 ms 4572 KB Output is correct
21 Correct 3 ms 4700 KB Output is correct
22 Correct 11 ms 5980 KB Output is correct
23 Correct 19 ms 7260 KB Output is correct
24 Correct 21 ms 7256 KB Output is correct
25 Correct 1 ms 4440 KB Output is correct
26 Correct 1 ms 4444 KB Output is correct
27 Correct 1 ms 4444 KB Output is correct
28 Correct 1 ms 4444 KB Output is correct
29 Correct 1 ms 4444 KB Output is correct
30 Correct 4 ms 4700 KB Output is correct
31 Correct 4 ms 4888 KB Output is correct
32 Correct 17 ms 6344 KB Output is correct
33 Correct 15 ms 5980 KB Output is correct
34 Correct 28 ms 7140 KB Output is correct
35 Correct 30 ms 7256 KB Output is correct
36 Correct 36 ms 7248 KB Output is correct
37 Correct 30 ms 7272 KB Output is correct
38 Correct 1 ms 4444 KB Output is correct
39 Correct 30 ms 7256 KB Output is correct
40 Correct 26 ms 7256 KB Output is correct
41 Correct 24 ms 7252 KB Output is correct
42 Correct 21 ms 7260 KB Output is correct