#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N = 1e5 + 10;
int r[N][3];
int w[N];
int h[N];
int pre[N];
int ans = 0;
int mod = 1e9 + 7;
int power(int a,int b){
if (b==0)
return 1;
int ans = power(a,b/2);
ans = ans*ans;
ans %= mod;
if (b%2)
ans = ans*a;
return ans%mod;
}
int mod_inv(int k){
return power(k,mod-2);
}
int asd(int a){
int ans = (a*(a+1));
ans = ans%mod;
ans = ans*mod_inv(2);
ans = ans% mod;
return ans;
}
int answer(int W,int H){
int ans = asd(W);
int ans2 = asd(H);
return (ans*ans2)%mod ;
}
int MIN(int l,int r){
int ind = l;
for (int i=l;i<=r;i++)
if (h[i]<h[ind])
ind = i;
return ind;
}
void solve(int l,int r,int height){
if (r<l or l>r)
return;
int ind = MIN(l,r);
int width = pre[r]-pre[l-1];
if (width<0)
width += mod;
ans -= answer(width,height);
if (ans<0)
ans += mod;
ans += answer(width,h[ind]);
ans %= mod;
solve(l,ind-1,h[ind]);
solve(ind+1,r,h[ind]);
}
signed main(){
int n;
cin>>n;
for (int i=1;i<=n;i++)
cin>>h[i];
for (int i=1;i<=n;i++){
cin>>w[i];
pre[i] = pre[i-1] + w[i];
pre[i] %= mod;
}
solve(1LL,n,0LL);
cout<<ans<<endl;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
3 ms |
2392 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2392 KB |
Output is correct |
3 |
Correct |
1 ms |
2392 KB |
Output is correct |
4 |
Correct |
1 ms |
2392 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
2 ms |
2396 KB |
Output is correct |
3 |
Correct |
431 ms |
3236 KB |
Output is correct |
4 |
Execution timed out |
1035 ms |
5708 KB |
Time limit exceeded |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
2392 KB |
Output is correct |
2 |
Correct |
53 ms |
2392 KB |
Output is correct |
3 |
Correct |
906 ms |
2644 KB |
Output is correct |
4 |
Execution timed out |
1042 ms |
4688 KB |
Time limit exceeded |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
3 ms |
2396 KB |
Output is correct |
3 |
Correct |
53 ms |
2392 KB |
Output is correct |
4 |
Correct |
994 ms |
2644 KB |
Output is correct |
5 |
Execution timed out |
1045 ms |
4692 KB |
Time limit exceeded |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2592 KB |
Output is correct |
2 |
Correct |
2 ms |
2392 KB |
Output is correct |
3 |
Correct |
1 ms |
2392 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2392 KB |
Output is correct |
6 |
Correct |
1 ms |
2392 KB |
Output is correct |
7 |
Correct |
1 ms |
2392 KB |
Output is correct |
8 |
Correct |
3 ms |
2396 KB |
Output is correct |
9 |
Correct |
3 ms |
2648 KB |
Output is correct |
10 |
Correct |
3 ms |
2392 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
2 ms |
2392 KB |
Output is correct |
13 |
Correct |
3 ms |
2392 KB |
Output is correct |
14 |
Correct |
3 ms |
2392 KB |
Output is correct |
15 |
Correct |
2 ms |
2396 KB |
Output is correct |
16 |
Correct |
1 ms |
2396 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
3 ms |
2392 KB |
Output is correct |
3 |
Correct |
1 ms |
2392 KB |
Output is correct |
4 |
Correct |
3 ms |
2392 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2392 KB |
Output is correct |
7 |
Correct |
1 ms |
2392 KB |
Output is correct |
8 |
Correct |
1 ms |
2392 KB |
Output is correct |
9 |
Correct |
1 ms |
2392 KB |
Output is correct |
10 |
Correct |
3 ms |
2392 KB |
Output is correct |
11 |
Correct |
419 ms |
3232 KB |
Output is correct |
12 |
Execution timed out |
1020 ms |
5840 KB |
Time limit exceeded |
13 |
Halted |
0 ms |
0 KB |
- |