// **y ***** Khoroo
#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:60:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
60 | scanf("%lld",&n);
| ~~~~~^~~~~~~~~~~
fancyfence.cpp:63:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
63 | scanf("%lld",&h[i]);
| ~~~~~^~~~~~~~~~~~~~
fancyfence.cpp:67:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
67 | scanf("%lld",&w[i]);
| ~~~~~^~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
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 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
22 ms |
8972 KB |
Output is correct |
4 |
Correct |
45 ms |
13140 KB |
Output is correct |
5 |
Correct |
49 ms |
11600 KB |
Output is correct |
6 |
Correct |
46 ms |
9808 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4440 KB |
Output is correct |
2 |
Correct |
5 ms |
7512 KB |
Output is correct |
3 |
Correct |
23 ms |
10576 KB |
Output is correct |
4 |
Correct |
46 ms |
14708 KB |
Output is correct |
5 |
Correct |
51 ms |
14900 KB |
Output is correct |
6 |
Correct |
1 ms |
4440 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
5 ms |
7380 KB |
Output is correct |
4 |
Correct |
24 ms |
10808 KB |
Output is correct |
5 |
Correct |
46 ms |
14780 KB |
Output is correct |
6 |
Correct |
45 ms |
14932 KB |
Output is correct |
7 |
Correct |
1 ms |
4440 KB |
Output is correct |
8 |
Correct |
5 ms |
7516 KB |
Output is correct |
9 |
Correct |
24 ms |
10576 KB |
Output is correct |
10 |
Correct |
45 ms |
14676 KB |
Output is correct |
11 |
Correct |
46 ms |
14632 KB |
Output is correct |
12 |
Correct |
1 ms |
4444 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
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 |
4544 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 |
# |
결과 |
실행 시간 |
메모리 |
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 |
4484 KB |
Output is correct |
5 |
Correct |
1 ms |
4444 KB |
Output is correct |
6 |
Correct |
1 ms |
4548 KB |
Output is correct |
7 |
Correct |
1 ms |
4444 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 |
22 ms |
8788 KB |
Output is correct |
12 |
Correct |
44 ms |
13136 KB |
Output is correct |
13 |
Correct |
44 ms |
11048 KB |
Output is correct |
14 |
Correct |
48 ms |
9692 KB |
Output is correct |
15 |
Correct |
1 ms |
4440 KB |
Output is correct |
16 |
Correct |
5 ms |
7512 KB |
Output is correct |
17 |
Correct |
25 ms |
10580 KB |
Output is correct |
18 |
Correct |
46 ms |
14928 KB |
Output is correct |
19 |
Correct |
46 ms |
14856 KB |
Output is correct |
20 |
Correct |
1 ms |
4444 KB |
Output is correct |
21 |
Correct |
5 ms |
7516 KB |
Output is correct |
22 |
Correct |
27 ms |
10664 KB |
Output is correct |
23 |
Correct |
45 ms |
14576 KB |
Output is correct |
24 |
Correct |
47 ms |
14700 KB |
Output is correct |
25 |
Correct |
1 ms |
4444 KB |
Output is correct |
26 |
Correct |
1 ms |
4444 KB |
Output is correct |
27 |
Correct |
2 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 |
5 ms |
7256 KB |
Output is correct |
31 |
Correct |
5 ms |
7004 KB |
Output is correct |
32 |
Correct |
24 ms |
8284 KB |
Output is correct |
33 |
Correct |
25 ms |
8452 KB |
Output is correct |
34 |
Correct |
46 ms |
9776 KB |
Output is correct |
35 |
Correct |
46 ms |
10012 KB |
Output is correct |
36 |
Correct |
47 ms |
10076 KB |
Output is correct |
37 |
Correct |
50 ms |
10076 KB |
Output is correct |
38 |
Correct |
1 ms |
4440 KB |
Output is correct |
39 |
Correct |
49 ms |
10072 KB |
Output is correct |
40 |
Correct |
51 ms |
10072 KB |
Output is correct |
41 |
Correct |
54 ms |
11092 KB |
Output is correct |
42 |
Correct |
45 ms |
14672 KB |
Output is correct |