This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |