답안 #697054

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
697054 2023-02-08T04:07:28 Z vjudge1 Fancy Fence (CEOI20_fancyfence) C++17
100 / 100
65 ms 6856 KB
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define fi first
#define se second
#define pii pair<int, int>
#define pll pair<ll, ll>
const int mod=1e9+7, maxn=1e6+5;
ll n, h[maxn], lebar[maxn], par[maxn], sz[maxn], kiri, kanan, w, t, ans, last, v[maxn];
bool vis[maxn];

int find(int x) {
	if(par[x]==x) return x;
	return par[x]=find(par[x]);
}

void join(int u, int v) {
	int ou=find(u), ov=find(v);
	if(ou!=ov) {
		par[ou]=ov;
		sz[ov]+=sz[ou];
		lebar[ov]+=lebar[ou];
	}
}

ll p(ll a, ll b) {
	ll res=1;
	while(b) {
		if(b%2) res=(res*a)%mod;
		a=(a*a)%mod;
		b/=2;
	}
	return res;
}

ll deret(ll a, ll b) {
	ll n=(b-a+1)%mod;
	return (((n*((a+b)%mod))%mod)*p(2, mod-2))%mod;
}

int main() {
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	cin >> n;
	for(int i=1; i<=n; i++) {
		cin >> h[i];
		v[i]=par[i]=i;
		sz[i]=1;
	}
	for(int i=1; i<=n; i++) cin >> lebar[i];
	sort(v+1, v+n+1, [](auto ki, auto ka) {
		return h[ki]>h[ka];
	});
	last=1;
	for(int i=1; i<=n; i++) {
		if(i==n||h[v[i]]>h[v[i+1]]) {
			for(int j=last; j<=i; j++) {
				if(h[v[j]]<=h[v[j]-1]) join(v[j], v[j]-1);
				if(h[v[j]]<=h[v[j]+1]) join(v[j]+1, v[j]);
			}
			for(int j=last; j<=i; j++) {
				kiri=find(v[j]);
				if(vis[kiri]) continue;
				kanan=kiri+sz[kiri]-1, w=lebar[kiri], t=h[v[j]];
				// cout << v[j] << ' ' << t << ' ' << w << '\n';
				ans=(((deret(max(h[kiri-1], h[kanan+1])+1, t)*deret(1, w))%mod)+ans)%mod;
				vis[kiri]=true;
			}
			for(int j=last; j<=i; j++) vis[find(v[j])]=false;
			last=i+1;
		}
	}
	cout << ans << '\n';
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 408 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 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 0 ms 328 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 18 ms 2904 KB Output is correct
4 Correct 27 ms 5508 KB Output is correct
5 Correct 32 ms 5580 KB Output is correct
6 Correct 23 ms 5428 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 3 ms 852 KB Output is correct
3 Correct 13 ms 3308 KB Output is correct
4 Correct 26 ms 6224 KB Output is correct
5 Correct 27 ms 6224 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 3 ms 852 KB Output is correct
4 Correct 15 ms 3192 KB Output is correct
5 Correct 26 ms 6200 KB Output is correct
6 Correct 27 ms 6304 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 5 ms 852 KB Output is correct
9 Correct 19 ms 3256 KB Output is correct
10 Correct 49 ms 6172 KB Output is correct
11 Correct 51 ms 6212 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 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
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 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 408 KB Output is correct
14 Correct 1 ms 536 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 408 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 15 ms 2840 KB Output is correct
12 Correct 27 ms 5524 KB Output is correct
13 Correct 29 ms 5460 KB Output is correct
14 Correct 23 ms 5472 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 3 ms 852 KB Output is correct
17 Correct 13 ms 3280 KB Output is correct
18 Correct 26 ms 6220 KB Output is correct
19 Correct 32 ms 6304 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 6 ms 884 KB Output is correct
22 Correct 19 ms 3284 KB Output is correct
23 Correct 50 ms 6144 KB Output is correct
24 Correct 50 ms 6284 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 408 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 7 ms 852 KB Output is correct
31 Correct 6 ms 888 KB Output is correct
32 Correct 28 ms 3156 KB Output is correct
33 Correct 36 ms 3300 KB Output is correct
34 Correct 61 ms 6112 KB Output is correct
35 Correct 56 ms 6000 KB Output is correct
36 Correct 62 ms 6288 KB Output is correct
37 Correct 65 ms 6308 KB Output is correct
38 Correct 0 ms 340 KB Output is correct
39 Correct 63 ms 6312 KB Output is correct
40 Correct 55 ms 6300 KB Output is correct
41 Correct 56 ms 6328 KB Output is correct
42 Correct 58 ms 6856 KB Output is correct