#include <bits/stdc++.h>
#define MEM 111111
#define sanic ios_base::sync_with_stdio(0)
#define x first
#define y second
#define pf push_front
#define pb push_back
#define all(v) v.begin(), v.end()
#define sz size()
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pi;
const ll INF = 1e13+7;
const ll MOD = 1e9+7;
ll gcd(ll a, ll b){
if(a%b) return gcd(b, a%b);
return b;
}
ll c2(ll n){
ll ret = n*(n-1)/2LL;
ret %= MOD;
ret += MOD;
ret %= MOD;
return ret;
}
ll hp(ll l, ll r){
ll a=c2(l+1);
ll b=c2(r+1);
return ((b-a)%MOD+MOD)%MOD;
}
ll n,m,t,c;
ll h[MEM], w[MEM];
signed main(){
//sanic; cin.tie(0); cout.tie(0);
cin >> n;
for(int i=0; i<n; i++)
cin >> h[i];
for(int i=0; i<n; i++)
cin >> w[i];
stack<pi> s;
ll ans=0;
for(int i=0; i<n; i++)
s.push({h[i], w[i]});
while(!s.empty()){
ll h1=s.top().x, w1=s.top().y;
s.pop();
ans = (ans+(hp((s.empty()?0:s.top().x), h1)*c2(w1+1))%MOD+MOD)%MOD;
//cout << h1 << ' ' << w1 << '\n';
if(s.empty()) break;
pi ff=s.top();
s.pop();
ff.y += w1;
ff.y %= MOD;
ff.y += MOD;
ff.y %= MOD;
s.push(ff);
}
cout << ans;
}
/*
10
1 3 2 4 2 1 3 5 6 7
2 3 5 4 6 2 3 5 6 7
3
2 3 1
3 1 2
660
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
11 ms |
816 KB |
Output is correct |
3 |
Correct |
40 ms |
2808 KB |
Output is correct |
4 |
Correct |
109 ms |
5448 KB |
Output is correct |
5 |
Correct |
91 ms |
5416 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
8 ms |
764 KB |
Output is correct |
4 |
Correct |
41 ms |
2824 KB |
Output is correct |
5 |
Correct |
89 ms |
5388 KB |
Output is correct |
6 |
Correct |
84 ms |
5484 KB |
Output is correct |
7 |
Correct |
2 ms |
340 KB |
Output is correct |
8 |
Correct |
9 ms |
764 KB |
Output is correct |
9 |
Correct |
43 ms |
2872 KB |
Output is correct |
10 |
Correct |
73 ms |
5276 KB |
Output is correct |
11 |
Correct |
82 ms |
5324 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |