#include<bits/stdc++.h>
using namespace std;
#define X first
#define Y second
#define pb push_back
#define int long long
const int MAX=1e5+3,mod=1e9+7;
int dp[MAX];
void maxx(int &a,int b){if(b>a) a=b;}
void minn(int &a,int b){if(b<a) a=b;}
void PL(int &a,int b){a+=b;if(a>=mod) a-=mod;}
int b[MAX];
int a[MAX];
int D[MAX];
int gs(int x){
return (x*(x+1)/2)%mod;
}
signed main(){
ios::sync_with_stdio(0);cin.tie(0);
int n;
cin>>n;
for(int i=1;i<=n;i++){
cin>>a[i];
}
int ans=0;
int top=0;
for(int i=1,x;i<=n;i++){
cin>>x;
b[i]=(b[i-1]+x)%mod;
while(a[i]<a[D[top]]) top--;
int u=D[top];
dp[i]=( gs(a[i])*(b[i]-b[u])+dp[u] )%mod;
(ans+=dp[u]*x+gs(a[i])*(gs(x)+x*(b[i-1]-b[u])%mod) )%=mod;
D[++top]=i;
}
PL(ans,mod);
cout<<ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
0 ms |
336 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
11 ms |
1612 KB |
Output is correct |
4 |
Correct |
20 ms |
3184 KB |
Output is correct |
5 |
Correct |
22 ms |
2856 KB |
Output is correct |
6 |
Correct |
20 ms |
2636 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
3 ms |
588 KB |
Output is correct |
3 |
Correct |
13 ms |
1892 KB |
Output is correct |
4 |
Correct |
30 ms |
3440 KB |
Output is correct |
5 |
Correct |
28 ms |
3328 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
3 ms |
588 KB |
Output is correct |
4 |
Correct |
13 ms |
1824 KB |
Output is correct |
5 |
Correct |
25 ms |
3352 KB |
Output is correct |
6 |
Correct |
27 ms |
3368 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
3 ms |
588 KB |
Output is correct |
9 |
Correct |
14 ms |
1864 KB |
Output is correct |
10 |
Correct |
24 ms |
3384 KB |
Output is correct |
11 |
Correct |
25 ms |
3348 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
380 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
10 ms |
1612 KB |
Output is correct |
12 |
Correct |
20 ms |
3228 KB |
Output is correct |
13 |
Correct |
21 ms |
2896 KB |
Output is correct |
14 |
Correct |
20 ms |
2684 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
3 ms |
588 KB |
Output is correct |
17 |
Correct |
14 ms |
1868 KB |
Output is correct |
18 |
Correct |
26 ms |
3396 KB |
Output is correct |
19 |
Correct |
30 ms |
5392 KB |
Output is correct |
20 |
Correct |
1 ms |
332 KB |
Output is correct |
21 |
Correct |
4 ms |
844 KB |
Output is correct |
22 |
Correct |
14 ms |
2840 KB |
Output is correct |
23 |
Correct |
25 ms |
5188 KB |
Output is correct |
24 |
Correct |
26 ms |
5264 KB |
Output is correct |
25 |
Correct |
1 ms |
332 KB |
Output is correct |
26 |
Correct |
1 ms |
332 KB |
Output is correct |
27 |
Correct |
1 ms |
332 KB |
Output is correct |
28 |
Correct |
1 ms |
332 KB |
Output is correct |
29 |
Correct |
1 ms |
332 KB |
Output is correct |
30 |
Correct |
3 ms |
752 KB |
Output is correct |
31 |
Correct |
4 ms |
752 KB |
Output is correct |
32 |
Correct |
14 ms |
2376 KB |
Output is correct |
33 |
Correct |
14 ms |
2372 KB |
Output is correct |
34 |
Correct |
27 ms |
4380 KB |
Output is correct |
35 |
Correct |
26 ms |
4292 KB |
Output is correct |
36 |
Correct |
27 ms |
4548 KB |
Output is correct |
37 |
Correct |
27 ms |
4580 KB |
Output is correct |
38 |
Correct |
1 ms |
332 KB |
Output is correct |
39 |
Correct |
26 ms |
4548 KB |
Output is correct |
40 |
Correct |
29 ms |
4572 KB |
Output is correct |
41 |
Correct |
26 ms |
4676 KB |
Output is correct |
42 |
Correct |
26 ms |
4892 KB |
Output is correct |