Submission #936679

# Submission time Handle Problem Language Result Execution time Memory
936679 2024-03-02T13:56:30 Z Batorgil952 Fancy Fence (CEOI20_fancyfence) C++14
100 / 100
71 ms 14748 KB
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair

using namespace std;

const ll N=1e5+5, mod=1e9+7;
ll h[N], w[N], tree[4*N], urt[4*N];
ll n;

void build(ll v, ll l, ll r){
	if(l==r) tree[v]=l, urt[v]=w[l];
	else{
		ll mid=(l+r)/2;
		build(2*v, l, mid);
		build(2*v+1, mid+1, r);
		if(h[tree[2*v]]<=h[tree[2*v+1]]){
			tree[v]=tree[2*v];
		}
		else{
			tree[v]=tree[2*v+1];
		}
		urt[v]=urt[2*v]+urt[2*v+1];
	}
}

ll query1(ll v, ll l, ll r, ll ql, ll qr){
	if(qr<l || r<ql) return -1;
	if(ql<=l && r<=qr) return tree[v];
	ll mid=(l+r)/2;
	ll x=query1(2*v, l, mid, ql, qr);
	ll y=query1(2*v+1, mid+1, r, ql, qr);
	if(x==-1) return y;
	if(y==-1) return x;
	if(h[x]<=h[y]) return x;
	return y;
 }

ll query2(ll v, ll l, ll r, ll ql, ll qr){
	if(qr<l || r<ql) return 0;
	if(ql<=l && r<=qr) return urt[v];
	ll mid=(l+r)/2;
	return query2(2*v, l, mid, ql, qr)+query2(2*v+1, mid+1, r, ql, qr);
}

ll Fun(ll l, ll r, ll tuvshin){
	if(l>r) return 0;
	ll p=query1(1, 1, n, l, r);
	ll q=query2(1, 1, n, l, r);
	ll a=h[p]-tuvshin;
	ll b=tuvshin;
	return ((((((q%mod)*((q+1)%mod))%mod)*500000004)%mod)*((((((2*b+a+1)%mod)*a)%mod)*500000004)%mod)%mod+Fun(l, p-1, h[p])+Fun(p+1, r, h[p]))%mod;
}

int main(){
	ll i;
	
	scanf("%lld",&n);
	
	for(i=1; i<=n; i++){
		scanf("%lld",&h[i]);
	}
	
	for(i=1; i<=n; i++){
		scanf("%lld",&w[i]);
	}
	
	build(1, 1, n);
	
	printf("%lld\n", Fun(1, n, 0));
	
	return 0;
}

Compilation message

fancyfence.cpp: In function 'int main()':
fancyfence.cpp:59:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   59 |  scanf("%lld",&n);
      |  ~~~~~^~~~~~~~~~~
fancyfence.cpp:62:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   62 |   scanf("%lld",&h[i]);
      |   ~~~~~^~~~~~~~~~~~~~
fancyfence.cpp:66:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   66 |   scanf("%lld",&w[i]);
      |   ~~~~~^~~~~~~~~~~~~~
# 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 4544 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 2 ms 4440 KB Output is correct
4 Correct 1 ms 4444 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 1 ms 4444 KB Output is correct
3 Correct 24 ms 8852 KB Output is correct
4 Correct 44 ms 13140 KB Output is correct
5 Correct 43 ms 11084 KB Output is correct
6 Correct 46 ms 9808 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4568 KB Output is correct
2 Correct 6 ms 7516 KB Output is correct
3 Correct 23 ms 10588 KB Output is correct
4 Correct 48 ms 14572 KB Output is correct
5 Correct 46 ms 14508 KB Output is correct
6 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 6 ms 7516 KB Output is correct
4 Correct 23 ms 10616 KB Output is correct
5 Correct 48 ms 14564 KB Output is correct
6 Correct 47 ms 14676 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 5 ms 7516 KB Output is correct
9 Correct 24 ms 10580 KB Output is correct
10 Correct 52 ms 14520 KB Output is correct
11 Correct 46 ms 14672 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 4524 KB Output is correct
4 Correct 2 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 4536 KB Output is correct
8 Correct 1 ms 4444 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 1 ms 4444 KB Output is correct
13 Correct 1 ms 4444 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 4572 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4696 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 0 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 22 ms 8892 KB Output is correct
12 Correct 43 ms 13136 KB Output is correct
13 Correct 44 ms 11092 KB Output is correct
14 Correct 53 ms 9808 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 5 ms 7296 KB Output is correct
17 Correct 27 ms 10616 KB Output is correct
18 Correct 51 ms 14748 KB Output is correct
19 Correct 48 ms 14676 KB Output is correct
20 Correct 1 ms 4444 KB Output is correct
21 Correct 5 ms 7340 KB Output is correct
22 Correct 24 ms 10624 KB Output is correct
23 Correct 46 ms 14504 KB Output is correct
24 Correct 71 ms 14688 KB Output is correct
25 Correct 1 ms 4444 KB Output is correct
26 Correct 1 ms 4444 KB Output is correct
27 Correct 1 ms 4444 KB Output is correct
28 Correct 2 ms 4444 KB Output is correct
29 Correct 1 ms 4444 KB Output is correct
30 Correct 8 ms 7000 KB Output is correct
31 Correct 6 ms 7004 KB Output is correct
32 Correct 24 ms 8228 KB Output is correct
33 Correct 24 ms 8280 KB Output is correct
34 Correct 48 ms 9772 KB Output is correct
35 Correct 57 ms 9856 KB Output is correct
36 Correct 47 ms 10044 KB Output is correct
37 Correct 50 ms 10024 KB Output is correct
38 Correct 1 ms 4444 KB Output is correct
39 Correct 48 ms 9988 KB Output is correct
40 Correct 51 ms 9848 KB Output is correct
41 Correct 53 ms 10844 KB Output is correct
42 Correct 46 ms 14680 KB Output is correct