#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;
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 subtask5() {
int ans=0;
for (int i=0; i<n; i++) {
int mini=a[i].H;
int sum=a[i].W;
ans=MOD(ans+section(a[i].W, a[i].H)); //i=j
for (int j=i+1; j<n; j++) { //i!=j
mini=min(mini, a[j].H);
int res=section(mini, sum); // toute la section entre i et j
res-=MOD(section(mini, sum-a[i].W)+section(mini, sum-a[j].W)); // j'enlève tous les points qui ne commencent pas
res=MOD(res); // par j ou par i
res+=section(mini, sum-a[i].W-a[j].W); // je rajoute ce que j'ai enlevé de trop (a+b)^2
ans=MOD(ans+MOD(res));
}
}
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.clear();
a=temp;
n=a.size();
return subtask5();
}
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 |
348 KB |
Output is correct |
2 |
Correct |
10 ms |
344 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 |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
3 ms |
348 KB |
Output is correct |
3 |
Execution timed out |
1031 ms |
1760 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
2 ms |
604 KB |
Output is correct |
3 |
Correct |
8 ms |
1252 KB |
Output is correct |
4 |
Correct |
15 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 |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
2 ms |
604 KB |
Output is correct |
4 |
Correct |
8 ms |
1256 KB |
Output is correct |
5 |
Correct |
19 ms |
2040 KB |
Output is correct |
6 |
Correct |
15 ms |
2032 KB |
Output is correct |
7 |
Correct |
11 ms |
348 KB |
Output is correct |
8 |
Correct |
992 ms |
896 KB |
Output is correct |
9 |
Execution timed out |
1095 ms |
1756 KB |
Time limit exceeded |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
11 ms |
504 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 |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
3 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
10 ms |
344 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
3 ms |
484 KB |
Output is correct |
13 |
Correct |
11 ms |
348 KB |
Output is correct |
14 |
Correct |
11 ms |
348 KB |
Output is correct |
15 |
Correct |
11 ms |
504 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
10 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
11 ms |
508 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
3 ms |
348 KB |
Output is correct |
11 |
Execution timed out |
1084 ms |
2016 KB |
Time limit exceeded |
12 |
Halted |
0 ms |
0 KB |
- |