#include <iostream>
#include <vector>
using namespace std;
const long long mod=1e9+7;
const int stala=1e5+10;
long long wysokosci[stala];
long long szerokosci[stala];
vector<long long>h;
vector<long long>w;
vector<long long>war;
long long odejmij(long long a)
{
if(a<0)
{
return a+mod;
}
else
{
return a;
}
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int ile;
cin>>ile;
for(int i=1;i<=ile;i++)
{
cin>>wysokosci[i];
}
for(int i=1;i<=ile;i++)
{
cin>>szerokosci[i];
}
long long suma=0;
long long wyn=0;
for(int i=1;i<=ile;i++)
{
long long width=0;
while(!h.empty()&&h.back()>=wysokosci[i])
{
width+=w.back();
width%=mod;
suma=odejmij(suma-war.back());
h.pop_back();
w.pop_back();
war.pop_back();
}
long long pom=(wysokosci[i]*(wysokosci[i]+1))/2;
pom%=mod;
pom*=width;
pom%=mod;
wyn+=pom*szerokosci[i];
wyn%=mod;
pom=(wysokosci[i]*(wysokosci[i]+1))/2;
pom%=mod;
long long pom2=(szerokosci[i]*(szerokosci[i]+1))/2;
pom2%=mod;
pom*=pom2;
pom%=mod;
wyn+=pom;
wyn%=mod;
width+=szerokosci[i];
pom=(wysokosci[i]*(wysokosci[i]+1))/2;
pom%=mod;
pom*=width;
pom%=mod;
wyn+=suma*szerokosci[i];
wyn%=mod;
suma+=pom;
suma%=mod;
h.push_back(wysokosci[i]);
w.push_back(width);
war.push_back(pom);
}
cout<<wyn;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
324 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
300 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
320 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
11 ms |
1612 KB |
Output is correct |
4 |
Correct |
25 ms |
2920 KB |
Output is correct |
5 |
Correct |
20 ms |
2980 KB |
Output is correct |
6 |
Correct |
16 ms |
3012 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
308 KB |
Output is correct |
2 |
Correct |
3 ms |
564 KB |
Output is correct |
3 |
Correct |
11 ms |
1992 KB |
Output is correct |
4 |
Correct |
21 ms |
3696 KB |
Output is correct |
5 |
Correct |
29 ms |
3824 KB |
Output is correct |
6 |
Correct |
0 ms |
324 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
324 KB |
Output is correct |
2 |
Correct |
1 ms |
308 KB |
Output is correct |
3 |
Correct |
3 ms |
588 KB |
Output is correct |
4 |
Correct |
11 ms |
1996 KB |
Output is correct |
5 |
Correct |
21 ms |
3712 KB |
Output is correct |
6 |
Correct |
35 ms |
3796 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
3 ms |
1084 KB |
Output is correct |
9 |
Correct |
14 ms |
2876 KB |
Output is correct |
10 |
Correct |
31 ms |
6172 KB |
Output is correct |
11 |
Correct |
23 ms |
6256 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
320 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
0 ms |
332 KB |
Output is correct |
9 |
Correct |
0 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
352 KB |
Output is correct |
11 |
Correct |
0 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
460 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
452 KB |
Output is correct |
16 |
Correct |
0 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
324 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
300 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
300 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
320 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
9 |
Correct |
0 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
328 KB |
Output is correct |
11 |
Correct |
9 ms |
1564 KB |
Output is correct |
12 |
Correct |
19 ms |
3012 KB |
Output is correct |
13 |
Correct |
26 ms |
3000 KB |
Output is correct |
14 |
Correct |
16 ms |
3028 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
3 ms |
588 KB |
Output is correct |
17 |
Correct |
11 ms |
1956 KB |
Output is correct |
18 |
Correct |
25 ms |
3692 KB |
Output is correct |
19 |
Correct |
26 ms |
3828 KB |
Output is correct |
20 |
Correct |
1 ms |
328 KB |
Output is correct |
21 |
Correct |
3 ms |
992 KB |
Output is correct |
22 |
Correct |
13 ms |
2892 KB |
Output is correct |
23 |
Correct |
27 ms |
6136 KB |
Output is correct |
24 |
Correct |
29 ms |
6316 KB |
Output is correct |
25 |
Correct |
1 ms |
204 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 |
588 KB |
Output is correct |
31 |
Correct |
3 ms |
580 KB |
Output is correct |
32 |
Correct |
11 ms |
1852 KB |
Output is correct |
33 |
Correct |
12 ms |
1988 KB |
Output is correct |
34 |
Correct |
21 ms |
3520 KB |
Output is correct |
35 |
Correct |
21 ms |
3588 KB |
Output is correct |
36 |
Correct |
22 ms |
3704 KB |
Output is correct |
37 |
Correct |
26 ms |
3724 KB |
Output is correct |
38 |
Correct |
0 ms |
204 KB |
Output is correct |
39 |
Correct |
22 ms |
3696 KB |
Output is correct |
40 |
Correct |
32 ms |
3776 KB |
Output is correct |
41 |
Correct |
31 ms |
4172 KB |
Output is correct |
42 |
Correct |
23 ms |
5048 KB |
Output is correct |