#include <bits/stdc++.h>
#define int long long
#define sz(x) (int)(x.size())
using namespace std;
const int mod=1000000007;
int MOD(int x) {
return (x+3*mod)%mod;
}
struct sections {
int H=0, W=0;
};
int n, k, m;
vector<sections> a;
int section(int h, int w) {
h%=mod, w%=mod;
int facteur=MOD((h*(h+1))/2);
int ans=MOD((w*(w+1))/2);
return MOD(ans*facteur);
}
int full() {
int ans=0;
vector<int> l(n, 0);
vector<int> r(n, 0);
vector<int> prefix(n, 0);
stack<pair<int, int>> stk;
for (int i=0; i<n; i++) {
while (!stk.empty() && stk.top().first >= a[i].H) stk.pop();
if (!stk.empty()) l[i]=stk.top().second+1; // Je supprime une fois de torp -> Je dois faire -1
else l[i]=0; // Tout est parti -> je prends depuis le début
stk.push({a[i].H, i});
if (i) prefix[i]=prefix[i-1]; // PREFIX SUM
prefix[i]= MOD(prefix[i]+a[i].W);
}
while (!stk.empty()) stk.pop();
for (int i=n-1; i>=0; i--) {
while (!stk.empty() && stk.top().first > a[i].H) stk.pop();
if (!stk.empty()) r[i]=stk.top().second-1; //Je retire une fois de trop -> Donc je dois faire -1
else r[i]=n-1; // Tout est parti -> je prends depuis la fin
stk.push({a[i].H, i});
}
for (int i=0; i<n; i++) {
int suml=0, sumr=0;
if (i>0) suml=MOD(prefix[i-1]-(l[i]>0?prefix[l[i]-1]:0)); // SOMME DROITE
if (r[i]>=0) sumr=MOD(prefix[r[i]]-prefix[i]); // SOMME GAUCHE
int sumw=suml+sumr+a[i].W; // Largeure totale du rectangle
int sum=MOD(section(a[i].H, sumw)-section(a[i].H, suml)-section(a[i].H, sumr)); //Si je prends tout - je prends pas 2 fois gauche/droite
ans=MOD(ans+sum);
}
return ans;
}
int solve() {
cin >> n;
a.clear();
a.resize(n);
for (auto &u: a) cin >> u.H;
for (auto &u: a) cin >> u.W;
vector<sections> temp;
for (int i=0; i<n; i++) {
if (!temp.empty() && a[i].H==temp.back().H) temp.back().W+=a[i].W;
else temp.push_back(a[i]);
a[i].W%=mod;
}
a.clear();
a=temp;
n=a.size();
return full();
}
signed main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout << solve() << endl;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
8 ms |
2180 KB |
Output is correct |
4 |
Correct |
15 ms |
3548 KB |
Output is correct |
5 |
Correct |
16 ms |
4312 KB |
Output is correct |
6 |
Correct |
14 ms |
2780 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
2 ms |
604 KB |
Output is correct |
3 |
Correct |
8 ms |
1004 KB |
Output is correct |
4 |
Correct |
17 ms |
1884 KB |
Output is correct |
5 |
Correct |
16 ms |
1884 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
2 ms |
604 KB |
Output is correct |
4 |
Correct |
8 ms |
1252 KB |
Output is correct |
5 |
Correct |
16 ms |
1884 KB |
Output is correct |
6 |
Correct |
16 ms |
2028 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
3 ms |
992 KB |
Output is correct |
9 |
Correct |
10 ms |
2264 KB |
Output is correct |
10 |
Correct |
23 ms |
7380 KB |
Output is correct |
11 |
Correct |
25 ms |
7628 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
596 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
500 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
544 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
8 ms |
2268 KB |
Output is correct |
12 |
Correct |
14 ms |
3548 KB |
Output is correct |
13 |
Correct |
17 ms |
4208 KB |
Output is correct |
14 |
Correct |
14 ms |
2676 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
3 ms |
604 KB |
Output is correct |
17 |
Correct |
9 ms |
1252 KB |
Output is correct |
18 |
Correct |
16 ms |
1880 KB |
Output is correct |
19 |
Correct |
16 ms |
1884 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
3 ms |
992 KB |
Output is correct |
22 |
Correct |
10 ms |
2268 KB |
Output is correct |
23 |
Correct |
23 ms |
7524 KB |
Output is correct |
24 |
Correct |
22 ms |
7632 KB |
Output is correct |
25 |
Correct |
0 ms |
348 KB |
Output is correct |
26 |
Correct |
1 ms |
348 KB |
Output is correct |
27 |
Correct |
1 ms |
348 KB |
Output is correct |
28 |
Correct |
1 ms |
348 KB |
Output is correct |
29 |
Correct |
1 ms |
348 KB |
Output is correct |
30 |
Correct |
4 ms |
992 KB |
Output is correct |
31 |
Correct |
3 ms |
992 KB |
Output is correct |
32 |
Correct |
11 ms |
3164 KB |
Output is correct |
33 |
Correct |
12 ms |
3216 KB |
Output is correct |
34 |
Correct |
22 ms |
5948 KB |
Output is correct |
35 |
Correct |
22 ms |
5832 KB |
Output is correct |
36 |
Correct |
23 ms |
5844 KB |
Output is correct |
37 |
Correct |
23 ms |
5844 KB |
Output is correct |
38 |
Correct |
0 ms |
348 KB |
Output is correct |
39 |
Correct |
22 ms |
5844 KB |
Output is correct |
40 |
Correct |
26 ms |
5844 KB |
Output is correct |
41 |
Correct |
23 ms |
6096 KB |
Output is correct |
42 |
Correct |
22 ms |
6764 KB |
Output is correct |