#include <bits/stdc++.h>
#define debug(x) cerr << #x << " " << x << "\n"
#define debugs(x) cerr << #x << " " << x << " "
using namespace std;
typedef long long ll;
typedef pair <ll, ll> pii;
typedef pair <long double, pii> muchie;
const ll NMAX = 100001;
const ll VMAX = 101;
const ll INF = (1LL << 60);
const ll MOD = 1000000007;
const ll BLOCK = 447;
const ll base = 117;
const ll nr_of_bits = 18;
const ll inv2 = 500000004;
pii stiva[NMAX];
ll vf;
ll scor = 0;
ll h[NMAX];
ll w[NMAX];
ll lgput(ll n, ll p){
ll rez = 1;
while(p){
if(p % 2){
rez = (1LL * rez * n) % MOD;
}
n = (1LL * n * n) % MOD;
p /= 2;
}
return rez;
}
ll gauss(ll x){
return 1LL * (1LL * x * (x + 1)) % MOD * inv2 % MOD;
}
ll cate(ll h, ll w){
return (1LL * gauss(h) * gauss(w)) % MOD;
}
ll combined(ll h, ll w1, ll w2){
return (1LL * (1LL * gauss(h) * w1) % MOD * w2) % MOD;
}
void add(ll &x, ll val){
x += val;
if(x >= MOD){
x -= MOD;
}
if(x < 0){
x += MOD;
}
}
unordered_map <int, ll> mp;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
ll n, i;
ll total = 0, scor = 0;
cin >> n;
for(i = 1; i <= n; i++) cin >> h[i];
for(i = 1; i <= n; i++) cin >> w[i];
for(i = 1; i <= n; i++){
add(total, cate(h[i], w[i]));
ll avem = w[i];
while(vf && stiva[vf].first >= h[i]){
add(total, combined(h[i], stiva[vf].second, w[i]));
add(scor, -(gauss(stiva[vf].first) * stiva[vf].second) % MOD);
add(avem, stiva[vf].second);
vf--;
}
add(total, (scor * w[i]) % MOD);
stiva[++vf] = {h[i], avem};
add(scor, (gauss(stiva[vf].first) * stiva[vf].second) % MOD);
}
cout << total;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
328 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
10 ms |
1612 KB |
Output is correct |
4 |
Correct |
18 ms |
3020 KB |
Output is correct |
5 |
Correct |
19 ms |
3040 KB |
Output is correct |
6 |
Correct |
20 ms |
2936 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
360 KB |
Output is correct |
2 |
Correct |
3 ms |
664 KB |
Output is correct |
3 |
Correct |
12 ms |
2016 KB |
Output is correct |
4 |
Correct |
22 ms |
2700 KB |
Output is correct |
5 |
Correct |
25 ms |
2764 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
3 ms |
596 KB |
Output is correct |
4 |
Correct |
12 ms |
2004 KB |
Output is correct |
5 |
Correct |
22 ms |
2696 KB |
Output is correct |
6 |
Correct |
24 ms |
2760 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
4 ms |
724 KB |
Output is correct |
9 |
Correct |
13 ms |
2260 KB |
Output is correct |
10 |
Correct |
21 ms |
4328 KB |
Output is correct |
11 |
Correct |
23 ms |
5244 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
328 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
336 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
344 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
10 ms |
1620 KB |
Output is correct |
12 |
Correct |
18 ms |
3028 KB |
Output is correct |
13 |
Correct |
19 ms |
3008 KB |
Output is correct |
14 |
Correct |
19 ms |
2972 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
3 ms |
584 KB |
Output is correct |
17 |
Correct |
12 ms |
1984 KB |
Output is correct |
18 |
Correct |
25 ms |
3956 KB |
Output is correct |
19 |
Correct |
25 ms |
3920 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
3 ms |
756 KB |
Output is correct |
22 |
Correct |
13 ms |
2396 KB |
Output is correct |
23 |
Correct |
22 ms |
5240 KB |
Output is correct |
24 |
Correct |
22 ms |
5352 KB |
Output is correct |
25 |
Correct |
0 ms |
340 KB |
Output is correct |
26 |
Correct |
0 ms |
340 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
1 ms |
340 KB |
Output is correct |
29 |
Correct |
1 ms |
340 KB |
Output is correct |
30 |
Correct |
3 ms |
596 KB |
Output is correct |
31 |
Correct |
3 ms |
584 KB |
Output is correct |
32 |
Correct |
12 ms |
1876 KB |
Output is correct |
33 |
Correct |
12 ms |
2072 KB |
Output is correct |
34 |
Correct |
23 ms |
3632 KB |
Output is correct |
35 |
Correct |
23 ms |
3532 KB |
Output is correct |
36 |
Correct |
24 ms |
3732 KB |
Output is correct |
37 |
Correct |
25 ms |
3720 KB |
Output is correct |
38 |
Correct |
0 ms |
340 KB |
Output is correct |
39 |
Correct |
23 ms |
3788 KB |
Output is correct |
40 |
Correct |
23 ms |
3752 KB |
Output is correct |
41 |
Correct |
24 ms |
4036 KB |
Output is correct |
42 |
Correct |
23 ms |
4564 KB |
Output is correct |